]>
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 | ||
11 | if [ ! -f $stamp ]; then | |
12 | return 0 | |
0c132682 | 13 | fi |
05f6a46a MZ |
14 | |
15 | # compare midnight today to midnight the day the stamp was updated | |
16 | stamp=$(date --date=$(date -r $stamp --iso-8601) +%s) | |
17 | now=$(date --date=$(date --iso-8601) +%s) | |
18 | delta=$(($now-$stamp)) | |
19 | echo "stamp=$stamp, now=$now, delta=$delta" | |
20 | ||
21 | if [ $delta -ge $interval ]; then | |
22 | return 0 | |
23 | fi | |
24 | ||
25 | return 1 | |
26 | } | |
27 | ||
28 | update_stamp() | |
29 | { | |
30 | stamp="$1" | |
31 | ||
32 | touch $stamp | |
0c132682 MZ |
33 | } |
34 | ||
35 | UpdateInterval=0 | |
05f6a46a MZ |
36 | DownloadUpgradeableInterval=0 |
37 | RES=`apt-config shell UpdateInterval APT::Periodic::Update-Package-Lists DownloadUpgradeableInterval APT::Periodic::Download-Upgradeable-Packages` | |
0c132682 MZ |
38 | eval $RES |
39 | ||
0c132682 MZ |
40 | # laptop check, on_ac_power returns: |
41 | # 0 (true) System is on mains power | |
42 | # 1 (false) System is not on mains power | |
43 | # 255 (false) Power status could not be determined | |
44 | # Desktop systems always return 255 it seems | |
2288cf77 | 45 | if which on_ac_power >/dev/null; then |
05f6a46a | 46 | on_ac_power |
0c132682 MZ |
47 | if [ $? -eq 1 ]; then |
48 | exit 0 | |
49 | fi | |
50 | fi | |
51 | ||
05f6a46a MZ |
52 | UPDATE_STAMP=/var/lib/apt/periodic/update-stamp |
53 | if check_stamp $UPDATE_STAMP $UpdateInterval; then | |
54 | if apt-get -qq update 2>/dev/null; then | |
55 | if which dbus-send >/dev/null; then | |
56 | dbus-send --system / app.apt.dbus.updated boolean:true | |
57 | fi | |
58 | update_stamp $UPDATE_STAMP | |
59 | fi | |
0c132682 MZ |
60 | fi |
61 | ||
05f6a46a MZ |
62 | DOWNLOAD_UPGRADEABLE_STAMP=/var/lib/apt/periodic/download-upgradeable-stamp |
63 | if check_stamp $DOWNLOAD_UPGRADEABLE_STAMP $DownloadUpgradeableInterval; then | |
64 | apt-get -qq -d dist-upgrade 2>/dev/null | |
65 | update_stamp $DOWNLOAD_UPGRADEABLE_STAMP | |
0c132682 | 66 | fi |