Files
Misc-Scripts/glances-install.sh

141 lines
4.0 KiB
Bash

#!/bin/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}"
# 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 \
"batinfo" "batinfo" OFF \
"browser" "browser" ON \
"cpuinfo" "cpuinfo" ON \
"chart" "chart" ON \
"docker" "docker" OFF \
"export" "export" ON \
"folders" "folders" ON \
"gpu" "gpu" OFF \
"ip" "ip" ON \
"raid" "raid" OFF \
"snmp" "snmp" ON \
"web" "web" ON \
"wifi" "wifi" OFF 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
do_with_root pip install --upgrade pip
for DEP in $DEPS
do
do_with_root pip install $DEP
done
fi
# Install or ugrade Glances from the Pipy repository
if [[ -x /usr/local/bin/glances || -x /usr/bin/glances ]]; then
echo "Upgrade Glances and dependancies"
# Upgrade libs
do_with_root pip install --upgrade $DEPS
do_with_root pip install --upgrade glances
else
echo "Install Glances"
# Install Glances
do_with_root pip install glances
fi