11 if [ $interval -eq 0 ]; then
15 if [ ! -f $stamp ]; then
19 # compare midnight today to midnight the day the stamp was updated
20 stamp
=$(date --date=$(date -r $stamp --iso-8601) +%s
)
21 now
=$(date --date=$(date --iso-8601) +%s
)
22 delta
=$(($now-$stamp))
24 if [ $delta -ge $interval ]; then
40 # we check here if autoclean was enough sizewise
41 check_size_constraints
()
46 CacheDir
="var/cache/apt"
47 CacheArchive
="archives/"
48 eval $(apt-config shell MaxAge APT::Archives::MaxAge)
49 eval $(apt-config shell MaxSize APT::Archives::MaxSize)
50 eval $(apt-config shell Dir Dir)
51 eval $(apt-config shell CacheDir Dir::Cache)
52 eval $(apt-config shell CacheArchive Dir::Cache::archives)
55 if [ -z "$CacheDir" -o -z "$CacheArchive" ]; then
56 echo "empty Dir::Cache or Dir::Cache::archives, exiting"
60 Cache
="${Dir%/}/${CacheDir%/}/${CacheArchive%/}/"
63 if [ ! $MaxAge -eq 0 ]; then
64 find $Cache -name "*.deb" -mtime +$MaxAge -print0 | xargs -r -0 rm -f
68 if [ ! $MaxSize -eq 0 ]; then
69 # reverse-sort by mtime
70 for file in $(ls -rt $Cache/*.deb); do
73 # check if the cache is small enough
74 if [ $size -lt $MaxSize ]; then
85 DownloadUpgradeableInterval
=0
86 eval $(apt-config shell UpdateInterval APT::Periodic::Update-Package-Lists DownloadUpgradeableInterval APT::Periodic::Download-Upgradeable-Packages)
87 AutocleanInterval
=$DownloadUpgradeableInterval
88 eval $(apt-config shell AutocleanInterval APT::Periodic::Autoclean)
90 # laptop check, on_ac_power returns:
91 # 0 (true) System is on mains power
92 # 1 (false) System is not on mains power
93 # 255 (false) Power status could not be determined
94 # Desktop systems always return 255 it seems
95 if which on_ac_power
>/dev
/null
; then
102 UPDATE_STAMP
=/var
/lib
/apt
/periodic
/update
-stamp
103 if check_stamp
$UPDATE_STAMP $UpdateInterval; then
104 if apt
-get -qq update
2>/dev
/null
; then
105 if which dbus
-send >/dev
/null
; then
106 dbus
-send --system / app.apt.dbus.updated boolean
:true
108 update_stamp
$UPDATE_STAMP
112 DOWNLOAD_UPGRADEABLE_STAMP
=/var
/lib
/apt
/periodic
/download
-upgradeable-stamp
113 if check_stamp
$DOWNLOAD_UPGRADEABLE_STAMP $DownloadUpgradeableInterval; then
114 apt
-get -qq -d dist
-upgrade 2>/dev
/null
115 update_stamp
$DOWNLOAD_UPGRADEABLE_STAMP
118 AUTOCLEAN_STAMP
=/var
/lib
/apt
/periodic
/autoclean
-stamp
119 if check_stamp
$AUTOCLEAN_STAMP $AutocleanInterval; then
120 apt
-get -qq autoclean
121 update_stamp
$AUTOCLEAN_STAMP
125 check_size_constraints