#!/usr/bin/env bash REBOOT=0 FORCEREBOOT=0 SLEEPTIME=10 while getopts "rR" opt; do case "$opt" in r) REBOOT=1 ;; R) FORCEREBOOT=1 ;; esac done shift $((OPTIND-1)) echo -e "\n *********************" echo -e " * gw APT-GET runner *" echo -e " *********************\n" if (( EUID != 0 )); then echo "Script must be run as root. Try 'sudo $0'" exit 1 fi if (( FORCEREBOOT )); then echo -e "FORCE REBOOT option is set! Will reboot when finished.\n" elif (( REBOOT )); then echo -e "REBOOT option is set! Will reboot if necessary when finished.\n" fi echo "Running UPDATE.." if ! apt-get update; then echo "ERROR during apt-get update! Exiting.." exit 1 fi echo -e "done.\n" echo "Running FULL UPGRADE.." if ! apt-get -y full-upgrade; then echo "ERROR during apt-get full-upgrade! Exiting.." exit 1 fi echo -e "done.\n" if [[ "$#" -gt 0 ]]; then printf 'Running INSTALL for: %s\n' "$*" if ! apt-get -y install "$@"; then echo "ERROR during apt-get install!" echo -e "failed.\n" else echo -e "done.\n" fi fi echo "Running AUTOCLEAN.." if ! apt-get -y autoclean; then echo "ERROR during autoclean!" fi echo -e "done.\n" echo "Running AUTOREMOVE.." if ! apt-get -y autoremove; then echo "ERROR during autoremove!" fi echo -e "done.\n" if command -v checkrestart >/dev/null 2>&1; then echo "Finally running CHECKRESTART to see what needs to be restarted.." checkrestart echo -e "done.\n" else echo "Skipping CHECKRESTART. Seems to be not available.." fi echo -e "** Finished APT-GET Runner! **\n" DOREBOOT=0 MSG="Have a good day!" if (( FORCEREBOOT )); then MSG="Rebooting in ${SLEEPTIME} seconds..." DOREBOOT=1 elif (( REBOOT )); then if [[ -f /var/run/reboot-required ]]; then MSG="System reboot required. Rebooting in ${SLEEPTIME} seconds..." DOREBOOT=1 else MSG="No reboot required. Have a good day!" fi fi if (( DOREBOOT )); then echo "${MSG}" sleep "$SLEEPTIME" reboot else echo "${MSG}" fi