.dots/scripts/update/alpine.sh

61 lines
1.8 KiB
Bash
Raw Normal View History

2024-09-26 11:05:50 +02:00
#!/usr/bin/env ash
# author: Daniel Sommer <daniel.sommer@velvettear.de>
# license: MIT
# exit on ctrl-c
2024-09-26 13:45:53 +02:00
trap 'printf ""$font_colored_bold"\n>> system update aborted!"$font_default"\n" && exit 1' SIGINT
2024-09-26 11:05:50 +02:00
# font styles & colors
font_default="\e[0m"
font_colored="\e[32;1m"
font_colored_bold="\e[31;1m"
[[ "$(id -u)" != "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"
2024-09-26 11:05:50 +02:00
;;
esac
done
printf ""$font_colored_bold">> system update started..."$font_default"\n"
printf ""$font_colored"> updating packages..."$font_default"\n"
[[ "$noconfirm" ]] && apk --update-cache upgrade --progress || apk --update-cache upgrade --progress --interactive
2024-09-26 11:05:50 +02:00
2024-09-26 13:45:53 +02:00
orphans="$(apk list --orphaned | awk '{print $1}' 2> /dev/null)"
2024-09-26 11:05:50 +02:00
if [[ "$orphans" ]]; then
orphans="$(printf "$orphans" | tr '\n' ' ')"
printf ""$font_colored"> removing orphaned packages..."$font_default"\n"
2024-09-26 13:45:53 +02:00
[[ "$noconfirm" ]] && apk del --purge --progress $orphans || apk del --purge --progress --interactive $orphans
2024-09-26 11:05:50 +02:00
fi
[[ -f "/etc/motd" ]] && printf ""$font_colored"> removing '/etc/motd'..."$font_default"\n" && rm -f "/etc/motd"
2024-09-26 13:45:53 +02:00
script="$(dirname $(realpath $0))/conf.d/$(hostname).sh"
2024-09-26 11:05:50 +02:00
[[ -x "$script" ]] && printf ""$font_colored"> executing script "$script"..."$font_default"\n" && (. "$script")
2024-11-05 16:27:47 +01:00
printf ""$font_colored"> cleaning cache..."$font_default"\n"
apk cache clean &> /dev/null
rm -rf "/var/cache/apk/*"
2024-09-26 11:05:50 +02:00
printf ""$font_colored_bold">> system updated finished!"$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"
reboot