X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/d59725349555939d39af81cf7746069d6aa3536c..40cdb71e715cf1c8e6d8201da307f992763f1654:/debian/apt.cron.daily?ds=sidebyside diff --git a/debian/apt.cron.daily b/debian/apt.cron.daily index 3cf1e28f1..328282a41 100644 --- a/debian/apt.cron.daily +++ b/debian/apt.cron.daily @@ -1,4 +1,6 @@ #!/bin/sh +# + #set -e # # This file understands the following apt configuration variables: @@ -14,6 +16,9 @@ # Dir::Cache::Archive "archives/"; # - Set package archive directory # +# APT::Periodic::Enable "1"; +# - Enable the update/upgrade script (0=disable) +# # APT::Periodic::BackupArchiveInterval "0"; # - Backup after n-days if archive contents changed.(0=disable) # @@ -44,24 +49,33 @@ # 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"; +# - Use debdelta-upgrade to download updates if available (0=disable) +# # APT::Periodic::Unattended-Upgrade "0"; # - Run the "unattended-upgrade" security upgrade script # every n-days (0=disabled) # Requires the package "unattended-upgrades" and will write # a log in /var/log/unattended-upgrades # -# APT::Periodic::AutocleanInterval "0"; -# - Do "apt-get autoclean" every n-days (0=disable) +# "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::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 +# "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::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. +# check_stamp() { @@ -102,9 +116,17 @@ check_stamp() delta=$(($now-$stamp)) - # intervall is in days, convert to sec. + # intervall is in days, interval=$(($interval*60*60*24)) - debug_echo "check_stamp: interval=$interval, now=$now, stamp=$stamp, delta=$delta (sec)" + #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 # remove timestamps a day (or more) in the future and force re-check if [ $stamp -gt $(($now+86400)) ]; then @@ -123,6 +145,7 @@ check_stamp() update_stamp() { stamp="$1" + touch $stamp } @@ -319,12 +342,18 @@ if ! which apt-config >/dev/null ; then exit 0 fi +# check if the user really wants to do something +AutoAptEnable=1 # default is yes +eval $(apt-config shell AutoAptEnable APT::Periodic::Enable) + +if [ $AutoAptEnable -eq 0 ]; then + exit 0 +fi + # Set VERBOSE mode from apt-config (or inherit from environment) +VERBOSE=0 eval $(apt-config shell VERBOSE APT::Periodic::Verbose) debug_echo "verbose level $VERBOSE" -if [ -z "$VERBOSE" ]; then - VERBOSE="0" -fi if [ "$VERBOSE" -le 2 ]; then # quiet for 0,1,2 XSTDOUT=">/dev/null" @@ -360,7 +389,7 @@ if which on_ac_power >/dev/null; then fi # check if we can lock the cache and if the cache is clean -if which apt-get >/dev/null && ! apt-get check $XAPTOPT $XSTDERR ; then +if which apt-get >/dev/null && ! eval apt-get check -f $XAPTOPT $XSTDERR ; then debug_echo "error encountered in cron job with \"apt-get check\"." exit 0 fi @@ -372,11 +401,10 @@ 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 DownloadUpgradeableInterval APT::Periodic::Download-Upgradeable-Packages) - +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) UnattendedUpgradeInterval=0 eval $(apt-config shell UnattendedUpgradeInterval APT::Periodic::Unattended-Upgrade) @@ -386,15 +414,29 @@ eval $(apt-config shell AutocleanInterval APT::Periodic::AutocleanInterval) BackupArchiveInterval=0 eval $(apt-config shell BackupArchiveInterval APT::Periodic::BackupArchiveInterval) +Debdelta=1 +eval $(apt-config shell Debdelta APT::Periodic::Download-Upgradeable-Packages-Debdelta) + # check if we actually have to do anything if [ $UpdateInterval -eq 0 ] && [ $DownloadUpgradeableInterval -eq 0 ] && [ $UnattendedUpgradeInterval -eq 0 ] && - [ $BackupArchiveInterval -eq 0 ] && [ $AutocleanInterval -eq 0 ]; then exit 0 fi +# set the proxy based on the admin users gconf settings +admin_user=$(getent group admin|cut -d: -f4|cut -d, -f1) +if [ -n "$admin_user" ] && [ -x /usr/bin/sudo ] && [ -z "$http_proxy" ] && [ -x /usr/bin/gconftool ]; then + use=$(sudo -u "$admin_user" gconftool --get /system/http_proxy/use_http_proxy 2>/dev/null) + host=$(sudo -u "$admin_user" gconftool --get /system/http_proxy/host 2>/dev/null) + port=$(sudo -u "$admin_user" gconftool --get /system/http_proxy/port 2>/dev/null) + if [ "$use" = "true" ] && [ -n "$host" ] && [ -n "$port" ]; then + export http_proxy="http://$host:$port/" + fi +fi + + # deal with BackupArchiveInterval do_cache_backup $BackupArchiveInterval @@ -403,9 +445,16 @@ do_cache_backup $BackupArchiveInterval random_sleep # update package lists +UPDATED=0 UPDATE_STAMP=/var/lib/apt/periodic/update-stamp if check_stamp $UPDATE_STAMP $UpdateInterval; then - if eval apt-get $XAPTOPT -y update $XSTDERR; 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 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 @@ -417,6 +466,12 @@ if check_stamp $UPDATE_STAMP $UpdateInterval; then debug_echo "dbus signal not send (command not available)" 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 @@ -426,7 +481,10 @@ fi # download all upgradeable packages (if it is requested) DOWNLOAD_UPGRADEABLE_STAMP=/var/lib/apt/periodic/download-upgradeable-stamp -if check_stamp $DOWNLOAD_UPGRADEABLE_STAMP $DownloadUpgradeableInterval; then +if [ $UPDATED -eq 1 ] && check_stamp $DOWNLOAD_UPGRADEABLE_STAMP $DownloadUpgradeableInterval; then + if [ $Debdelta -eq 1 ]; then + debdelta-upgrade >/dev/null 2>&1 || true + fi if eval apt-get $XAPTOPT -y -d dist-upgrade $XSTDERR; then update_stamp $DOWNLOAD_UPGRADEABLE_STAMP debug_echo "download upgradable (success)" @@ -439,7 +497,7 @@ fi # auto upgrade all upgradeable packages UPGRADE_STAMP=/var/lib/apt/periodic/upgrade-stamp -if which unattended-upgrade >/dev/null && check_stamp $UPGRADE_STAMP $UnattendedUpgradeInterval; then +if [ $UPDATED -eq 1 ] && which unattended-upgrade >/dev/null && check_stamp $UPGRADE_STAMP $UnattendedUpgradeInterval; then if unattended-upgrade $XUUPOPT; then update_stamp $UPGRADE_STAMP debug_echo "unattended-upgrade (success)"