|
#!/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!" |
Gonna use the pits off this. Easy to customize and modify too. Thanks! :)