Offline upgrades with DNF

I wanted to setup my Wi-Fi hotspot (running Fedora 29 on a A20 Olimex Lime board) so it automatically updates itself every night.

DNF provides a way to run offline distro upgrades, from one version of Fedora to the next, but for routine upgrades within a Fedora release.

PackageKit has that, but I'm trying to keep this box as minimal as possible, so I was looking for a solution with just DNF.

Fortunately, someone had the same idea and submitted a plugin doing just that to DNF upstream.

Hoping this plugin would eventually be accepted upstream, I built my own Fedora packages with the plugin added.

Then I simply created a service:

# Saved as /etc/systemd/system/dnf-offline-upgrade.service 
[Unit]
Description=Prepare for an offline update and run it
After=NetworkManager-wait-online.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/dnf offline-upgrade download -y --no-downgrade
ExecStart=/usr/bin/dnf offline-upgrade reboot
TimeoutSec=5min

And a timer:

# Saved as /etc/systemd/system/dnf-offline-upgrade.timer
[Unit]
Description=Daily system upgrade
After=chrony-wait.service

[Timer]
OnCalendar=23:00:00

[Install]
WantedBy=multi-user.target

All it takes at this point is to enable the timer:

$ sudo systemctl daemon-reload
$ sudo systemctl enable dnf-offline-upgrade.timer
$ sudo systemctl start dnf-offline-upgrade.timer

And that's it, from now on, every day at 11pm, DNF is going to perform an offline upgrade of the system:

# systemctl status dnf-offline-upgrade.timer
● dnf-offline-upgrade.timer - Daily system upgrade
   Loaded: loaded (/etc/systemd/system/dnf-offline-upgrade.timer; enabled; vendor preset: disabled)
   Active: active (waiting) since Thu 2018-11-22 18:10:35 CET; 1s ago
  Trigger: Thu 2018-11-22 23:00:00 CET; 4h 49min left

Nov 22 18:10:35 localhost systemd[1]: Started Daily system upgrade.

Hopefully the new DNF plugin will be merged upstream and included in a release soon, so I don't need my custom packages!