.dots/scripts/update.sh

63 lines
1.8 KiB
Bash
Raw Normal View History

2024-08-28 15:22:02 +02:00
#!/usr/bin/env bash
# author: Daniel Sommer <daniel.sommer@velvettear.de>
# license: MIT
# debian update script
# exit on ctrl-c
trap 'printf ""$font_colored_bold"\n>> stopping system update after "$SECONDS" seconds..."$font_default"\n" && exit 1' SIGINT
# font styles & colors
font_default="\e[0m"
font_colored="\e[32;1m"
font_colored_bold="\e[31;1m"
[[ "$EUID" != "0" ]] && printf ""$font_colored_bold">> error: permission denied!"$font_default"\n" && exit 1
for arg in "$@"; do
case "$arg" in
-n|--noconfirm)
noconfirm="true"
;;
-r|--reboot)
reboot="true"
;;
esac
done
printf ""$font_colored_bold">> system update started..."$font_default"\n"
printf ""$font_colored"> updating packages..."$font_default"\n"
/usr/bin/apt-get update
[[ "$noconfirm" ]] && /usr/bin/apt-get dist-upgrade -y || /usr/bin/apt-get dist-upgrade
printf ""$font_colored"> cleaning cache..."$font_default"\n"
rm -rf "/var/cache//usr/bin/apt-get/*"
[[ "$noconfirm" ]] && /usr/bin/apt-get clean -y || /usr/bin/apt-get clean
printf ""$font_colored"> removing orphaned packages..."$font_default"\n"
[[ "$noconfirm" ]] && /usr/bin/apt-get autoremove --purge -y || /usr/bin/apt-get autoremove --purge
printf ""$font_colored"> removing \"no valid subscription\" message..."$font_default"\n"
sed -i.bak "s/data.status.* !== 'ACTIVE'/false/I" /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js
2024-10-28 13:38:30 +01:00
if [[ "$(which restic &> /dev/null)" ]]; then
printf ""$font_colored"> updating restic..."$font_default"\n"
restic self-update
fi
2024-08-28 15:22:02 +02:00
printf ""$font_colored_bold">> system updated finished after "$SECONDS" seconds!"$font_default"\n"
[[ ! "$reboot" ]] && exit 0
timeout="5"
printf ""$font_colored"> rebooting system in "
while [[ "$timeout" -gt "0" ]]; do
printf "$timeout... "
timeout="$(( timeout - 1 ))"
sleep 1
done
printf "now!"$font_default"\n"
systemctl reboot