diff --git a/wire-build.sh b/wire-build.sh index 6359248..d5652b7 100755 --- a/wire-build.sh +++ b/wire-build.sh @@ -1,31 +1,111 @@ #!/bin/bash -CURRENT_USER="mollusk" -DISTRO=$(lsb_release -i | cut -d: -f2 | sed s/'^\t'//) -BIN_DIR="/home/${CURRENT_USER}/wire-packages" + +NPM_DIR="/usr/bin/npm" +BIN_DIR="/home/${USER}/wire-packages" 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(){ - ARCH="x64" - TARGET="deb" + local ARCH="x64" + 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 update - npm install -g grunt - grunt 'clean:linux' 'update-keys' 'release-prod' - grunt --arch=${ARCH} --target=${TARGET} 'electronbuilder:linux_other' - mv -v ${PACKAGE_DEFAULT_DIR}/*.deb ${BIN_DIR} + npm install grunt + ${SUPER_USER_CMD} "grunt ${UPDATE_OPTS}" + ${SUPER_USER_CMD} "grunt ${BUILD_OPTS}" + ${SUPER_USER_CMD} "mv -v ${PACKAGE_DEFAULT_DIR}/*.deb ${BIN_DIR}" } build_rpm(){ - ARCH="x64" - TARGET="rpm" + local ARCH="x64" + 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 update - npm install -g grunt - grunt 'clean:linux' 'update-keys' 'release-prod' - dnf install rpm-build rpmdevtools - grunt --arch=${ARCH} --target=${TARGET} 'electronbuilder:linux_other' - mv -v ${PACKAGE_DEFAULT_DIR}/*.rpm ${BIN_DIR} + npm install grunt + ${SUPER_USER_CMD} grunt 'clean:linux' 'update-keys' 'release-prod' + ${SUPER_USER_CMD} grunt --arch=${ARCH} --target=${TARGET} 'electronbuilder:linux_other' + ${SUPER_USER_CMD} mv -v ${PACKAGE_DEFAULT_DIR}/*.rpm ${BIN_DIR} } git_pull(){ @@ -40,7 +120,7 @@ main(){ mkdir -pv ${BIN_DIR} fi - + check_deps case $1 in all | -a) git_pull && build_rpm && build_deb