summaryrefslogtreecommitdiff
path: root/debian/apt.cron.daily
blob: 67b58747e8fcb19d62cf1ffc4d1e9d360ad3a898 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
#
# cron job for apt-get update
#
# Update-Package-Intervall is in days
#
STAMP=/var/lib/apt/update-stamp

#set -e

do_update()
{
    touch $STAMP.new
    if apt-get update -qq; then
	if [ -x /usr/bin/dbus-send ]; then
	    dbus-send --system / app.apt.dbus.updated boolean:true
	fi
        mv $STAMP.new $STAMP
    fi
    rm -f $STAMP.new
}

UpdateInterval=0
RES=`apt-config shell UpdateInterval APT::Periodic::Update-Package-Lists`
eval $RES

if [ $UpdateInterval -eq 0 ]; then
    exit 0
fi

# laptop check, on_ac_power returns:
#       0 (true)    System is on mains power
#       1 (false)   System is not on mains power
#       255 (false) Power status could not be determined
# Desktop systems always return 255 it seems
if [ -x /usr/bin/on_ac_power ]; then
    /usr/bin/on_ac_power 
    if [ $? -eq 1 ]; then
	exit 0
    fi
fi

if [ ! -f $STAMP ]; then
    do_update
    exit 0
fi

LastUpdate=`stat -c "%Y" $STAMP 2>/dev/null` 
Now=`date +%s`

NeedUpdate=$(($LastUpdate+$UpdateInterval*3600*24))
if [ $NeedUpdate -le $Now ]; then
    do_update
fi