#!/usr/bin/env bash Color_Off='\033[0m' Blue='\033[0;34m' BBlue='\033[1;34m' Green='\033[0;32m' LGreen='\033[1;32m' BOrange='\033[0;33m' DGray='\033[1;30m' Red='\033[10;31m' LRed='\033[1;31m' #echo -e "${Green}TEST${Color_Off}" echo -e "${BOrange}Preparinig to install Glances${Color_Off}" echo "" DEPS=$(whiptail --title "iDS-Glances Auto Install Script" --checklist --separate-output \ "\nPlease select which modules to install for Glances to be able\nto utilize for this system:" 28 80 16 \ "action" "Allows Glances to trigger actions on events" OFF \ "batinfo" "Displays Battery Stats" OFF \ "browser" "Allows for other Glances client browsing" ON \ "chart" "Charts Module" OFF \ "cloud" "Displays Cloud Stats" OFF \ "cpuinfo" "Display CPU Stats" ON \ "docker" "Display Docker Containers" OFF \ "export" "Allows for Data Export" OFF \ "folders" "Folders Module" ON \ "gpu" "Displays GPU Stats" OFF \ "ip" "Displays Public and Private Addresses" ON \ "raid" "Displays RAID Stats" OFF \ "snmp" "Could retrieve stats from an snmp endpoint" OFF \ "web" "Allows Glances to run as a webserver" ON \ "wifi" "Displays WiFi Stats" OFF 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 1 ]; then exit; fi 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 -e "${BOrange}Please run this script as root.${Color_Off}" exit 1 fi } if hash glances 2>/dev/null; then echo -e "${Green}Uninstalling previous Glances install and dependencies...${Color_Off}" do_with_root pip3 uninstall -y glances[action,batinfo,browser,cpuinfo,chart,docker,export,folders,gpu,ip,raid,snmp,web,wifi] 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 "${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 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 update # Install prerequirements do_with_root apt-get install -y python3-pip python3-dev gcc lm-sensors python3-setuptools pkg-config if [[ " ${DEPS[@]} " =~ "wifi" ]]; then do_with_root apt-get install -y 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 epel-release do_with_root yum -y install python3-pip python-devel gcc lm_sensors python3-setuptools 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 python3-setuptools 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 python3-pip python-devel gcc lm_sensors python3-setuptools 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 python3-pip lm_sensors python3-setuptools --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)]" echo "" # Install or ugrade Glances from the Pipy repository if [[ -x /usr/local/bin/glances || -x /usr/bin/glances ]]; then echo -e "${Green}Upgrade Glances and dependancies${Color_Off}" # Upgrade libs do_with_root pip3 install --upgrade $DEPS2 do_with_root pip3 install --upgrade glances else echo -e "${Green}Installing dependancies...${Color_Off}" do_with_root pip3 install $DEPS2 echo "" echo -e "${Green}Installing Glances...${Color_Off}" # Install Glances do_with_root pip3 install glances fi exit 0