apt.apt-compat.cron.daily 920 B

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