Merge pull request #26 from YunoHost-Apps/fix_cron_apticron

Try to fix broken cron
This commit is contained in:
Salamandar 2024-03-11 12:04:38 +01:00 committed by GitHub
commit 62f3666be4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 17 deletions

View file

@ -0,0 +1,9 @@
## Backup is broken and breaks upgrade with it
If the backup fails because some file in `/etc/yunohost` does not exist, it will prevent any app upgrade.
You should run the upgrade with `--no-safety-backup`, like that:
```bash
sudo yunohost app upgrade unattended_upgrades --no-safety-backup
```

View file

@ -7,7 +7,7 @@ name = "Unattended-upgrades"
description.en = "Daily automatic upgrades"
description.fr = "Mise à jour automatique quotidienne"
version = "1.0~ynh7"
version = "1.1~ynh1"
maintainers = []
@ -18,7 +18,7 @@ admindoc = "https://wiki.debian.org/UnattendedUpgrades"
userdoc = "https://manpages.debian.org/stretch/apticron/apticron.1.en.html"
[integration]
yunohost = ">= 4.3.0"
yunohost = ">= 11.2"
architectures = "all"
multi_instance = false
ldap = "not_relevant"

View file

@ -31,22 +31,22 @@ _apticron_set_config() {
# Create a backup of the cron file for the reset action
cp "$apticron_cron" "$apticron_cron_backup"
# Copy and comment the current cron
ynh_replace_string --match_string="^.* root if.*" --replace_string="#&\n&" --target_file="$apticron_cron"
# Modify the time to set at 20:00 every day
ynh_replace_string --match_string="^[[:digit:]].*\( root if.*\)" --replace_string="0 20 * * *\1" --target_file="$apticron_cron"
# Copy the new cron and set the time to 2:00 every night
ynh_replace_string --match_string="^0 20\(.*\)" --replace_string="&\n0 2\1" --target_file="$apticron_cron"
# Clear everything, keep only the first (official) one. Uncomment.
origin_line=$(grep -m 1 "apticron --cron" "$apticron_cron" | sed 's/^#* *//')
if [ "$previous_apticron" -eq 0 ]; then
# Comment the first cron
ynh_replace_string --match_string="^0 20 .*" --replace_string="#&" --target_file="$apticron_cron"
fi
if [ "$after_apticron" -eq 0 ]; then
# Comment the second cron
ynh_replace_string --match_string="^0 2 .*" --replace_string="#&" --target_file="$apticron_cron"
fi
# Remove all lines matching
ynh_replace_string --match_string=".*apticron --cron.*" --replace_string="" --target_file="$apticron_cron"
# Remove empty lines
sed -i '/^\s*$/d' "$apticron_cron"
(
echo "# $origin_line"
if [ "$previous_apticron" -eq 1 ]; then
echo "$origin_line" | sed 's|^.*\( root if.*\)|0 20 * * *\1|'
fi
if [ "$after_apticron" -eq 1 ]; then
echo "$origin_line" | sed 's|^.*\( root if.*\)|0 2 * * *\1|'
fi
) >> "$apticron_cron"
}
_apticron_restore_config() {