Upload etc/cron.daily/apt-compat with huggingface_hub
Browse files- etc/cron.daily/apt-compat +55 -0
etc/cron.daily/apt-compat
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
check_power()
|
| 15 |
+
{
|
| 16 |
+
# laptop check, on_ac_power returns:
|
| 17 |
+
# 0 (true) System is on main power
|
| 18 |
+
# 1 (false) System is not on main power
|
| 19 |
+
# 255 (false) Power status could not be determined
|
| 20 |
+
# Desktop systems always return 255 it seems
|
| 21 |
+
if which on_ac_power >/dev/null 2>&1; then
|
| 22 |
+
if on_ac_power; then
|
| 23 |
+
:
|
| 24 |
+
elif [ $? -eq 1 ]; then
|
| 25 |
+
return 1
|
| 26 |
+
fi
|
| 27 |
+
fi
|
| 28 |
+
return 0
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
# sleep for a random interval of time (default 30min)
|
| 32 |
+
# (some code taken from cron-apt, thanks)
|
| 33 |
+
random_sleep()
|
| 34 |
+
{
|
| 35 |
+
RandomSleep=1800
|
| 36 |
+
eval $(apt-config shell RandomSleep APT::Periodic::RandomSleep)
|
| 37 |
+
if [ $RandomSleep -eq 0 ]; then
|
| 38 |
+
return
|
| 39 |
+
fi
|
| 40 |
+
if [ -z "$RANDOM" ] ; then
|
| 41 |
+
# A fix for shells that do not have this bash feature.
|
| 42 |
+
RANDOM=$(( $(dd if=/dev/urandom bs=2 count=1 2> /dev/null | cksum | cut -d' ' -f1) % 32767 ))
|
| 43 |
+
fi
|
| 44 |
+
TIME=$(($RANDOM % $RandomSleep))
|
| 45 |
+
sleep $TIME
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
# delay the job execution by a random amount of time
|
| 49 |
+
random_sleep
|
| 50 |
+
|
| 51 |
+
# ensure we don't do this on battery
|
| 52 |
+
check_power || exit 0
|
| 53 |
+
|
| 54 |
+
# run daily job
|
| 55 |
+
exec /usr/lib/apt/apt.systemd.daily
|