This simple script runs correctly when launched manually:
#!/bin/sh
flatpak -y update 2>&1 >> ~/cron/cron-flatpak.log
When run with 00 07 * * * sh ~/cron/cron-flatpak.sh
(same regular user, not root crontab), it produces the following:
Looking for updates…
1. org.chromium.Chromium.Codecs stable u flathub < 1.1 MB
2. org.chromium.Chromium.Locale stable u flathub < 112.8 kB (partial)
3. org.qbittorrent.qBittorrent stable u flathub < 8.3 MB
Updating 1/3…
Warning: Failed to get revokefs-fuse socket from system-helper: Flatpak system operation GetRevokefsFd not allowed for user
Updating 1/3… ██▌ 13% 41.1 kB/s
Updating 1/3… ████████████████████ 100% 674.8 kB/s
Updating 1/3… ████████████████████ 100% 674.8 kB/s
Updating 2/3…
Warning: Failed to get revokefs-fuse socket from system-helper: Flatpak system operation GetRevokefsFd not allowed for user
Updating 2/3… ████████████████████ 100% 592 bytes/s
Updating 3/3…
Warning: Failed to get revokefs-fuse socket from system-helper: Flatpak system operation GetRevokefsFd not allowed for user
Updating 3/3… ████████████████████ 100% 0 bytes/s
Updates complete.
Afterwards, the versions seem to match what's listed on flathub.io, but the script tries to update everything over and over again on each run. Any suggestions?
ETA: Okay people, I'll be testing the approaches you suggested and I will accept one answer or the other after I manage to make the thing work. Going to take a while since every single iteration requires a new app version rolled out on flathub.
It's not so much a solution as a workaround, or possible clue, but installing Chromium with the
--user
flag (flatpak uses--system
by default) and updating works fine in cron.Unfortunately, I'm unsure why the ability to update system flatpaks is dropped in cron—
at least for the Chromium flatpak since it looks like the third flatpak was able to update just. Maybe the issue is with that particular flatpak.Edit: I missed the third error in the output, it was not unique to Chromium.
Edit 2: Just some further clarification/steps for using flatpak's
--user
flag. Since system and user packages are managed separately, this means adding/removing remotes, installing, and updating must also be done separately. A user package cannot pull from a system remote and vice versa.Jobs run through
cron
, orat
, orbatch
, aren't run in the same runtime environment that you have on your desktop. None of yourPATH
changes, or other environment variable settings are automatically propagated to yourcron
job. For example, there's no$DISPLAY
, so GUI programs need special treatment (readman xhost
).One can set environment variables for all one's
cron
jobs in thecrontab
file Readman 5 crontab
.Look at the results of
echo "=== set ===";set;echo "=== env ===";env | sort;echo "=== alias ===";alias
in each of your environments.Since the
command
part of thecrontab
line is, by default, interpreted by/bin/sh
, which has a simpler syntax than/bin/bash
, I recommend havingcommand
be a call to abash
script (executable, mounted, starts with#!/bin/bash
) which sets up the environment, then calls the desired program.Found a cheap and dirty solution: run flatpak via cron with
sudo
. There are at least 3 ways to do it; I went with adding flatpak tosudoers
like this:The script changes accordingly:
With these modifications, everything updates without a hitch. The real reason is most likely not the privileges per se but some other change in the environment, but at least it does not make me reinstall everything.
If anyone thinks it's a bad idea, please explain why.