Many thanks John Walker for your help !
Everything seems to work.
Here is my proposed solution, step by step, for those who are interested:
1. Script side
A. Create the script (update-script.bash)
# nano /usr/local/bin/update-script.bash
B. Add the commands (update routine) to run:
#!/usr/bin/env bash
sleep 60
dnf clean all
fwupdmgr get-updates
fwupdmgr update
flatpak repair
flatpak --system update -y --noninteractive
pkcon refresh force
pkcon update --only-download
pkcon offline-get-prepared
pkcon offline-trigger
C. make the script executable:
# chmod +x /usr/local/bin/update-script.bash
2. Systemd service
A. Create the “update-script.service” :
# nano /etc/systemd/system/update-script.service
B. Add the following content:
[Unit]
Description=Service to run update script
Wants=network-online.target
ConditionACPower=true
[Service]
Type=oneshot
ExecStart=/usr/local/bin/update-script.bash
-
Wants=network-online.target : waits for network to be available.
-
ConditionACPower=true : ensures power cable is plugged in before (you may want to comment it if it’s not necessary)
3. Systemd timer
A. Create the “update-script.timer”
# nano /etc/systemd/system/update-script.timer
B. Add the following content:
[Unit]
Description=Timer for the custom update script service
[Timer]
OnCalendar=Tue,Fri *-*-* 18:00
RandomizedDelaySec=15m
WakeSystem=true
Persistent=true
[Install]
WantedBy=default.target
-
RandomizedDelaySec=5m : run the script randomly between 18:00 and 18:15, it’s useful when several computers share a weak connection.
-
WakeSystem=true : wake the computer from sleep to make it run the service.
-
Persistent=true : if the script cannot be launched (because the computer was off, for exemple) it will be relaunched during the next boot.
C. Enable the timer:
# systemctl enable --now update-script.timer
# systemctl daemon-reload
You can check the last/next run of the timer with:
# systemctl list-timers
If there is any problem, logs of the service/timer are stored in journald :
# journalctl -u update-script.service
Edit : But I’m not really sure of these options:
- the “Type=oneshot” in the .service
- the “WantedBy=default.target” in the .timer