]> git.decadent.org.uk Git - dak.git/blob - config/debian/cron.reboot
path changes
[dak.git] / config / debian / cron.reboot
1 #!/bin/bash
2 # No way I try to deal with a crippled sh just for POSIX foo.
3
4 # Copyright (C) 2009 Joerg Jaspert <joerg@debian.org>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; version 2.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 # exit on errors
20 set -e
21 # make sure to only use defined variables
22 set -u
23 # ERR traps should be inherited from functions too. (And command
24 # substitutions and subshells and whatnot, but for us the functions is
25 # the important part here)
26 set -E
27
28 # import the general variable set.
29 export SCRIPTVARS=/srv/ftp-master.debian.org/dak/config/debian/vars
30 . $SCRIPTVARS
31
32 # common functions are "outsourced"
33 . "${configdir}/common"
34
35 # usually we are not using debug logs. Set to 1 if you want them.
36 DEBUG=0
37
38 # our name
39 PROGRAM="dinstall_reboot"
40
41 # where do we want mails to go? For example log entries made with error()
42 if [ "x$(hostname -s)x" != "xriesx" ]; then
43     # Not our ftpmaster host
44     MAILTO=${MAILTO:-"root"}
45 else
46     # Yay, ftpmaster
47     MAILTO=${MAILTO:-"ftpmaster@debian.org"}
48 fi
49
50 # Marker for dinstall start
51 DINSTALLSTART="${lockdir}/dinstallstart"
52 # Marker for dinstall end
53 DINSTALLEND="${lockdir}/dinstallend"
54
55 set +e
56 starttime=$(/usr/bin/stat -c %Z "${DINSTALLSTART}")
57 endtime=$(/usr/bin/stat -c %Z "${DINSTALLEND}")
58 set -e
59
60 if [ ${endtime} -gt ${starttime} ]; then
61         # Great, last dinstall run did seem to end without trouble, no need to rerun
62         log "Last dinstall run did end without trouble, not rerunning"
63         exit 0
64 else
65         # Hrm, it looks like we did not successfully end the last run.
66         # This either means dinstall did abort due to an error, or we had a reboot
67         # No way to tell, so lets restart and see what happens.
68
69         # Make sure we are not fooled by some random touching of the files, only
70         # really restart if we have the first stage stampfile there, indicating that
71         # dinstall got started
72         if [ -f "${stagedir}/savetimestamp" ]; then
73                 log "Seems we have to restart a dinstall run after reboot"
74                 ${configdir}/cron.dinstall
75         fi
76 fi