source: trunk/debathena/scripts/build-server/autolivebuilder @ 24354

Revision 24354, 4.3 KB checked in by broder, 14 years ago (diff)
Actually cleanup the autolivebuilder runfile on error.
  • 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 the Debathena build server--i.e. debuild@debuild.mit.edu. The
5# account should have
6#
7# * A GPG secret key to sign the checksums for the live CDs.
8#
9# * A file named $HOME/autolivebuilder.config specifying shell
10#   variable assignments for:
11#   - error_addr: An email address to send errors to
12#   - release: The Ubuntu release to base the live CDs off of
13#   - release_version: The version number of that release
14#   - arch: Which architecture to use for the live CD
15#   - mirror: Which Ubuntu mirror to use
16#   - gpg_opts: A bash array of options to pass to gpg. This should
17#     include which keys to sign the checksums files with
18#   - live_dir: The directory to put the live CDs into
19
20# Send all output to a logfile.
21mkdir -p "$HOME/autolivebuilder-logs"
22logfile=$HOME/autolivebuilder-logs/$(date '+%Y-%m-%d-%H').log
23exec </dev/null >>$logfile 2>&1
24
25# Set default configuration values
26mirror='ubuntu.media.mit.edu'
27
28# Read configuration; if it's not complete, do nothing.
29config=$HOME/autolivebuilder.config
30. $config
31if (! [ -n "$error_addr" ]) || \
32    (! [ -n "release" ]) || \
33    (! [ -n "$release_version" ]) || \
34    (! [ -n "$arch" ]) || \
35    (! [ -n "${gpg_opts[*]}" ]) || \
36    (! [ -n "$live_dir" ]); then
37    echo "Incomplete $config; doing nothing."
38    exit
39fi
40
41suppress=$HOME/autolivebuilder.suppress
42if [ -e "$suppress" ]; then
43    echo "$suppress exists; not running."
44    exit
45fi
46
47# Make sure runs of this script do not overlap.
48runfile=$HOME/autolivebuilder.running
49if [ -e "$runfile" ]; then
50  # A previous invocation appears to still be running.
51  pid=$(cat "$runfile")
52  if ! kill -0 "$pid" 2>/dev/null; then
53    # Okay, it's not really running.  Perhaps the machine has
54    # rebooted.  Wait for manual intervention before running again.
55    echo "Stale runfile."
56  else
57    echo "$runfile exists; not running."
58  fi
59  exit
60fi
61echo $$ > $runfile
62
63# Put here cleanup that should always happen
64clean_up () {
65    err=$?
66
67    set +e
68
69    touch "$suppress"
70    rm "$runfile"
71    /usr/sbin/sendmail -t <<EOF
72From: Autolivebuilder <$error_addr>
73To: Autolivebuilder <$error_addr>
74Subject: Autolivebuilder failure
75
76Autolivebuilder has experienced a failure.
77
78Please see $logfile on $(hostname) for more details.
79
80Autolivebuilder will stop running until $suppress is removed.
81EOF
82
83    if [ -n "$session" ]; then
84        schroot -ec "$session"
85        print "$session"
86    fi
87
88    exit $err
89}
90
91trap clean_up ERR
92set -e
93
94cd $HOME/live
95
96if ! [ -d debathena-live ]; then
97    echo "E: The Debathena Live CD builder is not checked out."
98    echo "E: Run 'git clone file:///mit/debathena/git/debathena-live.git' in"
99    echo "E: $HOME/live"
100    false
101fi
102pushd debathena-live
103  # This will break if we ever add an epoch. So don't do that.
104  version="$(dpkg-parsechangelog | sed -ne 's/^Version: //p')"
105  debuild -us -uc -b
106popd
107
108iso="ubuntu-${release_version}-desktop-${arch}.iso"
109wget -N "http://${mirror}/ubuntu-releases/${release_version}/$iso"
110
111wget -N "http://${mirror}/ubuntu-releases/${release_version}/SHA1SUMS"
112wget -N "http://${mirror}/ubuntu-releases/${release_version}/SHA1SUMS.gpg"
113
114gpg --verify SHA1SUMS.gpg SHA1SUMS
115grep "$iso" SHA1SUMS | sha1sum -c
116
117session="$(schroot -bc "${release}-${arch}-sbuild")"
118
119schroot -rc "$session" -u root -- dpkg -i "debathena-livecd-tools_${version}_all.deb" || :
120schroot -rc "$session" -u root -- apt-get install -y -f
121
122date="$(date "+%Y%m%d")"
123da_iso="ubuntu-${release_version}-debathena-${date}-${arch}.iso"
124da_dvd_iso="ubuntu-${release_version}-debathena-${date}-${arch}-dvd.iso"
125
126schroot -rc "$session" -u root -- debathena-livecd-convert "$iso" "$da_iso"
127schroot -rc "$session" -u root -- debathena-livecd-convert --dvd "$iso" "$da_dvd_iso"
128
129cp "$da_iso" "$da_dvd_iso" "${live_dir}"
130sha1sum "$da_iso" >"${live_dir}/${da_iso}.sha1sum"
131sha512sum "$da_iso" >"${live_dir}/${da_iso}.sha512sum"
132sha1sum "$da_dvd_iso" >"${live_dir}/${da_dvd_iso}.sha1sum"
133sha512sum "$da_dvd_iso" >"${live_dir}/${da_dvd_iso}.sha512sum"
134
135gpg --batch --yes "${gpg_opts[@]}" -a -b "${live_dir}/${da_iso}.sha1sum"
136gpg --batch --yes "${gpg_opts[@]}" -a -b "${live_dir}/${da_iso}.sha512sum"
137gpg --batch --yes "${gpg_opts[@]}" -a -b "${live_dir}/${da_dvd_iso}.sha1sum"
138gpg --batch --yes "${gpg_opts[@]}" -a -b "${live_dir}/${da_dvd_iso}.sha512sum"
139
140kdestroy
141rm -f "$runfile"
Note: See TracBrowser for help on using the repository browser.