]> git.saurik.com Git - apt.git/blobdiff - debian/apt.cron.daily
cmdline/apt-key: relax the apt-key update code
[apt.git] / debian / apt.cron.daily
index 5524c16eef0482eeeb6ae49c3690bd6103327783..ec53a7f2f73b10c92044df358e91211cfd4390d8 100644 (file)
@@ -147,6 +147,28 @@ check_size_constraints()
     fi
 }
 
+# sleep for a random intervall 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 count=1 2> /dev/null | cksum | cut -c"1-5")
+    fi
+    TIME=$(($RANDOM % $RandomSleep))
+    sleep $TIME
+}
+
+# main
+
+if ! which apt-config >/dev/null; then
+       exit 0
+fi
 
 UpdateInterval=0
 DownloadUpgradeableInterval=0
@@ -172,9 +194,17 @@ fi
 
 # check if we can lock the cache and if the cache is clean
 if ! apt-get check -q -q 2>/dev/null; then
+    echo "$0: could not lock the APT cache"
     exit 1
 fi
 
+# sleep random amount of time
+random_sleep
+
+# check again if we can access the cache
+if ! apt-get check -q -q 2>/dev/null; then
+    exit 1
+fi
 
 UPDATE_STAMP=/var/lib/apt/periodic/update-stamp
 if check_stamp $UPDATE_STAMP $UpdateInterval; then