X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/a3b76cde9b0be9a83ca1548e8a6a91d26d8fa29e..bd8274311db48fdcc78456c17c2d59497b96cc2f:/debian/apt.cron.daily?ds=inline diff --git a/debian/apt.cron.daily b/debian/apt.cron.daily index 5c00f22db..7e976a087 100644 --- a/debian/apt.cron.daily +++ b/debian/apt.cron.daily @@ -3,7 +3,7 @@ # # This file understands the following apt configuration variables: # Values here are the default. -# Create /etc/apt/apt.conf.d/02periodic file to set your preference. +# Create /etc/apt/apt.conf.d/10periodic file to set your preference. # # Dir "/"; # - RootDir for all configuration files @@ -34,14 +34,14 @@ # APT::Archives::MinAge "2"; (old, deprecated) # APT::Periodic::MinAge "2"; (new) # - Set minimum age of a package file. If a file is younger it -# will not be deleted (0=disable). Usefull to prevent races +# will not be deleted (0=disable). Useful to prevent races # and to keep backups of the packages for emergency. # # APT::Archives::MaxSize "0"; (old, deprecated) # APT::Periodic::MaxSize "0"; (new) # - 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 +# requirement is met (the oldest packages will be deleted # first). # # APT::Periodic::Update-Package-Lists "0"; @@ -62,12 +62,28 @@ # APT::Periodic::AutocleanInterval "0"; # - Do "apt-get autoclean" every n-days (0=disable) # +# APT::Periodic::CleanInterval "0"; +# - Do "apt-get clean" every n-days (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::Periodic::RandomSleep "1800"; +# - The apt cron job will delay its execution by a random +# time span between zero and 'APT::Periodic::RandomSleep' +# seconds. +# This is done because otherwise everyone would access the +# mirror servers at the same time and put them collectively +# under very high strain. +# You can set this to '0' if you are using a local mirror and +# do not care about the load spikes. +# Note that sleeping in the apt job will be delaying the +# execution of all subsequent cron.daily jobs. +# check_stamp() { @@ -91,7 +107,7 @@ check_stamp() stamp=$(date --date=$(date -r $stamp_file --iso-8601) +%s 2>/dev/null) if [ "$?" != "0" ]; then # Due to some timezones returning 'invalid date' for midnight on - # certain dates (eg America/Sao_Paulo), if date returns with error + # certain dates (e.g. America/Sao_Paulo), if date returns with error # remove the stamp file and return 0. See coreutils bug: # http://lists.gnu.org/archive/html/bug-coreutils/2007-09/msg00176.html rm -f "$stamp_file" @@ -101,14 +117,14 @@ check_stamp() now=$(date --date=$(date --iso-8601) +%s 2>/dev/null) if [ "$?" != "0" ]; then # As above, due to some timezones returning 'invalid date' for midnight - # on certain dates (eg America/Sao_Paulo), if date returns with error + # on certain dates (e.g. America/Sao_Paulo), if date returns with error # return 0. return 0 fi delta=$(($now-$stamp)) - # intervall is in days, convert to sec. + # interval is in days, convert to sec. interval=$(($interval*60*60*24)) debug_echo "check_stamp: interval=$interval, now=$now, stamp=$stamp, delta=$delta (sec)" @@ -197,11 +213,11 @@ check_size_constraints() delta=$(($now-$ctime)) fi if [ $delta -le $MinAge ]; then - debug_echo "skip remove by archive size: $file, delta=$delta < $MinAgeSec" + debug_echo "skip remove by archive size: $file, delta=$delta < $MinAge" break else # delete oldest file - debug_echo "remove by archive size: $file, delta=$delta >= $MinAgeSec (sec), size=$size >= $MaxSize" + debug_echo "remove by archive size: $file, delta=$delta >= $MinAge (sec), size=$size >= $MaxSize" rm -f $file fi fi @@ -289,7 +305,7 @@ random_sleep() 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") + RANDOM=$(( $(dd if=/dev/urandom bs=2 count=1 2> /dev/null | cksum | cut -d' ' -f1) % 32767 )) fi TIME=$(($RANDOM % $RandomSleep)) debug_echo "sleeping for $TIME seconds" @@ -311,7 +327,7 @@ check_power(){ # 1 (false) System is not on main power # 255 (false) Power status could not be determined # Desktop systems always return 255 it seems - if which on_ac_power >/dev/null; then + if which on_ac_power >/dev/null 2>&1; then on_ac_power POWER=$? if [ $POWER -eq 1 ]; then @@ -338,8 +354,8 @@ if test -r /var/lib/apt/extended_states; then fi fi -# check apt-config exstance -if ! which apt-config >/dev/null ; then +# check apt-config existence +if ! which apt-config >/dev/null 2>&1; then exit 0 fi @@ -375,7 +391,7 @@ fi check_power || exit 0 # check if we can lock the cache and if the cache is clean -if which apt-get >/dev/null && ! eval apt-get check -f $XAPTOPT $XSTDERR ; then +if which apt-get >/dev/null 2>&1 && ! eval apt-get check $XAPTOPT $XSTDERR ; then debug_echo "error encountered in cron job with \"apt-get check\"." exit 0 fi @@ -384,7 +400,7 @@ fi now=$(date +%s) # Support old Archive for compatibility. -# Document only Periodic for all controling parameters of this script. +# Document only Periodic for all controlling parameters of this script. UpdateInterval=0 eval $(apt-config shell UpdateInterval APT::Periodic::Update-Package-Lists) @@ -398,6 +414,9 @@ eval $(apt-config shell UnattendedUpgradeInterval APT::Periodic::Unattended-Upgr AutocleanInterval=0 eval $(apt-config shell AutocleanInterval APT::Periodic::AutocleanInterval) +CleanInterval=0 +eval $(apt-config shell CleanInterval APT::Periodic::CleanInterval) + BackupArchiveInterval=0 eval $(apt-config shell BackupArchiveInterval APT::Periodic::BackupArchiveInterval) @@ -409,7 +428,8 @@ if [ $UpdateInterval -eq 0 ] && [ $DownloadUpgradeableInterval -eq 0 ] && [ $UnattendedUpgradeInterval -eq 0 ] && [ $BackupArchiveInterval -eq 0 ] && - [ $AutocleanInterval -eq 0 ]; then + [ $AutocleanInterval -eq 0 ] && + [ $CleanInterval -eq 0 ]; then # check cache size check_size_constraints @@ -438,7 +458,7 @@ UPDATE_STAMP=/var/lib/apt/periodic/update-stamp if check_stamp $UPDATE_STAMP $UpdateInterval; 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 which dbus-send >/dev/null 2>&1 && pidof dbus-daemon >/dev/null 2>&1; then if dbus-send --system / app.apt.dbus.updated boolean:true ; then debug_echo "send dbus signal (success)" else @@ -474,7 +494,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 which unattended-upgrade >/dev/null 2>&1 && check_stamp $UPGRADE_STAMP $UnattendedUpgradeInterval; then if unattended-upgrade $XUUPOPT; then update_stamp $UPGRADE_STAMP debug_echo "unattended-upgrade (success)" @@ -485,6 +505,19 @@ else debug_echo "unattended-upgrade (not run)" fi +# clean package archive +CLEAN_STAMP=/var/lib/apt/periodic/clean-stamp +if check_stamp $CLEAN_STAMP $CleanInterval; then + if eval apt-get $XAPTOPT -y clean $XSTDERR; then + debug_echo "clean (success)." + update_stamp $CLEAN_STAMP + else + debug_echo "clean (error)" + fi +else + debug_echo "clean (not run)" +fi + # autoclean package archive AUTOCLEAN_STAMP=/var/lib/apt/periodic/autoclean-stamp if check_stamp $AUTOCLEAN_STAMP $AutocleanInterval; then