]> git.saurik.com Git - apt.git/blob - debian/apt.cron.daily
Add cron.daily
[apt.git] / debian / apt.cron.daily
1 #!/bin/sh
2 #
3 # cron job for apt-get update
4 #
5 # Update-Package-Intervall is in days
6 #
7 STAMP=/var/lib/apt/update-stamp
8
9 #set -e
10
11 do_update()
12 {
13 touch $STAMP.new
14 if apt-get update -qq; then
15 if [ -x /usr/bin/dbus-send ]; then
16 dbus-send --system / app.apt.dbus.updated boolean:true
17 fi
18 mv $STAMP.new $STAMP
19 fi
20 rm -f $STAMP.new
21 }
22
23 UpdateInterval=0
24 RES=`apt-config shell UpdateInterval APT::Periodic::Update-Package-Lists`
25 eval $RES
26
27 if [ $UpdateInterval -eq 0 ]; then
28 exit 0
29 fi
30
31 # laptop check, on_ac_power returns:
32 # 0 (true) System is on mains power
33 # 1 (false) System is not on mains power
34 # 255 (false) Power status could not be determined
35 # Desktop systems always return 255 it seems
36 if [ -x /usr/bin/on_ac_power ]; then
37 /usr/bin/on_ac_power
38 if [ $? -eq 1 ]; then
39 exit 0
40 fi
41 fi
42
43 if [ ! -f $STAMP ]; then
44 do_update
45 exit 0
46 fi
47
48 LastUpdate=`stat -c "%Y" $STAMP 2>/dev/null`
49 Now=`date +%s`
50
51 NeedUpdate=$(($LastUpdate+$UpdateInterval*3600*24))
52 if [ $NeedUpdate -le $Now ]; then
53 do_update
54 fi