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
53 stamp
=$
(date --date=$
(date -r $stamp --iso-8601) +%s
)
54 now
=$
(date --date=$
(date --iso-8601) +%s
)
55 delta
=$
(($now-$stamp))
57 # intervall is in days,
58 interval
=$
(($interval*60*60*24))
60 #echo "interval=$interval, now=$now, stamp=$stamp, delta=$delta"
62 if [ $delta -ge $interval ]; then
78 # we check here if autoclean was enough sizewise
79 check_size_constraints
()
85 CacheDir
="var/cache/apt"
86 CacheArchive
="archives/"
87 eval $
(apt-config shell MaxAge APT
::Archives
::MaxAge
)
88 eval $
(apt-config shell MinAge APT
::Archives
::MinAge
)
89 eval $
(apt-config shell MaxSize APT
::Archives
::MaxSize
)
90 eval $
(apt-config shell Dir Dir
)
91 eval $
(apt-config shell CacheDir Dir
::Cache
)
92 eval $
(apt-config shell CacheArchive Dir
::Cache
::archives
)
95 if [ -z "$CacheDir" -o -z "$CacheArchive" ]; then
96 echo "empty Dir::Cache or Dir::Cache::archives, exiting"
100 Cache
="${Dir%/}/${CacheDir%/}/${CacheArchive%/}/"
103 if [ ! $MaxAge -eq 0 ] && [ ! $MinAge -eq 0 ]; then
104 find $Cache -name "*.deb" \
( -mtime +$MaxAge -and -ctime +$MaxAge \
) -and -not \
( -mtime -$MinAge -or -ctime -$MinAge \
) -print0 |
xargs -r -0 rm -f
105 elif [ ! $MaxAge -eq 0 ]; then
106 find $Cache -name "*.deb" -ctime +$MaxAge -and -mtime +$MaxAge -print0 |
xargs -r -0 rm -f
110 if [ ! $MaxSize -eq 0 ]; then
112 MaxSize
=$
(($MaxSize*1024))
115 now
=$
(date --date=$
(date --iso-8601) +%s
)
116 MinAge
=$
(($MinAge*24*60*60))
118 # reverse-sort by mtime
119 for file in $
(ls -rt $Cache/*.deb
2>/dev
/null
); do
122 # check if the cache is small enough
123 if [ $size -lt $MaxSize ]; then
127 # check for MinAge of the file
128 if [ ! $MinAge -eq 0 ]; then
129 # check both ctime and mtime
130 mtime
=$
(stat
-c %Y
$file)
131 ctime
=$
(stat
-c %Z
$file)
132 if [ $mtime -gt $ctime ]; then
133 delta
=$
(($now-$mtime))
135 delta
=$
(($now-$ctime))
137 #echo "$file ($delta), $MinAge"
138 if [ $delta -le $MinAge ]; then
139 #echo "Skiping $file (delta=$delta)"
150 # sleep for a random interval of time (default 30min)
151 # (some code taken from cron-apt, thanks)
155 eval $
(apt-config shell RandomSleep APT
::Periodic
::RandomSleep
)
156 if [ $RandomSleep -eq 0 ]; then
159 if [ -z "$RANDOM" ] ; then
160 # A fix for shells that do not have this bash feature.
161 RANDOM
=$
(dd if=/dev
/urandom count
=1 2> /dev
/null |
cksum | cut
-c"1-5")
163 TIME
=$
(($RANDOM % $RandomSleep))
169 if ! which apt-config
>/dev
/null
; then
174 DownloadUpgradeableInterval
=0
175 eval $
(apt-config shell UpdateInterval APT
::Periodic
::Update-Package-Lists DownloadUpgradeableInterval APT
::Periodic
::Download-Upgradeable-Packages
)
176 AutocleanInterval
=$DownloadUpgradeableInterval
177 eval $
(apt-config shell AutocleanInterval APT
::Periodic
::AutocleanInterval
)
178 UnattendedUpgradeInterval
=0
179 eval $
(apt-config shell UnattendedUpgradeInterval APT
::Periodic
::Unattended-Upgrade
)
181 # check if we actually have to do anything
182 if [ $UpdateInterval -eq 0 ] &&
183 [ $DownloadUpgradeableInterval -eq 0 ] &&
184 [ $UnattendedUpgradeInterval -eq 0 ] &&
185 [ $AutocleanInterval -eq 0 ]; then
189 # laptop check, on_ac_power returns:
190 # 0 (true) System is on mains power
191 # 1 (false) System is not on mains power
192 # 255 (false) Power status could not be determined
193 # Desktop systems always return 255 it seems
194 if which on_ac_power
>/dev
/null
; then
196 if [ $?
-eq 1 ]; then
201 # sleep random amount of time to avoid hitting the
202 # mirrors at the same time
205 # check if we can access the cache
206 if ! apt-get check
-q -q 2>/dev
/null
; then
207 # wait random amount of time before retrying
210 if ! apt-get check
-q -q 2>/dev
/null
; then
211 echo "$0: could not lock the APT cache while performing daily cron job. "
212 echo "Is another package manager working?"
217 # set the proxy based on the admin users gconf settings
218 admin_user
=$
(getent group admin|cut
-d: -f4|cut
-d, -f1)
219 if [ -n "$admin_user" ] && [ -x /usr
/bin
/sudo
] && [ -z "$http_proxy" ] && [ -x /usr
/bin
/gconftool
]; then
220 use
=$
(sudo
-u "$admin_user" gconftool
--get /system
/http_proxy
/use_http_proxy
2>/dev
/null
)
221 host=$
(sudo
-u "$admin_user" gconftool
--get /system
/http_proxy
/host 2>/dev
/null
)
222 port
=$
(sudo
-u "$admin_user" gconftool
--get /system
/http_proxy
/port
2>/dev
/null
)
223 if [ "$use" = "true" ] && [ -n "$host" ] && [ -n "$port" ]; then
224 export http_proxy
="http://$host:$port/"
228 UPDATE_STAMP
=/var
/lib
/apt
/periodic
/update-stamp
229 if check_stamp
$UPDATE_STAMP $UpdateInterval; then
230 # check for a new archive signing key (against the master keyring)
233 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
234 # Could possible test access to '/var/run/dbus/system_bus_socket' has well,
235 # but I'm not sure how stable the internal pipe location is defined as
236 # being; so for the moment just 2>/dev/null . --sladen 2007-09-27
237 if which dbus-send
>/dev
/null
; then
238 dbus-send
--system / app.apt.dbus.updated boolean
:true
2>/dev
/null || true
240 # now run apt-xapian-index if it is installed to ensure the index
242 if [ -x /usr
/sbin
/update-apt-xapian-index
]; then
243 ionice
-c3 update-apt-xapian-index
-q
245 update_stamp
$UPDATE_STAMP
249 DOWNLOAD_UPGRADEABLE_STAMP
=/var
/lib
/apt
/periodic
/download-upgradeable-stamp
250 if check_stamp
$DOWNLOAD_UPGRADEABLE_STAMP $DownloadUpgradeableInterval; then
251 apt-get
-qq -d dist-upgrade
2>/dev
/null
252 update_stamp
$DOWNLOAD_UPGRADEABLE_STAMP
255 UPGRADE_STAMP
=/var
/lib
/apt
/periodic
/upgrade-stamp
256 if check_stamp
$UPGRADE_STAMP $UnattendedUpgradeInterval; then
258 update_stamp
$UPGRADE_STAMP
261 AUTOCLEAN_STAMP
=/var
/lib
/apt
/periodic
/autoclean-stamp
262 if check_stamp
$AUTOCLEAN_STAMP $AutocleanInterval; then
263 apt-get
-qq autoclean
264 update_stamp
$AUTOCLEAN_STAMP
268 check_size_constraints