1
0
Fork 0
fedora_upgrade/fedora_upgrade

59 lines
No EOL
1.1 KiB
Bash

#!/bin/bash
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
timeout
return
fi
local mirror_response=$(curl -s -o /dev/null -w "%{http_code}" $MIRROR/$VERSION_NEXT/)
case $mirror_response in
404)
echo "Fedora $VERSION_ID is the latest version."
;;
200)
download
;;
*)
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 () {
rm $STATUS_FILE
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