prevent from running script as root, added color, better detect pkgmgr

This commit is contained in:
mollusk 2017-08-19 22:18:14 -07:00
parent 06c967182c
commit a3f658ed80

View File

@ -1,31 +1,111 @@
#!/bin/bash #!/bin/bash
CURRENT_USER="mollusk"
DISTRO=$(lsb_release -i | cut -d: -f2 | sed s/'^\t'//) NPM_DIR="/usr/bin/npm"
BIN_DIR="/home/${CURRENT_USER}/wire-packages" BIN_DIR="/home/${USER}/wire-packages"
PACKAGE_DEFAULT_DIR="$(pwd)/wrap/dist" PACKAGE_DEFAULT_DIR="$(pwd)/wrap/dist"
SUPER_USER_CMD="sudo"
# Colors
RED='\033[0;31m'
LRED="\033[1;31m"
BLUE="\033[0;34m"
LBLUE="\033[1;34m"
GREEN="\033[0;32m"
LGREEN="\033[1;32m"
YELLOW="\033[1;33m"
CYAN="\033[0;36m"
LCYAN="\033[1;36m"
PURPLE="\033[0;35m"
LPURPLE="\033[1;35m"
BWHITE="\e[1m"
NC='\033[0m' # No Color
if [[ $EUID -eq 0 ]]; then
printf "${LRED}Do not run this script as root${NC}\n" 1>&2
exit 1
fi
check_sudo(){
if [ ! -f /usr/bin/sudo ];then
SUPER_USER_CMD="su -c"
fi
}
apt_install(){
local PACKAGES='git make nodejs npm'
printf "${LCYAN}Fetching dependencies${NC}\n\n"
${SUPER_USER_CMD} "apt install ${PACKAGES}"
}
dnf_install(){
local PACKAGES='rpm-build rpmdevtools make nodejs npm git'
printf "${LCYAN}Fetching dependencies${NC}\n\n"
${SUPER_USER_CMD} dnf install ${PACKAGES}
}
zypper_install(){
local PACKAGES="make git nodejs npm"
printf "${LCYAN}Fetching dependencies${NC}\n\n"
${SUPER_USER_CMD} 'zypper install "${PACKAGES}"'
}
check_deps(){
declare -a FIND_PACKAGE_MANAGER=(
"apt"
"dnf"
"zypper")
for i in ${FIND_PACKAGE_MANAGER[@]};do
PACKAGE_MANAGER=$(which ${i} 2> /dev/null)
echo "$PACKAGE_MANAGER"
if [ -n "${PACKAGE_MANAGER}" ];then
break
fi
done
if [[ "${PACKAGE_MANAGER}" = "/usr/bin/apt" ]];then
apt_install
elif [ "${PACKAGE_MANAGER}" = "/usr/bin/dnf" ];then
dnf_install
elif [[ "${PACKAGE_MANAGER}" = "/usr/bin/xbps-install" ]];then
xbps_install
elif [[ "${PACKAGE_MANAGER}" = "/usr/bin/zypper" ]];then
zypper_install
fi
}
build_deb(){ build_deb(){
ARCH="x64" local ARCH="x64"
TARGET="deb" local TARGET="deb"
local UPDATE_OPTS="'clean:linux' 'update-keys' 'release-prod'"
local BUILD_OPTS="--arch=${ARCH} --target=${TARGET} 'electronbuilder:linux_other'"
npm install npm install
npm update npm update
npm install -g grunt npm install grunt
grunt 'clean:linux' 'update-keys' 'release-prod' ${SUPER_USER_CMD} "grunt ${UPDATE_OPTS}"
grunt --arch=${ARCH} --target=${TARGET} 'electronbuilder:linux_other' ${SUPER_USER_CMD} "grunt ${BUILD_OPTS}"
mv -v ${PACKAGE_DEFAULT_DIR}/*.deb ${BIN_DIR} ${SUPER_USER_CMD} "mv -v ${PACKAGE_DEFAULT_DIR}/*.deb ${BIN_DIR}"
} }
build_rpm(){ build_rpm(){
ARCH="x64" local ARCH="x64"
TARGET="rpm" local TARGET="rpm"
local UPDATE_OPTS="'clean:linux' 'update-keys' 'release-prod'"
local BUILD_OPTS="--arch=${ARCH} --target=${TARGET} 'electronbuilder:linux_other'"
npm install npm install
npm update npm update
npm install -g grunt npm install grunt
grunt 'clean:linux' 'update-keys' 'release-prod' ${SUPER_USER_CMD} grunt 'clean:linux' 'update-keys' 'release-prod'
dnf install rpm-build rpmdevtools ${SUPER_USER_CMD} grunt --arch=${ARCH} --target=${TARGET} 'electronbuilder:linux_other'
grunt --arch=${ARCH} --target=${TARGET} 'electronbuilder:linux_other' ${SUPER_USER_CMD} mv -v ${PACKAGE_DEFAULT_DIR}/*.rpm ${BIN_DIR}
mv -v ${PACKAGE_DEFAULT_DIR}/*.rpm ${BIN_DIR}
} }
git_pull(){ git_pull(){
@ -40,7 +120,7 @@ main(){
mkdir -pv ${BIN_DIR} mkdir -pv ${BIN_DIR}
fi fi
check_deps
case $1 in case $1 in
all | -a) git_pull && build_rpm && build_deb all | -a) git_pull && build_rpm && build_deb