60 lines
1.8 KiB
Bash
Executable file
60 lines
1.8 KiB
Bash
Executable file
#!/usr/bin/env ash
|
|
|
|
# author: Daniel Sommer <daniel.sommer@velvettear.de>
|
|
# license: MIT
|
|
|
|
# exit on ctrl-c
|
|
trap 'printf ""$font_colored_bold"\n>> system update aborted!"$font_default"\n" && exit 1' SIGINT
|
|
|
|
# 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"
|
|
;;
|
|
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
|
|
|
|
orphans="$(apk list --orphaned | awk '{print $1}' 2> /dev/null)"
|
|
if [[ "$orphans" ]]; then
|
|
orphans="$(printf "$orphans" | tr '\n' ' ')"
|
|
printf ""$font_colored"> removing orphaned packages..."$font_default"\n"
|
|
[[ "$noconfirm" ]] && apk del --purge --progress $orphans || apk del --purge --progress --interactive $orphans
|
|
fi
|
|
|
|
[[ -f "/etc/motd" ]] && printf ""$font_colored"> removing '/etc/motd'..."$font_default"\n" && rm -f "/etc/motd"
|
|
|
|
script="$(dirname $(realpath $0))/conf.d/$(hostname).sh"
|
|
[[ -x "$script" ]] && printf ""$font_colored"> executing script "$script"..."$font_default"\n" && (. "$script")
|
|
|
|
printf ""$font_colored"> cleaning cache..."$font_default"\n"
|
|
apk cache clean &> /dev/null
|
|
rm -rf "/var/cache/apk/*"
|
|
|
|
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
|