]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | # | |
3 | ||
4 | #set -e | |
5 | ||
6 | check_stamp() | |
7 | { | |
8 | stamp="$1" | |
9 | interval="$2" | |
10 | ||
11 | if [ ! -f $stamp ]; then | |
12 | return 0 | |
13 | fi | |
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 | |
33 | } | |
34 | ||
35 | UpdateInterval=0 | |
36 | DownloadUpgradeableInterval=0 | |
37 | RES=`apt-config shell UpdateInterval APT::Periodic::Update-Package-Lists DownloadUpgradeableInterval APT::Periodic::Download-Upgradeable-Packages` | |
38 | eval $RES | |
39 | ||
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 | |
45 | if which on_ac_power >/dev/null; then | |
46 | on_ac_power | |
47 | if [ $? -eq 1 ]; then | |
48 | exit 0 | |
49 | fi | |
50 | fi | |
51 | ||
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 | |
60 | fi | |
61 | ||
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 | |
66 | fi |