* debian/apt.cron.daily:
[ntk/apt.git] / debian / apt.cron.daily
index 8e46651..8ace14a 100644 (file)
@@ -1,6 +1,4 @@
 #!/bin/sh
-#
-
 #set -e
 #
 # This file understands the following apt configuration variables:
@@ -13,7 +11,7 @@
 #  Dir::Cache "var/apt/cache/";
 #  - Set apt package cache directory
 #
-#  Dir::Cache::Archive "archives/";
+#  Dir::Cache::Archives "archives/";
 #  - Set package archive directory
 #
 #  APT::Periodic::Enable "1";
@@ -49,7 +47,7 @@
 #  APT::Periodic::Update-Package-Lists "0";
 #  - Do "apt-get update" automatically every n-days (0=disable)
 #    
-#  "APT::Periodic::Download-Upgradeable-Packages=0",
+#  APT::Periodic::Download-Upgradeable-Packages "0";
 #  - Do "apt-get upgrade --download-only" every n-days (0=disable)
 #
 #  APT::Periodic::Download-Upgradeable-Packages-Debdelta "1";
 #    Requires the package "unattended-upgrades" and will write
 #    a log in /var/log/unattended-upgrades
 # 
-#  "APT::Archives::MaxAge",
-#  - Set maximum allowed age of a cache package file. If a cache 
-#    package file is older it is deleted (0=disable)
-#
-#  "APT::Archives::MaxSize",
-#  - Set maximum size of the cache in MB (0=disable). If the cache
-#    is bigger, cached package files are deleted until the size
-#    requirement is met (the biggest packages will be deleted 
-#    first).
+#  APT::Periodic::AutocleanInterval "0";
+#  - Do "apt-get autoclean" every n-days (0=disable)
 #
-#  "APT::Archives::MinAge"
-#  - Set minimum age of a package file. If a file is younger it
-#    will not be deleted (0=disable). Usefull to prevent races 
-#    and to keep backups of the packages for emergency.
-# 
+#  APT::Periodic::Verbose "0";
+#  - Send report mail to root
+#      0:  no report             (or null string)
+#      1:  progress report       (actually any string)
+#      2:  + command outputs     (remove -qq, remove 2>/dev/null, add -d)
+#      3:  + trace on            
 
 check_stamp()
 {
@@ -116,17 +108,9 @@ check_stamp()
 
     delta=$(($now-$stamp))
 
-    # intervall is in days,
+    # intervall is in days, convert to sec.
     interval=$(($interval*60*60*24))
-    #echo "stampfile: $1"
-    #echo "interval=$interval, now=$now, stamp=$stamp, delta=$delta"
-
-    # remove timestamps a day (or more) in the future and force re-check
-    if [ $stamp -gt $(($now+86400)) ]; then
-         echo "WARNING: file $stamp_file has a timestamp in the future: $stamp"
-         rm -f "$stamp_file"
-         return 0
-    fi
+    debug_echo "check_stamp: interval=$interval, now=$now, stamp=$stamp, delta=$delta (sec)"
 
     # remove timestamps a day (or more) in the future and force re-check
     if [ $stamp -gt $(($now+86400)) ]; then
@@ -145,7 +129,6 @@ check_stamp()
 update_stamp()
 {
     stamp="$1"
-
     touch $stamp
 }
 
@@ -164,21 +147,14 @@ check_size_constraints()
     eval $(apt-config shell MaxSize APT::Archives::MaxSize)
     eval $(apt-config shell MaxSize APT::Periodic::MaxSize)
 
-    CacheDir="var/cache/apt/"
-    eval $(apt-config shell CacheDir Dir::Cache)
-    CacheDir=${CacheDir%/}
-
-    CacheArchive="archives/"
-    eval $(apt-config shell CacheArchive Dir::Cache::archives)
-    CacheArchive=${CacheArchive%/}
+    Cache="/var/cache/apt/archives/"
+    eval $(apt-config shell Cache Dir::Cache::archives/d)
 
     # sanity check
-    if [ -z "$CacheDir" -o -z "$CacheArchive" ]; then
-       echo "empty Dir::Cache or Dir::Cache::archives, exiting"
+    if [ -z "$Cache" ]; then
+       echo "empty Dir::Cache::archives, exiting"
        exit
     fi
-    
-    Cache="${Dir%/}/${CacheDir%/}/${CacheArchive%/}/"
 
     # check age
     if [ ! $MaxAge -eq 0 ] && [ ! $MinAge -eq 0 ]; then
@@ -242,22 +218,17 @@ do_cache_backup()
     fi
 
     # Set default values and normalize
-    Dir="/"
-    eval $(apt-config shell Dir Dir)
-    Dir=${Dir%/}
-
-    CacheDir="var/cache/apt/"
-    eval $(apt-config shell CacheDir Dir::Cache)
+    CacheDir="/var/cache/apt"
+    eval $(apt-config shell CacheDir Dir::Cache/d)
     CacheDir=${CacheDir%/}
     if [ -z "$CacheDir" ]; then
        debug_echo "practically empty Dir::Cache, exiting"
        return 0
     fi
 
-    CacheArchive="archives/"
-    eval $(apt-config shell CacheArchive Dir::Cache::Archives)
-    CacheArchive=${CacheArchive%/}
-    if [ -z "$CacheArchive" ]; then
+    Cache="${CacheDir}/archives/"
+    eval $(apt-config shell Cache Dir::Cache::Archives/d)
+    if [ -z "$Cache" ]; then
        debug_echo "practically empty Dir::Cache::archives, exiting"
        return 0
     fi
@@ -268,16 +239,15 @@ do_cache_backup()
        BackupLevel=2 ; 
     fi
     
-    CacheBackup="backup/"
-    eval $(apt-config shell CacheBackup Dir::Cache::Backup)
-    CacheBackup=${CacheBackup%/}
-    if [ -z "$CacheBackup" ]; then
+    Back="${CacheDir}/backup/"
+    eval $(apt-config shell Back Dir::Cache::Backup/d)
+    if [ -z "$Back" ]; then
        echo "practically empty Dir::Cache::Backup, exiting" 1>&2
        return
     fi
 
-    Cache="${Dir}/${CacheDir}/${CacheArchive}/"
-    Back="${Dir}/${CacheDir}/${CacheBackup}/"
+    CacheArchive="$(basename "${Cache}")"
+    test -n "${CacheArchive}" || CacheArchive="archives"
     BackX="${Back}${CacheArchive}/"
     for x in $(seq 0 1 $((${BackupLevel}-1))); do 
        eval "Back${x}=${Back}${x}/"
@@ -337,6 +307,15 @@ debug_echo()
 
 # ------------------------ main ----------------------------
 
+# Backup the 7 last versions of APT's extended_states file
+# shameless copy from dpkg cron
+if cd /var/backups ; then
+    if ! cmp -s apt.extended_states.0 /var/lib/apt/extended_states; then
+       cp -p /var/lib/apt/extended_states apt.extended_states
+       savelog -c 7 apt.extended_states >/dev/null
+    fi
+fi
+
 # check apt-config exstance
 if ! which apt-config >/dev/null ; then
        exit 0
@@ -401,10 +380,11 @@ now=$(date +%s)
 # Document only Periodic for all controling parameters of this script.
 
 UpdateInterval=0
+eval $(apt-config shell UpdateInterval APT::Periodic::Update-Package-Lists)
+
 DownloadUpgradeableInterval=0
-eval $(apt-config shell UpdateInterval APT::Periodic::Update-Package-Lists DownloadUpgradeableInterval APT::Periodic::Download-Upgradeable-Packages)
-AutocleanInterval=$DownloadUpgradeableInterval
-eval $(apt-config shell AutocleanInterval APT::Periodic::AutocleanInterval)
+eval $(apt-config shell DownloadUpgradeableInterval APT::Periodic::Download-Upgradeable-Packages)
+
 UnattendedUpgradeInterval=0
 eval $(apt-config shell UnattendedUpgradeInterval APT::Periodic::Unattended-Upgrade)
 
@@ -421,6 +401,7 @@ eval $(apt-config shell Debdelta APT::Periodic::Download-Upgradeable-Packages-De
 if [ $UpdateInterval -eq 0 ] &&
    [ $DownloadUpgradeableInterval -eq 0 ] &&
    [ $UnattendedUpgradeInterval -eq 0 ] &&
+   [ $BackupArchiveInterval -eq 0 ] &&
    [ $AutocleanInterval -eq 0 ]; then
 
     # check cache size
@@ -440,13 +421,7 @@ random_sleep
 UPDATED=0
 UPDATE_STAMP=/var/lib/apt/periodic/update-stamp
 if check_stamp $UPDATE_STAMP $UpdateInterval; then
-    # check for a new archive signing key (against the master keyring)
-    if eval apt-key net-update $XSTDERR; then
-       debug_echo "apt-key net-update (success)"
-    else
-       debug_echo "apt-key net-update (failure)"
-    fi
-    if eval apt-get $XAPTOPT -y update -o APT::Update::Auth-Failure::=\"cp /usr/share/apt/apt-auth-failure.note /var/lib/update-notifier/user.d/\" $XSTDERR; then
+    if eval apt-get $XAPTOPT -y update $XSTDERR; then
        debug_echo "download updated metadata (success)."
        if which dbus-send >/dev/null && pidof dbus-daemon >/dev/null; then
            if dbus-send --system / app.apt.dbus.updated boolean:true ; then
@@ -459,11 +434,6 @@ if check_stamp $UPDATE_STAMP $UpdateInterval; then
        fi
        update_stamp $UPDATE_STAMP
        UPDATED=1
-       # now run apt-xapian-index if it is installed to ensure the index
-       # is up-to-date
-       if [ -x /usr/sbin/update-apt-xapian-index ]; then
-           ionice -c3 update-apt-xapian-index -q
-       fi
     else
        debug_echo "download updated metadata (error)"
     fi