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