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::Archives::MaxAge",
18 # - Set maximum allowed age of a cache package file. If a cache
19 # package file is older it is deleted (0=disable)
21 # "APT::Archives::MaxSize",
22 # - Set maximum size of the cache in MB (0=disable). If the cache
23 # is bigger, cached package files are deleted until the size
24 # requirement is met (the biggest packages will be deleted
27 # "APT::Archives::MinAge"
28 # - Set minimum age of a package file. If a file is younger it
29 # will not be deleted (0=disable). Usefull to prevent races
30 # and to keep backups of the packages for emergency.
38 if [ $interval -eq 0 ]; then
42 if [ ! -f $stamp ]; then
46 # compare midnight today to midnight the day the stamp was updated
47 stamp
=$(date --date=$(date -r $stamp --iso-8601) +%s
)
48 now
=$(date --date=$(date --iso-8601) +%s
)
49 delta
=$(($now-$stamp))
51 # intervall is in days,
52 interval
=$(($interval*60*60*24))
54 #echo "interval=$interval, now=$now, stamp=$stamp, delta=$delta"
56 if [ $delta -ge $interval ]; then
72 # we check here if autoclean was enough sizewise
73 check_size_constraints
()
79 CacheDir
="var/cache/apt"
80 CacheArchive
="archives/"
81 eval $(apt-config shell MaxAge APT::Archives::MaxAge)
82 eval $(apt-config shell MinAge APT::Archives::MinAge)
83 eval $(apt-config shell MaxSize APT::Archives::MaxSize)
84 eval $(apt-config shell Dir Dir)
85 eval $(apt-config shell CacheDir Dir::Cache)
86 eval $(apt-config shell CacheArchive Dir::Cache::archives)
89 if [ -z "$CacheDir" -o -z "$CacheArchive" ]; then
90 echo "empty Dir::Cache or Dir::Cache::archives, exiting"
94 Cache
="${Dir%/}/${CacheDir%/}/${CacheArchive%/}/"
97 if [ ! $MaxAge -eq 0 ] && [ ! $MinAge -eq 0 ]; then
98 find $Cache -name "*.deb" -mtime +$MaxAge -and -not -mtime -$MinAge -print0 | xargs -r -0 rm -f
99 elif [ ! $MaxAge -eq 0 ]; then
100 find $Cache -name "*.deb" -mtime +$MaxAge -print0 | xargs -r -0 rm -f
104 if [ ! $MaxSize -eq 0 ]; then
106 MaxSize
=$(($MaxSize*1024))
109 now
=$(date --date=$(date --iso-8601) +%s
)
110 MinAge
=$(($MinAge*24*60*60))
112 # reverse-sort by mtime
113 for file in $(ls -rt $Cache/*.deb); do
116 # check if the cache is small enough
117 if [ $size -lt $MaxSize ]; then
121 # check for MinAge of the file
122 if [ ! $MinAge -eq 0 ]; then
123 mtime
=$(date --date=$(date -r $file --iso-8601) +%s
)
124 delta
=$(($now-$mtime))
125 #echo "$file ($delta), $MinAge"
126 if [ $delta -le $MinAge ]; then
127 #echo "Skiping $file (delta=$delta)"
140 DownloadUpgradeableInterval
=0
141 eval $(apt-config shell UpdateInterval APT::Periodic::Update-Package-Lists DownloadUpgradeableInterval APT::Periodic::Download-Upgradeable-Packages)
142 AutocleanInterval
=$DownloadUpgradeableInterval
143 eval $(apt-config shell AutocleanInterval APT::Periodic::Autoclean)
145 # laptop check, on_ac_power returns:
146 # 0 (true) System is on mains power
147 # 1 (false) System is not on mains power
148 # 255 (false) Power status could not be determined
149 # Desktop systems always return 255 it seems
150 if which on_ac_power
>/dev
/null
; then
152 if [ $?
-eq 1 ]; then
157 UPDATE_STAMP
=/var
/lib
/apt
/periodic
/update
-stamp
158 if check_stamp
$UPDATE_STAMP $UpdateInterval; then
159 if apt
-get -qq update
2>/dev
/null
; then
160 if which dbus
-send >/dev
/null
; then
161 dbus
-send --system / app.apt.dbus.updated boolean
:true
163 update_stamp
$UPDATE_STAMP
167 DOWNLOAD_UPGRADEABLE_STAMP
=/var
/lib
/apt
/periodic
/download
-upgradeable-stamp
168 if check_stamp
$DOWNLOAD_UPGRADEABLE_STAMP $DownloadUpgradeableInterval; then
169 apt
-get -qq -d dist
-upgrade 2>/dev
/null
170 update_stamp
$DOWNLOAD_UPGRADEABLE_STAMP
173 AUTOCLEAN_STAMP
=/var
/lib
/apt
/periodic
/autoclean
-stamp
174 if check_stamp
$AUTOCLEAN_STAMP $AutocleanInterval; then
175 apt
-get -qq autoclean
176 update_stamp
$AUTOCLEAN_STAMP
180 check_size_constraints