Last active
June 13, 2023 20:11
-
-
Save milnak/93ff631ded8799045cd81cdddd854279 to your computer and use it in GitHub Desktop.
My linux update script #linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
cecho() { | |
color='' | |
reset=$(tput sgr0) | |
case "$1" in | |
bk) color=$(tput setaf 0) ;; | |
rd) color=$(tput setaf 1) ;; | |
gn) color=$(tput setaf 2) ;; | |
yl) color=$(tput setaf 3) ;; | |
bl) color=$(tput setaf 4) ;; | |
pr) color=$(tput setaf 5) ;; | |
lb) color=$(tput setaf 6) ;; | |
wt) color=$(tput setaf 7) ;; | |
*) local text="$1" ;; | |
esac | |
[[ -z "${text}" ]] && local text="${color}$2${reset}" | |
echo "${text}" | |
} | |
if [[ ${EUID} -ne 0 ]]; then | |
cecho pr 'Restarting script as super-user.' | |
sudo "./$(basename "$0")" | |
exit | |
fi | |
cecho yl 'Updating system ...' | |
cecho gn 'Updating the package list.' | |
sudo apt-get update | |
cecho gn 'Upgrading installed packages to their latest available versions.' | |
sudo apt-get upgrade -y | |
# cecho gn 'Performing upgrades involving changing dependencies, adding or removing new packages as necessary.' | |
# sudo apt-get dist-upgrade -y | |
cecho gn 'Removing packages that were installed by other packages and are no longer needed.' | |
sudo apt-get autoremove -y | |
cecho gn 'Removing .deb files for packages that are no longer installed on your system.' | |
sudo apt-get autoclean -y | |
if [[ -f /var/run/reboot-required ]]; then | |
cecho yl 'Rebooting to apply update.' | |
sudo shutdown -r | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment