]> git.saurik.com Git - apt.git/blame - debian/apt.cron.daily
* sync with matt again
[apt.git] / debian / apt.cron.daily
CommitLineData
0c132682
MZ
1#!/bin/sh
2#
0c132682
MZ
3
4#set -e
5
05f6a46a 6check_stamp()
0c132682 7{
05f6a46a
MZ
8 stamp="$1"
9 interval="$2"
10
10946ddc
MZ
11 if [ $interval -eq 0 ]; then
12 return 1
13 fi
14
05f6a46a
MZ
15 if [ ! -f $stamp ]; then
16 return 0
0c132682 17 fi
05f6a46a
MZ
18
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))
05f6a46a
MZ
23
24 if [ $delta -ge $interval ]; then
25 return 0
26 fi
27
28 return 1
29}
30
31update_stamp()
32{
33 stamp="$1"
34
35 touch $stamp
0c132682
MZ
36}
37
38UpdateInterval=0
05f6a46a 39DownloadUpgradeableInterval=0
9bd1cf87
MZ
40eval $(apt-config shell UpdateInterval APT::Periodic::Update-Package-Lists DownloadUpgradeableInterval APT::Periodic::Download-Upgradeable-Packages)
41AutocleanInterval=$DownloadUpgradeableInterval
42eval $(apt-config shell AutocleanInterval APT::Periodic::Autoclean)
0c132682 43
0c132682
MZ
44# laptop check, on_ac_power returns:
45# 0 (true) System is on mains power
46# 1 (false) System is not on mains power
47# 255 (false) Power status could not be determined
48# Desktop systems always return 255 it seems
2288cf77 49if which on_ac_power >/dev/null; then
05f6a46a 50 on_ac_power
0c132682
MZ
51 if [ $? -eq 1 ]; then
52 exit 0
53 fi
54fi
55
05f6a46a
MZ
56UPDATE_STAMP=/var/lib/apt/periodic/update-stamp
57if check_stamp $UPDATE_STAMP $UpdateInterval; then
58 if apt-get -qq update 2>/dev/null; then
59 if which dbus-send >/dev/null; then
60 dbus-send --system / app.apt.dbus.updated boolean:true
61 fi
62 update_stamp $UPDATE_STAMP
63 fi
0c132682
MZ
64fi
65
05f6a46a
MZ
66DOWNLOAD_UPGRADEABLE_STAMP=/var/lib/apt/periodic/download-upgradeable-stamp
67if check_stamp $DOWNLOAD_UPGRADEABLE_STAMP $DownloadUpgradeableInterval; then
68 apt-get -qq -d dist-upgrade 2>/dev/null
69 update_stamp $DOWNLOAD_UPGRADEABLE_STAMP
0c132682 70fi
9bd1cf87
MZ
71
72AUTOCLEAN_STAMP=/var/lib/apt/periodic/autoclean-stamp
73if check_stamp $AUTOCLEAN_STAMP $AutocleanInterval; then
74 apt-get -qq autoclean
75 update_stamp $AUTOCLEAN_STAMP
76fi