#!/usr/bin/env zsh # author: Daniel Sommer # license: MIT # exit on ctrl-c trap 'printf ""$font_colored_bold"\n>> system update aborted after "$SECONDS" seconds!"$font_default"\n" && exit 1' SIGINT # font styles & colors font_default="\e[0m" font_colored="\e[32;1m" font_colored_bold="\e[31;1m" [[ "$EUID" != "0" ]] && printf ""$font_colored_bold">> error: permission denied"$font_default"\n" && exit 1 for arg in "$@"; do case "$arg" in -n|--noconfirm) noconfirm="true" ;; -r|--reboot) reboot="true" ;; esac done printf ""$font_colored_bold">> system update started..."$font_default"\n" printf ""$font_colored"> updating packages..."$font_default"\n" /usr/bin/apt-get update [[ "$noconfirm" ]] && /usr/bin/apt-get upgrade -y || /usr/bin/apt-get upgrade printf ""$font_colored"> cleaning cache..."$font_default"\n" rm -rf "/var/cache//usr/bin/apt-get/*" [[ "$noconfirm" ]] && /usr/bin/apt-get clean -y || /usr/bin/apt-get clean printf ""$font_colored"> removing orphaned packages..."$font_default"\n" [[ "$noconfirm" ]] && /usr/bin/apt-get autoremove --purge -y || /usr/bin/apt-get autoremove --purge printf ""$font_colored_bold">> system updated finished after "$SECONDS" seconds!"$font_default"\n" [[ -z "$reboot" ]] && exit 0 timeout="5" printf ""$font_colored"> rebooting system in " while [[ "$timeout" -gt "0" ]]; do printf "$timeout... " timeout="$(( timeout - 1 ))" sleep 1 done printf "now!"$font_default"\n" systemctl reboot