From ae73a09e9520924a8172c59c220d015bad8c44b9 Mon Sep 17 00:00:00 2001 From: Sapphirus Date: Fri, 14 Apr 2023 00:22:58 +0000 Subject: [PATCH] Sleep timer, unintrusive upgrade and reboot - This script will reboot the system to commence an upgrade on the proceeding boot - Incrementing sleep timer with a limit of one hour - And some cleanup. --- fedora_upgrade | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/fedora_upgrade b/fedora_upgrade index b08da80..101e93d 100644 --- a/fedora_upgrade +++ b/fedora_upgrade @@ -3,14 +3,19 @@ source /etc/os-release MIRROR="https://mirror.xenyth.net/fedora/linux/releases" VERSION_NEXT=$(($VERSION_ID + 1)) +STATUS_FILE=/var/cache/dnf/upgrade.release +SLEEP=30 check () { + if [[ -f $STATUS_FILE ]]; then + upgrade + return + fi + curl -s -o /dev/null $MIRROR if [[ $? != 0 ]]; then - echo "Internet connection, or mirror, is offline. Trying again in 60 seconds.." - sleep 60 - check + timeout return fi @@ -24,20 +29,31 @@ check () { upgrade ;; *) - echo "Mirror returned unhandled HTTP Response Code: $mirror_response." + echo "Mirror returned unhandled HTTP response: $mirror_response." ;; esac } +download () { + dnf upgrade --refresh -y + dnf system-upgrade download --releasever=$VERSION_NEXT -y + [[ $? == 0 ]] && touch $STATUS_FILE +} + upgrade () { - dnf upgrade --refresh -y - dnf system-upgrade download --releasever=$VERSION_NEXT -y + rm $STATUS_FILE + dnf system-upgrade reboot -y +} - wall "WARNING: An upgrade from Fedora $VERSION_ID to Fedora $VERSION_NEXT is commencing! Your computer will reboot in 60 seconds." - - sleep 60 - - dnf system-upgrade reboot -y +timeout () { + if [[ $SLEEP -gt 3840 ]]; then + echo "Upgrade check has timed out. Aborting operation." + exit 1 + fi + echo "Internet connection, or mirror, is offline. Sleeping for $SLEEP seconds.." + sleep $SLEEP + SLEEP=$(($SLEEP*2)) + check } check \ No newline at end of file