#!/usr/bin/env bash # LinUPx - Linux Update Scripts action="$1" FOLDER='/opt/LinUPx' VERS='4.11232018' if [ ! -f /opt/LinUPx/settings.conf ]; then echo -ne "useAutoremove=1 opennms=false" > /opt/LinUPx/settings.conf fi source /opt/LinUPx/settings.conf 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' if type apt &>/dev/null; then ATYPE="apt" if [ "$EUID" -ne 0 ]; then APTFUNC='sudo apt' else APTFUNC='apt' fi elif type apt-get &>/dev/null; then ATYPE="apt-get" if [ "$EUID" -ne 0 ]; then APTFUNC='sudo apt-get' else APTFUNC='apt-get' fi elif type yum &>/dev/null; then ATYPE="yum" if [ "$EUID" -ne 0 ]; then APTFUNC='sudo yum' else APTFUNC='yum' fi else ATYPE="unknown" fi ######## NEWRELIC REMOVAL ######## if [ -e /etc/apt/sources.list.d/newrelic.list ]; then $APTFUNC remove -y newrelic-sysmond rm -f /etc/apt/sources.list.d/newrelic.list echo -e "${BBlue}NOTICE:${Color_Off} NewRelic Removed." sleep 5 fi UPDATE1() { if [ "$opennms" = true ]; then sudo apt-mark unhold libopennms-java libopennmsdeps-java opennms-common opennms-db fi if type yum &>/dev/null; then $APTFUNC -y update else if [ "$useAutoremove" -ne 0 ]; then AUTOREMOVE $APTFUNC update $APTFUNC upgrade -y AUTOREMOVE fi fi if [ "$opennms" = true ]; then sudo apt-mark hold libopennms-java libopennmsdeps-java opennms-common opennms-db fi touch "${FOLDER}/lastrun" echo "" echo -e "${Green}Updates have completed${Color_Off}" if [ ${action-x} ]; then exit 0; fi read -n 1 -s -p "Press any key to continue" } UPDATE2() { if [ "$opennms" = true ]; then sudo apt-mark unhold libopennms-java libopennmsdeps-java opennms-common opennms-db fi if [ "$useAutoremove" -ne 0 ]; then AUTOREMOVE $APTFUNC upgrade -y AUTOREMOVE fi if [ "$opennms" = true ]; then sudo apt-mark hold libopennms-java libopennmsdeps-java opennms-common opennms-db fi touch "${FOLDER}/lastrun" echo "" echo -e "${Green}Updated Upgrades have completed${Color_Off}" if [ ${action-x} ]; then exit 0; fi read -n 1 -s -p "Press any key to continue" } UPDATE3() { restart_flag=''; export DEBIAN_FRONTEND="noninteractive" source /etc/environment bash /etc/skel/.profile while getopts 'r' flag; do case "${flag}" in r) restart_flag='true' ;; esac done if [ "$autorun_logging" = true ]; then mv -f /opt/runupdates.log.2 /opt/runupdates.log.3 mv -f /opt/runupdates.log.1 /opt/runupdates.log.2 mv -f /opt/runupdates.log /opt/runupdates.log.1 fi if type yum &>/dev/null; then yum -y update >> /opt/runupdates.log else if [ "$opennms" = true ]; then sudo apt-mark unhold libopennms-java libopennmsdeps-java opennms-common opennms-db fi if [ "$useAutoremove" -ne 0 ]; then apt-get -y autoremove >> /opt/runupdates.log apt-get update >> /opt/runupdates.log apt-get upgrade -y >> /opt/runupdates.log apt-get -y autoremove >> /opt/runupdates.log fi if [ "$opennms" = true ]; then sudo apt-mark hold libopennms-java libopennmsdeps-java opennms-common opennms-db fi fi touch "${FOLDER}/lastrun" echo "" echo -e "${Green}Updates have completed${Color_Off}" if [ "$autorun_restart_after" = true ] || [ "$restart_flag" = true ]; then echo -e "${BOrange}Rebooting now...${Color_Off}" sleep 3 /sbin/shutdown -r now fi exit 0 } DISTUPGRADE() { if type yum &>/dev/null; then $APTFUNC upgrade else $APTFUNC dist-upgrade fi if [ "$useAutoremove" -ne 0 ] && type apt-get &>/dev/null; then AUTOREMOVE fi echo "" echo -e "${Green}Dist Upgrades has completed${Color_Off}" if [ ${action-x} ]; then exit 0; fi read -n 1 -s -p "Press any key to continue" } PIPUPGRADE() { if [ "$EUID" -ne 0 ]; then sudo pip install --upgrade pip sudo pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U else pip install --upgrade pip pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U fi echo "" echo -e "${Green}Python-Pip Upgrades has completed${Color_Off}" if [ ${action-x} ]; then exit 0; fi read -n 1 -s -p "Press any key to continue" } AUTOREMOVE() { if [ "$useAutoremove" -ne 0 ]; then if [ "$EUID" -ne 0 ]; then sudo apt-get autoremove else apt-get autoremove fi fi } DRYRUN1() { if type apt &>/dev/null; then $APTFUNC update $APTFUNC list --upgradable elif type apt-get &>/dev/null; then $APTFUNC update $APTFUNC upgrade --dry-run elif type yum &>/dev/null; then $APTFUNC check-update fi echo "" echo -e "${Green}Upgrade dry-run has completed${Color_Off}" if [ ${action-x} ]; then exit 0; fi read -n 1 -s -p "Press any key to continue" } DRYRUN2() { if type yum &>/dev/null; then $APTFUNC --obsoletes check-update else $APTFUNC dist-upgrade --dry-run fi echo "" echo -e "${Green}Dist-Upgrade dry-run has completed${Color_Off}" if [ ${action-x} ]; then exit 0; fi read -n 1 -s -p "Press any key to continue" } GO_REBOOT() { read -n 1 -p "Are you sure you wish to reboot (y/n)?" choice case "$choice" in [Yy]) if [ "$EUID" -ne 0 ]; then sudo shutdown -r now else shutdown -r now fi echo 'The system is now rebooting...' sleep 60 exit 0;; * ) SCRIPT_MENU;; esac } SHUTDOWN() { read -n 1 -p "Are you sure you wish to shutdown (y/n)?" choice case "$choice" in [Yy]) if [ "$EUID" -ne 0 ]; then sudo shutdown -h now else shutdown -h now fi echo 'The system is now shutting down...' sleep 60 exit 0;; * ) SCRIPT_MENU;; esac } ENDISASU() { if [ "$EUID" -ne 0 ]; then sudo dpkg-reconfigure --priority=low unattended-upgrades else dpkg-reconfigure --priority=low unattended-upgrades fi } EXIT1() { clear exit 0 } WEBMIN_INSTALL() { read -n 1 -p "Are you sure you wish to install Webmin (y/n)?" choice case "$choice" in [Yy]) echo "" bash <(curl -sL https://git.schroedercity.com/voltron/Misc-Scripts/raw/master/webmin-install.sh) echo "" echo -e "${Green}Webmin has been Installed${Color_Off}" if [ ${action-x} ]; then exit 0; fi read -n 1 -s -p "Press any key to continue";; * ) INSTALL_MENU;; esac } GLANCES_INSTALL() { read -n 1 -p "Are you sure you wish to install Glances (y/n)?" choice case "$choice" in [Yy]) echo "" bash <(curl -sL https://git.schroedercity.com/voltron/Misc-Scripts/raw/master/glances-install.sh) echo "" echo -e "${Green}Glances has been Installed${Color_Off}" if [ ${action-x} ]; then exit 0; fi read -n 1 -s -p "Press any key to continue";; * ) INSTALL_MENU;; esac } X11VNC_INSTALL() { read -n 1 -p "Are you sure you wish to install x11vnc (y/n)?" choice case "$choice" in [Yy]) echo "" bash <(curl -sL https://git.schroedercity.com/voltron/Misc-Scripts/raw/master/vnc-install-ubuntu.sh) echo "" echo -e "${Green}Webmin has been Installed${Color_Off}" if [ ${action-x} ]; then exit 0; fi read -n 1 -s -p "Press any key to continue";; * ) INSTALL_MENU;; esac } SCRIPT_MENU() { LASTRUND=$(stat -c %y /opt/LinUPx/lastrun | cut -d ' ' -f1) LASTRUNT=$((stat -c %y /opt/LinUPx/lastrun | cut -d ' ' -f2) | cut -d '.' -f1) while : do clear echo "" echo -e " ${LGreen}LinUPx - L I N U X U P D A T E S C R I P T S${Color_Off} ${DGray}(ver-${VERS})${Color_Off}" echo -e "${LGreen}---------------------------------------------------------------------------${Color_Off}" echo -e "Hostname: ${BBlue}$(hostname -s)${Color_Off}" echo -e "Domain: ${BBlue}$(hostname -d)${Color_Off}" echo "" echo -e "Last run: ${Green}${LASTRUND} ${LASTRUNT}${Color_Off}" echo "---------------------------------------------------------------------------" if type lsb_release &>/dev/null; then lsb_release -i lsb_release -d lsb_release -r lsb_release -c else cat /etc/*release fi cat /proc/cpuinfo | grep 'model name' cat /proc/cpuinfo | grep 'cpu cores' cat /proc/cpuinfo | grep 'stepping' echo -e "${LGreen}---------------------------------------------------------------------------${Color_Off}" echo "" echo " [1] Check for Updates/Upgrades" echo " [2] Run Updates" if [ "$ATYPE" != 'yum' ]; then echo " [3] Run Updates w/o retrieving new repo list" fi echo "" echo " [4] Check for Upgrades with obsoletes enabled" echo " [5] Run Dist-Upgrade" echo " [6] Run Python-Pip Upgrades" echo "" if [ "$ATYPE" != 'yum' ]; then echo " [0] Enable/Disable Automatic Security Updates" echo "" fi echo " [I] Installation Scripts" echo "" echo " [R] Reboot System" echo " [S] Shutdown System" echo " [Q] Quit" echo "" echo "" echo -e -n "${BOrange}Please select an [ActionItem] from above:${Color_Off} " read -n 1 opt echo "" case $opt in 1) DRYRUN1 SCRIPT_MENU;; 2) UPDATE1 SCRIPT_MENU;; 3) UPDATE2 SCRIPT_MENU;; 4) DRYRUN2 SCRIPT_MENU;; 5) DISTUPGRADE SCRIPT_MENU;; 6) PIPUPGRADE SCRIPT_MENU;; 0) ENDISASU SCRIPT_MENU;; [Ii]) INSTALL_MENU;; [Rr]) GO_REBOOT SCRIPT_MENU;; [Ss]) SHUTDOWN SCRIPT_MENU;; [Qq]) EXIT1 exit 1;; *) echo "Thats an invaild option,"; echo "please select a valid option only."; sleep 1;; esac done } INSTALL_MENU() { while : do clear echo "" echo -e " ${LGreen}LinUPx - L I N U X U P D A T E S C R I P T S${Color_Off} ${DGray}(ver-${VERS})${Color_Off}" echo -e " ${Green}INSTALLATION SCRIPTS${Color_Off}" echo -e "${LGreen}---------------------------------------------------------------------------${Color_Off}" echo -e "Hostname: ${BBlue}$(hostname -s)${Color_Off}" echo -e "Domain: ${BBlue}$(hostname -d)${Color_Off}" echo -e "${LGreen}---------------------------------------------------------------------------${Color_Off}" echo "" echo " [1] Webmin Install" echo " [2] Glances Install" echo " [3] x11vnc Install" echo "" echo " [B] Back to Update Scripts" echo " [Q] Quit" echo "" echo "" echo -e -n "${BOrange}Please select an [ActionItem] from above:${Color_Off} " read -n 1 opt echo "" case $opt in 1) WEBMIN_INSTALL INSTALL_MENU;; 2) GLANCES_INSTALL INSTALL_MENU;; 3) X11VNC_INSTALL INSTALL_MENU;; [Bb]) SCRIPT_MENU;; [Qq]) EXIT1 exit 1;; *) echo "Thats an invaild option,"; echo "please select a valid option only."; sleep 1;; esac done } if [ ${action-x} ]; then case $1 in update) UPDATE3;; # *) echo "Thats an invaild option,"; # exit 1;; esac else if [ -e ~/runup.sh ]; then rm -f ~/runup.sh ln -s $FOLDER/run.sh /usr/local/bin/runup echo "" echo "" echo -e "${BBlue}NOTICE:${Color_Off} To start this program from now on, simply execute the command ${Green}runup${Color_Off}." echo -e "${BBlue}NOTICE:${Color_Off} The ~/runup.sh command will no longer work." echo "" echo "" read -n 1 -s -p "Press any key to continue" fi SCRIPT_MENU fi exit 0