Lacking Natural Simplicity

Random musings on books, code, and tabletop games.

Looping on 'dnf -y system-upgrade download' until it succeeds

Fedora 31 is out, and fool that I am I'm upgrading to it. Unfortunately, my DSL connection is slow and my DSL modem router is flaky. With over 3000 packages to download,

dnf -y system-upgrade download --refresh --releasever=31

is bound to die in the middle at least once, if not multiple times, and with more than 6 hours estimated for the download to run I can't sit watching it and restarting it every time it dies.

I tried running dnf as the argument to a while loop, but was unable to C-c to interrupt it when I did want to kill it since dnf caught the SIGINT and the loop started the dnf command over again before I could C-c the shell.

Here's the script I came up with to work around the issue:

tryfedoraupdate (Source)

#! /usr/bin/bash
while ! dnf -y system-upgrade download --refresh --releasever=31
do
    read -t 30 -p "Continue? (y/n) " reply
    if (($?>128)); then
        echo "timed out, continuing..."
    elif [[ "$reply" =~ [Nn] ]]; then
        echo "Exiting..."
        exit
    else
        echo "Continuing..."
    fi
done

This way I can stop the script easily, but if it dies itself it will continue after a timeout.

Print Friendly and PDF

Comments

Comments powered by Disqus