source: trunk/debathena/config/auto-update/debian/debathena-auto-update.postinst @ 24935

Revision 24935, 2.2 KB checked in by jdreed, 13 years ago (diff)
In auto-update: * Generate crontabs at configure time * Run an update at boot time if it's been too long since the last one
Line 
1#!/bin/sh
2# postinst script for debathena-auto-update
3#
4# see: dh_installdeb(1)
5
6set -e
7
8# summary of how this script can be called:
9#        * <postinst> `configure' <most-recently-configured-version>
10#        * <old-postinst> `abort-upgrade' <new version>
11#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
12#          <new-version>
13#        * <postinst> `abort-remove'
14#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
15#          <failed-install-package> <version> `removing'
16#          <conflicting-package> <version>
17# for details, see http://www.debian.org/doc/debian-policy/ or
18# the debian-policy package
19
20desync2cron() {
21    hour=$1
22    interval=$2
23    shift 2
24    desync=`desync -n $interval`
25    mins=`echo $desync % 60 | bc`
26    hours=`echo "$hour + ($desync / 60)" | bc`
27    if [ $hours -ge 24 ]; then
28        hours=`echo $hours - 24 | bc`
29    fi
30    echo "$mins $hours * * * $*"
31}
32
33UPD_CRONFILE=/etc/cron.d/athena-auto-update
34UPG_CRONFILE=/etc/cron.d/athena-auto-upgrade
35
36case "$1" in
37    configure)
38        # Nuke /var/lib/athena-update-status on 1.18,
39        # since we changed its format. It will be created
40        # at the next auto update
41        if dpkg --compare-versions "$2" lt 1.18~ &&
42            [ -f /var/lib/athena-update-status ]; then
43            rm /var/lib/athena-update-status
44        fi
45
46        rm -f $UPD_CRONFILE
47        rm -f $UPG_CRONFILE
48
49        echo "# Automatically generated by debathena-auto-update postinst" > $UPD_CRONFILE
50        for h in 2 4 6; do
51            desync2cron $h 120 root /usr/sbin/athena-auto-update cron >> $UPD_CRONFILE
52        done
53        for h in 8 14 20; do
54            desync2cron $h 360 root /usr/sbin/athena-auto-update cron >> $UPD_CRONFILE
55        done
56        echo "# Automatically generated by debathena-auto-update postinst" > $UPG_CRONFILE
57
58        upginterval=360
59        hostname=`hostname | tr 'A-Z' 'a-z'`
60        case $hostname in
61            m38-370*)
62                upginterval=420
63                ;;
64            w20-575*)
65                upginterval=480
66                ;;
67        esac
68        desync2cron 2 $upginterval root /usr/sbin/athena-auto-upgrade >> $UPG_CRONFILE
69       
70    ;;
71
72    abort-upgrade|abort-remove|abort-deconfigure)
73    ;;
74
75    *)
76        echo "postinst called with unknown argument \`$1'" >&2
77        exit 1
78    ;;
79esac
80
81# dh_installdeb will replace this with shell code automatically
82# generated by other debhelper scripts.
83
84#DEBHELPER#
85
86exit 0
Note: See TracBrowser for help on using the repository browser.