]> git.saurik.com Git - apt.git/blob - debian/apt.apt-compat.cron.daily
delay progress until Release files are downloaded
[apt.git] / debian / apt.apt-compat.cron.daily
1 #!/bin/sh
2
3 set -e
4
5 # Systemd systems use a systemd timer unit which is preferable to
6 # run. We want to randomize the apt update and unattended-upgrade
7 # runs as much as possible to avoid hitting the mirrors all at the
8 # same time. The systemd time is better at this than the fixed
9 # cron.daily time
10 if [ -d /run/systemd/system ]; then
11 exit 0
12 fi
13
14 # sleep for a random interval of time (default 30min)
15 # (some code taken from cron-apt, thanks)
16 random_sleep()
17 {
18 RandomSleep=1800
19 eval $(apt-config shell RandomSleep APT::Periodic::RandomSleep)
20 if [ $RandomSleep -eq 0 ]; then
21 return
22 fi
23 if [ -z "$RANDOM" ] ; then
24 # A fix for shells that do not have this bash feature.
25 RANDOM=$(( $(dd if=/dev/urandom bs=2 count=1 2> /dev/null | cksum | cut -d' ' -f1) % 32767 ))
26 fi
27 TIME=$(($RANDOM % $RandomSleep))
28 sleep $TIME
29 }
30
31 # run daily job
32 random_sleep
33 exec /usr/lib/apt/apt.systemd.daily