diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 18:07:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 18:07:14 +0000 |
commit | 8a9229dbc7367a76c54f6f88c9c1738da260afc9 (patch) | |
tree | 9994217a3bd0e7839dd1d1e77e4072ca65e7affc /debian/apt.apt-compat.cron.daily | |
parent | Adding upstream version 1.8.2.3. (diff) | |
download | apt-debian.tar.xz apt-debian.zip |
Adding debian version 1.8.2.3.debian/1.8.2.3debian
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'debian/apt.apt-compat.cron.daily')
-rw-r--r-- | debian/apt.apt-compat.cron.daily | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/debian/apt.apt-compat.cron.daily b/debian/apt.apt-compat.cron.daily new file mode 100644 index 0000000..b0b5537 --- /dev/null +++ b/debian/apt.apt-compat.cron.daily @@ -0,0 +1,55 @@ +#!/bin/sh + +set -e + +# Systemd systems use a systemd timer unit which is preferable to +# run. We want to randomize the apt update and unattended-upgrade +# runs as much as possible to avoid hitting the mirrors all at the +# same time. The systemd time is better at this than the fixed +# cron.daily time +if [ -d /run/systemd/system ]; then + exit 0 +fi + +check_power() +{ + # laptop check, on_ac_power returns: + # 0 (true) System is on main power + # 1 (false) System is not on main power + # 255 (false) Power status could not be determined + # Desktop systems always return 255 it seems + if which on_ac_power >/dev/null 2>&1; then + if on_ac_power; then + : + elif [ $? -eq 1 ]; then + return 1 + fi + fi + return 0 +} + +# sleep for a random interval of time (default 30min) +# (some code taken from cron-apt, thanks) +random_sleep() +{ + RandomSleep=1800 + eval $(apt-config shell RandomSleep APT::Periodic::RandomSleep) + if [ $RandomSleep -eq 0 ]; then + return + fi + if [ -z "$RANDOM" ] ; then + # A fix for shells that do not have this bash feature. + RANDOM=$(( $(dd if=/dev/urandom bs=2 count=1 2> /dev/null | cksum | cut -d' ' -f1) % 32767 )) + fi + TIME=$(($RANDOM % $RandomSleep)) + sleep $TIME +} + +# delay the job execution by a random amount of time +random_sleep + +# ensure we don't do this on battery +check_power || exit 0 + +# run daily job +exec /usr/lib/apt/apt.systemd.daily |