Skip to content

Instantly share code, notes, and snippets.

@gamesguru
Last active August 3, 2022 18:39
Show Gist options
  • Save gamesguru/f069d7ac732df26a678c49d47dede0fd to your computer and use it in GitHub Desktop.
Save gamesguru/f069d7ac732df26a678c49d47dede0fd to your computer and use it in GitHub Desktop.
Software updating script for Ubuntu/Debian (apt-based systems)
#!/bin/bash
# A script for updating apt-based Linux distros
# ... put it in /usr/local/bin or anywhere in your $PATH
# Function to run
function run_update {
printf "\\n\e[1;31m%s\e[0m\\n" "apt update"
apt update
printf "\\n\e[1;31m%s\e[0m\\n" "apt dist-upgrade"
apt dist-upgrade
printf "\\n\e[1;31m%s\e[0m\\n" "apt autoremove"
apt autoremove
printf "\\n\e[1;31m%s\e[0m\\n" "dpkg -l | grep "^rc" | awk '{print \$2}' | xargs -r dpkg --purge"
dpkg -l | grep "^rc" | awk '{print $2}' | xargs -r dpkg --purge
printf "\\n\e[1;31m%s\e[0m\\n" "exit"
}
# Execute as sudo
printf "\\n\e[1;31m%s\e[0m\\n" "sudo su"
FUNC=$(declare -f run_update)
sudo bash -c "$FUNC; run_update"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment