source: trunk/debathena/scripts/build-server/autodebathenify @ 24352

Revision 24352, 3.8 KB checked in by broder, 15 years ago (diff)
Use /bin/bash for the auto{livebuilder,debathenificator}.
  • Property svn:executable set to *
Line 
1#!/bin/bash
2
3# This script is intended to be run from a cron job by a local account
4# on a build machine--either debuild on debuild.mit.edu or builder on
5# linux-build-10.mit.edu.  The account should have:
6#
7# * A keytab installed in $HOME/keytab containing a keytab for
8#   daemon/HOSTNAME, which should have write access to the build
9#   directory and apt repository.
10#
11# * A GPG secret key capable of signing packages for the apt
12#   repository.
13#
14# * A file named $HOME/autodebathenify.config specifying shell
15#   variable assignments for:
16#   - error_addr: An email address to send errors to
17#   - scripts_dir: Directory containing Debathena scripts (da, etc.)
18#   - build_dir: Build directory location, up through "third".
19#   - packages: A list of packages to keep up to date
20#   It should also specify an environment variable assignment for
21#   DEBATHENA_APT.
22
23# Send all output to a logfile.
24mkdir -p "$HOME/logs"
25logfile=$HOME/logs/$(date '+%Y-%m-%d-%H').log
26exec </dev/null >>$logfile 2>&1
27
28# Read configuration; if it's not complete, do nothing.
29config=$HOME/autodebathenify.config
30. $HOME/autodebathenify.config
31if [ ! -n "$error_addr" -o ! -n "$scripts_dir" -o ! -n "$build_dir" -o \
32     ! -n "$packages" ]; then
33  echo "Incomplete $config; doing nothing."
34  exit
35fi
36
37suppress=$HOME/autodebathenify.suppress
38if [ -e "$suppress" ]; then
39  echo "$suppress exists; not running."
40  exit
41fi
42
43# Send an error report to $error_addr and suppress future runs until a
44# human has checked things out.  This function does not remove the run
45# file and does not exit the script.
46error() {
47  touch "$suppress"
48  /usr/sbin/sendmail -t << EOM
49From: Autodebathenify <$error_addr>
50To: Autodebathenify <$error_addr>
51Subject: Autodebathenify failure: $1
52
53Autodebathenify has experienced a failure.
54
55Please see $logfile on $(hostname) for more details.
56
57Autodebathenify will stop running until $suppress is removed.
58EOM
59}
60
61# Similar to error, but do not suppress future runs.
62error_transient() {
63  /usr/sbin/sendmail -t << EOM
64From: Autodebathenify <$error_addr>
65To: Autodebathenify <$error_addr>
66Subject: Autodebathenify failure: $1
67
68Autodebathenify has experienced a transient failure.
69
70Autodebathenify will continue running; investigation is not required
71unless this failure repeats itself.  If that happens, see $logfile on
72$(hostname) for more details.
73EOM
74}
75
76# Exit handler.  If a subsidiary command exited with status 3, we
77# treat it as a transient failure; otherwise we treat it as a failure
78# requiring human investigation.  In either case, remove the run file.
79on_failure() {
80  if [ 3 -eq "$?" ]; then
81    error_transient "$state"
82  else
83    error "$state"
84  fi
85  rm -f "$runfile"
86}
87
88# Make sure runs of this script do not overlap.
89runfile=$HOME/autodebathenify.running
90if [ -e "$runfile" ]; then
91  # A previous invocation appears to still be running.
92  pid=$(cat "$runfile")
93  if ! kill -0 "$pid" 2>/dev/null; then
94    # Okay, it's not really running.  Perhaps the machine has
95    # rebooted.  Wait for manual intervention before running again.
96    error "Stale runfile"
97  else
98    echo "$runfile exists; not running."
99  fi
100  exit
101fi
102echo $$ > $runfile
103
104trap on_failure EXIT
105set -e
106
107# Acquire credentials.
108state="acquiring credentials"
109export KRB5CCNAME=$HOME/autodebathenify.ccache
110kinit -k -t "$HOME/keytab" daemon/$(hostname --fqdn)
111aklog
112
113export PATH=${scripts_dir}:$PATH
114. "$scripts_dir"/debian-versions.sh
115
116state="changing to build dir"
117cd "$build_dir"
118for pkg in $packages; do
119  state="changing to $pkg in build dir"
120  cd "$pkg"
121  for code in $DEBIAN_CODES; do
122    state="updating $pkg for $code"
123    echo "--- Updating $pkg for $code (amd64) ---"
124    ./debathenify-"$pkg" "$code"-amd64 -A source binary upload
125    echo "--- Updating $pkg for $code (i386) ---"
126    ./debathenify-"$pkg" "$code"-i386 source binary upload
127  done
128  cd ..
129done
130
131state="cleaning up"
132kdestroy
133rm -f "$runfile"
134trap '' EXIT
Note: See TracBrowser for help on using the repository browser.