6 # This file understands the following apt configuration variables:
8 # "APT::Periodic::Update-Package-Lists=1"
9 # - Do "apt-get update" automatically every n-days (0=disable)
11 # "APT::Periodic::Download-Upgradeable-Packages=0",
12 # - Do "apt-get upgrade --download-only" every n-days (0=disable)
14 # "APT::Periodic::AutocleanInterval"
15 # - Do "apt-get autoclean" every n-days (0=disable)
17 # "APT::Periodic::Unattended-Upgrade"
18 # - Run the "unattended-upgrade" security upgrade script
19 # every n-days (0=disabled)
20 # Requires the package "unattended-upgrades" and will write
21 # a log in /var/log/unattended-upgrades
23 # "APT::Archives::MaxAge",
24 # - Set maximum allowed age of a cache package file. If a cache
25 # package file is older it is deleted (0=disable)
27 # "APT::Archives::MaxSize",
28 # - Set maximum size of the cache in MB (0=disable). If the cache
29 # is bigger, cached package files are deleted until the size
30 # requirement is met (the biggest packages will be deleted
33 # "APT::Archives::MinAge"
34 # - Set minimum age of a package file. If a file is younger it
35 # will not be deleted (0=disable). Usefull to prevent races
36 # and to keep backups of the packages for emergency.
44 if [ $interval -eq 0 ]; then
48 if [ ! -f $stamp ]; then
52 # compare midnight today to midnight the day the stamp was updated
54 stamp
=$(date --date=$(date -r $stamp_file --iso-8601) +%s
2>/dev
/null
)
55 if [ "$?" != "0" ]; then
56 # Due to some timezones returning 'invalid date' for midnight on
57 # certain dates (eg America/Sao_Paulo), if date returns with error
58 # remove the stamp file and return 0. See coreutils bug:
59 # http://lists.gnu.org/archive/html/bug-coreutils/2007-09/msg00176.html
64 now
=$(date --date=$(date --iso-8601) +%s
2>/dev
/null
)
65 if [ "$?" != "0" ]; then
66 # As above, due to some timezones returning 'invalid date' for midnight
67 # on certain dates (eg America/Sao_Paulo), if date returns with error
72 delta
=$(($now-$stamp))
74 # intervall is in days,
75 interval
=$(($interval*60*60*24))
77 #echo "interval=$interval, now=$now, stamp=$stamp, delta=$delta"
79 # remove timestamps a day (or more) in the future and force re-check
80 if [ $stamp -gt $(($now+86400)) ]; then
81 echo "WARNING: file $stamp_file has a timestamp in the future: $stamp"
86 if [ $delta -ge $interval ]; then
102 # we check here if autoclean was enough sizewise
103 check_size_constraints
()
109 CacheDir
="var/cache/apt"
110 CacheArchive
="archives/"
111 eval $(apt-config shell MaxAge APT::Archives::MaxAge)
112 eval $(apt-config shell MinAge APT::Archives::MinAge)
113 eval $(apt-config shell MaxSize APT::Archives::MaxSize)
114 eval $(apt-config shell Dir Dir)
115 eval $(apt-config shell CacheDir Dir::Cache)
116 eval $(apt-config shell CacheArchive Dir::Cache::archives)
119 if [ -z "$CacheDir" -o -z "$CacheArchive" ]; then
120 echo "empty Dir::Cache or Dir::Cache::archives, exiting"
124 Cache
="${Dir%/}/${CacheDir%/}/${CacheArchive%/}/"
127 if [ ! $MaxAge -eq 0 ] && [ ! $MinAge -eq 0 ]; then
128 find $Cache -name "*.deb" \
( -mtime +$MaxAge -and -ctime +$MaxAge \
) -and -not \
( -mtime -$MinAge -or -ctime -$MinAge \
) -print0 | xargs -r -0 rm -f
129 elif [ ! $MaxAge -eq 0 ]; then
130 find $Cache -name "*.deb" -ctime +$MaxAge -and -mtime +$MaxAge -print0 | xargs -r -0 rm -f
134 if [ ! $MaxSize -eq 0 ]; then
136 MaxSize
=$(($MaxSize*1024))
139 now
=$(date --date=$(date --iso-8601) +%s
)
140 MinAge
=$(($MinAge*24*60*60))
142 # reverse-sort by mtime
143 for file in $(ls -rt $Cache/*.deb 2>/dev/null); do
146 # check if the cache is small enough
147 if [ $size -lt $MaxSize ]; then
151 # check for MinAge of the file
152 if [ ! $MinAge -eq 0 ]; then
153 # check both ctime and mtime
154 mtime
=$(stat -c %Y $file)
155 ctime
=$(stat -c %Z $file)
156 if [ $mtime -gt $ctime ]; then
157 delta
=$(($now-$mtime))
159 delta
=$(($now-$ctime))
161 #echo "$file ($delta), $MinAge"
162 if [ $delta -le $MinAge ]; then
163 #echo "Skiping $file (delta=$delta)"
174 # sleep for a random interval of time (default 30min)
175 # (some code taken from cron-apt, thanks)
179 eval $(apt-config shell RandomSleep APT::Periodic::RandomSleep)
180 if [ $RandomSleep -eq 0 ]; then
183 if [ -z "$RANDOM" ] ; then
184 # A fix for shells that do not have this bash feature.
185 RANDOM
=$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -c"1-5")
187 TIME
=$(($RANDOM % $RandomSleep))
193 if ! which apt
-config >/dev
/null
; then
198 DownloadUpgradeableInterval
=0
199 eval $(apt-config shell UpdateInterval APT::Periodic::Update-Package-Lists DownloadUpgradeableInterval APT::Periodic::Download-Upgradeable-Packages)
200 AutocleanInterval
=$DownloadUpgradeableInterval
201 eval $(apt-config shell AutocleanInterval APT::Periodic::AutocleanInterval)
202 UnattendedUpgradeInterval
=0
203 eval $(apt-config shell UnattendedUpgradeInterval APT::Periodic::Unattended-Upgrade)
205 # check if we actually have to do anything
206 if [ $UpdateInterval -eq 0 ] &&
207 [ $DownloadUpgradeableInterval -eq 0 ] &&
208 [ $UnattendedUpgradeInterval -eq 0 ] &&
209 [ $AutocleanInterval -eq 0 ]; then
213 # laptop check, on_ac_power returns:
214 # 0 (true) System is on mains power
215 # 1 (false) System is not on mains power
216 # 255 (false) Power status could not be determined
217 # Desktop systems always return 255 it seems
218 if which on_ac_power
>/dev
/null
; then
220 if [ $?
-eq 1 ]; then
225 # sleep random amount of time to avoid hitting the
226 # mirrors at the same time
229 # check if we can access the cache
230 if ! apt
-get check
-q -q 2>/dev
/null
; then
231 # wait random amount of time before retrying
234 if ! apt
-get check
-q -q 2>/dev
/null
; then
235 echo "$0: could not lock the APT cache while performing daily cron job. "
236 echo "Is another package manager working?"
241 # set the proxy based on the admin users gconf settings
242 admin_user
=$(getent group admin|cut -d: -f4|cut -d, -f1)
243 if [ -n "$admin_user" ] && [ -x /usr
/bin
/sudo
] && [ -z "$http_proxy" ] && [ -x /usr
/bin
/gconftool
]; then
244 use
=$(sudo -u "$admin_user" gconftool --get /system/http_proxy/use_http_proxy 2>/dev/null)
245 host=$(sudo -u "$admin_user" gconftool --get /system/http_proxy/host 2>/dev/null)
246 port
=$(sudo -u "$admin_user" gconftool --get /system/http_proxy/port 2>/dev/null)
247 if [ "$use" = "true" ] && [ -n "$host" ] && [ -n "$port" ]; then
248 export http_proxy
="http://$host:$port/"
252 UPDATE_STAMP
=/var
/lib
/apt
/periodic
/update
-stamp
253 if check_stamp
$UPDATE_STAMP $UpdateInterval; then
254 # check for a new archive signing key (against the master keyring)
257 if apt
-get -qq update
-o APT
::Update
::Auth
-Failure::="cp /usr/share/apt/apt-auth-failure.note /var/lib/update-notifier/user.d/" 2>/dev
/null
; then
258 # Could possible test access to '/var/run/dbus/system_bus_socket' has well,
259 # but I'm not sure how stable the internal pipe location is defined as
260 # being; so for the moment just 2>/dev/null . --sladen 2007-09-27
261 if which dbus
-send >/dev
/null
; then
262 dbus
-send --system / app.apt.dbus.updated boolean
:true
2>/dev
/null
|| true
264 # now run apt-xapian-index if it is installed to ensure the index
266 if [ -x /usr
/sbin
/update
-apt-xapian-index ]; then
267 ionice
-c3 update
-apt-xapian-index -q
269 update_stamp
$UPDATE_STAMP
273 DOWNLOAD_UPGRADEABLE_STAMP
=/var
/lib
/apt
/periodic
/download
-upgradeable-stamp
274 if check_stamp
$DOWNLOAD_UPGRADEABLE_STAMP $DownloadUpgradeableInterval; then
275 apt
-get -qq -d dist
-upgrade 2>/dev
/null
276 update_stamp
$DOWNLOAD_UPGRADEABLE_STAMP
279 UPGRADE_STAMP
=/var
/lib
/apt
/periodic
/upgrade
-stamp
280 if check_stamp
$UPGRADE_STAMP $UnattendedUpgradeInterval; then
282 update_stamp
$UPGRADE_STAMP
285 AUTOCLEAN_STAMP
=/var
/lib
/apt
/periodic
/autoclean
-stamp
286 if check_stamp
$AUTOCLEAN_STAMP $AutocleanInterval; then
287 apt
-get -qq autoclean
288 update_stamp
$AUTOCLEAN_STAMP
292 check_size_constraints