#!/bin/bash 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(){ 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 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}/*.${TARGET} ${BIN_DIR} } build_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 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}/*.${TARGET} ${BIN_DIR} } git_pull(){ if [ -d .git ];then git stash git pull origin master fi } main(){ if [ ! -d ${BIN_DIR} ];then mkdir -pv ${BIN_DIR} fi check_deps case $1 in all | -a) git_pull && build_rpm && build_deb ;; deb | -d) git_pull && build_deb ;; rpm | -r) git_pull && build_rpm ;; *) printf "\n\n" printf "Usage: $0 [-a/all | -d/deb | -r/rpm ]\n\n" printf " -a | all build all package formats\n" printf " -d | deb build only DEB package format\n" printf " -r | rpm build only RPM package format\n\n" ;; esac } main ${1}