#!/usr/bin/env bash # author: Daniel Sommer # license: MIT # font styles & colors DEFAULT=$(tput sgr0) BOLD=$(tput bold) RED=$(tput setaf 1) GREEN=$(tput setaf 2) YELLOW=$(tput setaf 3) # exit on ctr-c trap 'printf ""${BOLD}${RED}"\n>> system update aborted after "$SECONDS" seconds!"${DEFAULT}"\n" && exit 1' SIGINT # parse arguments for arg in "$@"; do case "$arg" in -n|--noconfirm) noconfirm="--noconfirm" ;; -r|--reboot) reboot="true" ;; esac done # sudo sudo id -u 2&> /dev/null printf "${BOLD}${YELLOW}>> starting system update...${DEFAULT}\n" # upgrade installed packages printf "${YELLOW}> upgrading packages...${DEFAULT}\n" paru -Syu --sudoloop --combinedupgrade --devel --cleanafter $noconfirm [[ "$?" != "0" ]] && printf "${RED}>> encountered an error upgrading packages!${DEFAULT}\n" && exit 1 printf "${GREEN}> packages successfully upgraded!${DEFAULT}\n" # remove unused packages unused="$(paru -Qtdq --sudoloop)" if [[ -n "$unused" ]]; then printf "${YELLOW}> removing unused packages...${DEFAULT}\n" paru -Rns --sudoloop --devel --cleanafter $noconfirm $unused [[ "$?" != "0" ]] && printf "${RED}>> encountered an error removing unused packages!${DEFAULT}\n" && exit 1 printf "${GREEN}> successfully removed unused packages!${DEFAULT}\n" fi # clean the pacman cache printf "${YELLOW}> cleaning pacman & paru cache directories...${DEFAULT}\n" sudo rm -rf "/var/cache/pacman/*" sudo rm -rf "$HOME/.cache/paru" [[ "$?" != "0" ]] && printf "${RED}>> encountered an error cleaning the pacman & paru cache directories!${DEFAULT}\n" && exit 1 printf "${GREEN}> successfully cleaned the pacman & paru cache directories!${DEFAULT}\n" printf "${BOLD}${YELLOW}>> system updated finished after "$SECONDS" seconds!${DEfAULT}\n" [[ -z "$reboot" ]] && exit 0 # reboot the system timeout="5" while [[ "$timeout" -gt "0" ]]; do if [[ "$timeout" -gt "3" ]]; then color="${GREEN}" elif [[ "$timeout" -gt "1" ]]; then color="${YELLOW}" else color="${RED}" fi printf "\r${color}> system reboot in ${BOLD}$timeout${DEFAULT} seconds..." timeout="$((timeout - 1))" sleep 1 done printf "\r${color}> system going down for reboot ${BOLD}NOW!${DEFAULT}\n" sudo systemctl reboot 2> /dev/null