From faec7c86986e10fe5084aa818a7545767bbd3b47 Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Mon, 19 Mar 2018 22:30:52 -0500 Subject: [PATCH] Update glances-install.sh --- glances-install.sh | 214 ++++++++++++++++++++++++--------------------- 1 file changed, 116 insertions(+), 98 deletions(-) diff --git a/glances-install.sh b/glances-install.sh index 218f9a0..c79b677 100644 --- a/glances-install.sh +++ b/glances-install.sh @@ -11,96 +11,6 @@ Red='\033[10;31m' LRed='\033[1;31m' #echo -e "${Green}TEST${Color_Off}" -function join_by { local IFS="$1"; shift; echo "$*"; } - -# Execute a command as root (or sudo) -do_with_root() { - # already root? "Just do it" (tm). - if [[ `whoami` = 'root' ]]; then - $* - elif [[ -x /bin/sudo || -x /usr/bin/sudo ]]; then - echo "sudo $*" - sudo $* - else - echo "Glances requires root privileges to install." - echo "Please run this script as root." - exit 1 - fi -} - -# Detect distribution name -if [[ `which lsb_release 2>/dev/null` ]]; then - # lsb_release available - distrib_name=`lsb_release -is` -else - # lsb_release not available - lsb_files=`find /etc -type f -maxdepth 1 \( ! -wholename /etc/os-release ! -wholename /etc/lsb-release -wholename /etc/\*release -o -wholename /etc/\*version \) 2> /dev/null` - for file in $lsb_files; do - if [[ $file =~ /etc/(.*)[-_] ]]; then - distrib_name=${BASH_REMATCH[1]} - break - else - echo "Sorry, GlancesAutoInstall script is not compliant with your system." - echo "Please read: https://github.com/nicolargo/glances#installation" - exit 1 - fi - done -fi - -echo -e "${LGreen}Detected system: $distrib_name${Color_Off}" - -shopt -s nocasematch -# Let's do the installation -if [[ $distrib_name == "ubuntu" || $distrib_name == "LinuxMint" || $distrib_name == "debian" || $distrib_name == "Raspbian" ]]; then - # Ubuntu/Debian variants - - # Set non interactive mode - set -eo pipefail - export DEBIAN_FRONTEND=noninteractive - - # Make sure the package repository is up to date - do_with_root apt-get -y --force-yes update - - # Install prerequirements - do_with_root apt-get install -y --force-yes python-pip python-dev gcc lm-sensors wireless-tools - -elif [[ $distrib_name == "redhat" || $distrib_name == "centos" || $distrib_name == "Scientific" ]]; then - # Redhat/CentOS/SL - - # Install prerequirements - do_with_root yum -y install python-pip python-devel gcc lm_sensors wireless-tools - -elif [[ $distrib_name == "centminmod" ]]; then - # /CentOS min based - - # Install prerequirements - do_with_root yum -y install python-devel gcc lm_sensors wireless-tools - do_with_root wget -O- https://bootstrap.pypa.io/get-pip.py | python && $(which pip) install -U pip && ln -s $(which pip) /usr/bin/pip - -elif [[ $distrib_name == "fedora" ]]; then - # Fedora - - # Install prerequirements - do_with_root dnf -y install python-pip python-devel gcc lm_sensors wireless-tools - -elif [[ $distrib_name == "arch" ]]; then - # Arch support - - # Headers not needed for Arch, shipped with regular python packages - do_with_root pacman -S python-pip lm_sensors wireless_tools --noconfirm - -else - # Unsupported system - echo "Sorry, GlancesAutoInstall script is not compliant with your system." - echo "Please read: https://github.com/nicolargo/glances#installation" - exit 1 - -fi -shopt -u nocasematch - -echo -e "${Green}Install dependancies${Color_Off}" - - DEPS=$(whiptail --title "Select which modules to install for Glances" --checklist --separate-output \ "Choose user's permissions" 28 80 14 \ "action" "ation" ON \ @@ -117,23 +27,131 @@ DEPS=$(whiptail --title "Select which modules to install for Glances" --checklis "snmp" "snmp" ON \ "web" "web" ON \ "wifi" "wifi" OFF 3>&1 1>&2 2>&3) - exitstatus=$? +if [ $exitstatus = 1 ]; then exit; fi -if [ $exitstatus = 0 ]; then - do_with_root pip install --upgrade pip - DEPS=$(join_by , $DEPS) - do_with_root pip install $DEPS +function join_by { local IFS="$1"; shift; echo "$*"; } + +do_with_root() { + if [[ `whoami` = 'root' ]]; then + $* + elif [[ -x /bin/sudo || -x /usr/bin/sudo ]]; then + echo "sudo $*" + sudo $* + else + echo "Please run this script as root." + exit 1 + fi +} + +# Detect distribution name +if [[ `which lsb_release 2>/dev/null` ]]; then + # lsb_release available + distrib_name=`lsb_release -is` +else + # lsb_release not available + lsb_files=`find /etc -type f -maxdepth 1 \( ! -wholename /etc/os-release ! -wholename /etc/lsb-release -wholename /etc/\*release -o -wholename /etc/\*version \) 2> /dev/null` + for file in $lsb_files; do + if [[ $file =~ /etc/(.*)[-_] ]]; then + distrib_name=${BASH_REMATCH[1]} + break + else + echo -e "Sorry, GlancesAutoInstall script is not compliant with your system." + echo -e "Please read: https://github.com/nicolargo/glances#installation" + exit 1 + fi + done fi +echo -e "${LGreen}Detected system: $distrib_name${Color_Off}" +echo "" +echo -e "${Green}Installing Dependencies${Color_Off}" + +shopt -s nocasematch +# Let's do the installation +if [[ $distrib_name == "ubuntu" || $distrib_name == "LinuxMint" || $distrib_name == "debian" || $distrib_name == "Raspbian" ]]; then + # Ubuntu/Debian variants + + # Set non interactive mode + set -eo pipefail + export DEBIAN_FRONTEND=noninteractive + + # Make sure the package repository is up to date + do_with_root apt-get -y --force-yes update + + # Install prerequirements + do_with_root apt-get install -y --force-yes python-pip python-dev gcc lm-sensors + + if [[ " ${DEPS[@]} " =~ "wifi" ]]; then + do_with_root apt-get install -y --force-yes wireless-tools + fi + + +elif [[ $distrib_name == "redhat" || $distrib_name == "centos" || $distrib_name == "Scientific" ]]; then + # Redhat/CentOS/SL + + # Install prerequirements + do_with_root yum -y install python-pip python-devel gcc lm_sensors + + if [[ " ${DEPS[@]} " =~ "wifi" ]]; then + do_with_root yum -y install wireless-tools + fi + +elif [[ $distrib_name == "centminmod" ]]; then + # /CentOS min based + + # Install prerequirements + do_with_root yum -y install python-devel gcc lm_sensors + do_with_root wget -O- https://bootstrap.pypa.io/get-pip.py | python && $(which pip) install -U pip && ln -s $(which pip) /usr/bin/pip + + if [[ " ${DEPS[@]} " =~ "wifi" ]]; then + do_with_root yum -y install wireless-tools + fi + +elif [[ $distrib_name == "fedora" ]]; then + # Fedora + + # Install prerequirements + do_with_root dnf -y install python-pip python-devel gcc lm_sensors + + if [[ " ${DEPS[@]} " =~ "wifi" ]]; then + do_with_root dnf -y install wireless-tools + fi + +elif [[ $distrib_name == "arch" ]]; then + # Arch support + + # Headers not needed for Arch, shipped with regular python packages + do_with_root pacman -S python-pip lm_sensors --noconfirm + + if [[ " ${DEPS[@]} " =~ "wifi" ]]; then + do_with_root pacman -S wireless_tools --noconfirm + fi + +else + # Unsupported system + echo -e "${BOrange}Sorry, GlancesAutoInstall script is not compliant with your system.${Color_Off}" + echo -e "${BOrange}Please read: https://github.com/nicolargo/glances#installation${Color_Off}" + exit 1 + +fi +shopt -u nocasematch + +do_with_root pip install --upgrade pip +DEPS2="setuptools glances[$(join_by , $DEPS)]" + + # Install or ugrade Glances from the Pipy repository if [[ -x /usr/local/bin/glances || -x /usr/bin/glances ]]; then - echo "Upgrade Glances and dependancies" + echo -e "${Green}Upgrade Glances and dependancies${Color_Off}" # Upgrade libs - do_with_root pip install --upgrade $DEPS + do_with_root pip install --upgrade $DEPS2 do_with_root pip install --upgrade glances else - echo "Install Glances" + echo -e "${Green}Install dependancies${Color_Off}" + do_with_root pip install $DEPS2 + + echo -e "${Green}Install Glances${Color_Off}" # Install Glances do_with_root pip install glances fi