Skip to content

Instantly share code, notes, and snippets.

@Morgyn
Last active July 7, 2024 10:57
Show Gist options
  • Select an option

  • Save Morgyn/224712810ebb999ee1427a79d17d1ebd to your computer and use it in GitHub Desktop.

Select an option

Save Morgyn/224712810ebb999ee1427a79d17d1ebd to your computer and use it in GitHub Desktop.
Fedora Update script
#!/bin/bash
# Will update as far as it will go
# echo "@reboot root /root/updateos.sh" >>/etc/crontab
# uname -m for arch
if [ "x${1}" == "xSCRIPT" ]; then
SHELL="/bin/bash"
/usr/bin/script /root/updateos-$(date --iso-8601=seconds).log ${0} SCRIPT
exit 0
fi
dnf list installed jq &>/dev/null
if [ "$?" -ne "0" ]; then
dnf install -y jq
fi
CURRENT_VERSION=$(
. /etc/os-release
if [ "${ID}" != "fedora" ]; then
echo "ERROR";
else
echo "${VERSION_ID}";
fi
)
TARGET_VERSION=$(
curl -sq https://fedoraproject.org/releases.json | \
jq -r '[.[] |
select(.variant == "Server" and .arch == "x86_64")] |
max_by(.version | tonumber) |
.version'
)
echo $TARGET_VERSION
UPDATE_VERSION_MAX=$((CURRENT_VERSION + 2))
if [ $TARGET_VERSION -eq $UPDATE_VERSION_MAX ]; then
echo "At latest version"
exit
fi
if [ $TARGET_VERSION -gt $UPDATE_VERSION_MAX ]; then
UPGRADE_VERSION=$UPDATE_VERSION_MAX
else
if [ $TARGET_VERSION -lt $CURRENT_VERSION ]; then
UPGRADE_VERSION=$CURRENT_VERSION
else
UPGRADE_VERSION=$TARGET_VERSION
fi
fi
# dnf install 'dnf-command(system-upgrade)'
dnf -y upgrade --refresh && \
dnf -y system-upgrade download --releasever=${UPGRADE_VERSION} && \
dnf -y system-upgrade reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment