Skip to content

Instantly share code, notes, and snippets.

@KrazyCanucks
Forked from EdinUser/README.md
Last active June 16, 2025 17:48
Show Gist options
  • Save KrazyCanucks/69bb26f1eba02d4b5f752f12c39f6cac to your computer and use it in GitHub Desktop.
Save KrazyCanucks/69bb26f1eba02d4b5f752f12c39f6cac to your computer and use it in GitHub Desktop.
Bash script to update Debian-based Linux - APT, SNAP and FLATPAK

Updater

Console bash script to make it easier to update packages (auto updaters only)

Install

Download file, than make it executable: chmod +x upd.sh Copy the file to /usr/bin without extension: sudo cp upd.sh /usr/bin/upd type upd from console and run it :)

Change Log

  • Added Nala as a fourth option as I like it over using apt directly. I left the apt in as well for more options.
  • Add option to use parameter to pass selection when running to help automate it more. Now can add to startup script if you wanted.
  • added " --assumeyes" to flatpak update
  • added " --assume-yes" to nala upgrade

Copyright

None ;)

Credit for code

really liked this code so added to it. https://gist.github.com/EdinUser

#!/bin/bash
# APT updates
function apt_updates(){
sudo apt update
sudo apt upgrade
}
# APT clean
function apt_clean(){
sudo apt autoclean
sudo apt autoremove
}
# NALA updates
function nala_updates(){
sudo nala upgrade --assume-yes
}
# NALA clean
function nala_clean(){
sudo nala autopurge
sudo nala audoremove
}
# Snap update packages
function snap_refresh(){
sudo snap refresh
}
# Clean old Snap packages
function snap_clean(){
set -eu
sudo snap list --all | awk '/disabled/{print $1, $3}' |
while read snapname revision; do
sudo snap remove "$snapname" --revision="$revision"
done
}
# Flatpak update
function flatpack_update(){
sudo flatpak update --assumeyes
}
# Remove old Flatpaks and clean cahce folder
function flatpack_clean(){
sudo flatpak uninstall --unused
sudo rm -rfv /var/tmp/flatpak-cache-*
}
# Options to select from
options[0]="All updates (Replace APT wth NALA) (Nala, SNAP, FLATPAK cleanup and autoremove)"
options[1]="All updates (APT, SNAP, FLATPAK cleanup and autoremove)"
options[2]="APT update only (no cleanup and autoremove)"
options[3]="APT updates and clean (APT update, cleanup and autoremove)"
options[4]="SNAP updates (SNAP refresh)"
options[5]="SNAP updates and clean (SNAP refresh and autoremove old version)"
options[6]="FLATPAK updates only (FLATPAK update)"
options[7]="FLATPAK updates and clean (FLATPAK refresh and autoremove old versions)"
options[9]="Quit (do not update anything)"
echo -e "Hello to updates!"
echo -e "Every option will require root password ('sudo')!\n"
# Display all options
for option in ${!options[@]}; do
echo "[$option] - ${options[$option]}"
done
# Check for passed parameter to run automatically
# if no parameter, then ask and wait.
if [ -z "$1" ];
then
# Wait for user response
read -p "Which options 9should be executed?: " selectedOption
else
# pass parameter to selected option
selectedOption="$1"
fi
# Exit?
if [ $selectedOption -eq 9 ]
then
echo -e "\nNo updates selected, good bye!\n"
exit
fi
echo -e "Executing ${options[$selectedOption]}\n"
# Run predefined functions
case $selectedOption in
0)
nala_updates
snap_refresh
snap_clean
flatpack_update
flatpack_clean
;;
1)
apt_updates
apt_clean
snap_refresh
snap_clean
flatpack_update
flatpack_clean
;;
2)
apt_updates
;;
3)
apt_updates
apt_clean
;;
4)
snap_refresh
;;
5)
snap_refresh
snap_clean
;;
6)
flatpack_update
;;
7)
flatpack_update
flatpack_clean
;;
esac
# Bye, bye!
echo -e "\nExecuted ${options[$selectedOption]}\nThank you for using this script!"
@KC-Dee
Copy link

KC-Dee commented Dec 4, 2024

Gonna use the pits off this. Easy to customize and modify too. Thanks! :)

@carltonwb
Copy link

Would it be possible to add a REBOOT option (Y/N) after the script has ended.
Some of the updates on my machine sometimes ask for a reboot.
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment