Skip to content

Instantly share code, notes, and snippets.

@EdinUser
Last active December 20, 2024 12:25
Show Gist options
  • Select an option

  • Save EdinUser/baa40021d0598ee997c9079801276fc7 to your computer and use it in GitHub Desktop.

Select an option

Save EdinUser/baa40021d0598ee997c9079801276fc7 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 :)

Copyright

None ;)

#!/bin/bash
# APT updates
function apt_updates(){
sudo apt update
sudo apt upgrade
}
# APT clean
function apt_clean(){
sudo apt autoclean
sudo apt autoremove
}
# 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
}
# 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[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
# Wait for user response
read -p "Which options should be executed?: " selectedOption
# 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
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!"
@EdinUser
Copy link
Author

Simple script to semi-automate updating... Got tired of constantly typing console commands, so combined them together. Also, you can select a dedicated update, instead of running all :)

@KrazyCanucks
Copy link

I love this!! Nice and simple and saves me the time to have to run all the commands, perfect

@KrazyCanucks
Copy link

Created a fork and added to it.
-- added Nala
-- added parameter to allow automating it.
-- need to add comments, error checking, and help still

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