[24352] | 1 | #!/bin/bash |
---|
[23981] | 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 |
---|
[24020] | 18 | # - live_dir: The directory to put the live CDs into |
---|
[23981] | 19 | |
---|
| 20 | # Send all output to a logfile. |
---|
| 21 | mkdir -p "$HOME/autolivebuilder-logs" |
---|
| 22 | logfile=$HOME/autolivebuilder-logs/$(date '+%Y-%m-%d-%H').log |
---|
| 23 | exec </dev/null >>$logfile 2>&1 |
---|
| 24 | |
---|
| 25 | # Set default configuration values |
---|
| 26 | mirror='ubuntu.media.mit.edu' |
---|
| 27 | |
---|
| 28 | # Read configuration; if it's not complete, do nothing. |
---|
| 29 | config=$HOME/autolivebuilder.config |
---|
| 30 | . $config |
---|
| 31 | if (! [ -n "$error_addr" ]) || \ |
---|
| 32 | (! [ -n "release" ]) || \ |
---|
| 33 | (! [ -n "$release_version" ]) || \ |
---|
| 34 | (! [ -n "$arch" ]) || \ |
---|
[24020] | 35 | (! [ -n "${gpg_opts[*]}" ]) || \ |
---|
| 36 | (! [ -n "$live_dir" ]); then |
---|
[23981] | 37 | echo "Incomplete $config; doing nothing." |
---|
| 38 | exit |
---|
| 39 | fi |
---|
| 40 | |
---|
| 41 | suppress=$HOME/autolivebuilder.suppress |
---|
| 42 | if [ -e "$suppress" ]; then |
---|
| 43 | echo "$suppress exists; not running." |
---|
| 44 | exit |
---|
| 45 | fi |
---|
| 46 | |
---|
| 47 | # Make sure runs of this script do not overlap. |
---|
[23984] | 48 | runfile=$HOME/autolivebuilder.running |
---|
[23981] | 49 | if [ -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. |
---|
[23989] | 55 | echo "Stale runfile." |
---|
[23981] | 56 | else |
---|
| 57 | echo "$runfile exists; not running." |
---|
| 58 | fi |
---|
| 59 | exit |
---|
| 60 | fi |
---|
| 61 | echo $$ > $runfile |
---|
| 62 | |
---|
| 63 | # Put here cleanup that should always happen |
---|
| 64 | clean_up () { |
---|
| 65 | err=$? |
---|
| 66 | |
---|
| 67 | set +e |
---|
| 68 | |
---|
| 69 | touch "$suppress" |
---|
[24354] | 70 | rm "$runfile" |
---|
[23989] | 71 | /usr/sbin/sendmail -t <<EOF |
---|
[23981] | 72 | From: Autolivebuilder <$error_addr> |
---|
| 73 | To: Autolivebuilder <$error_addr> |
---|
| 74 | Subject: Autolivebuilder failure |
---|
| 75 | |
---|
| 76 | Autolivebuilder has experienced a failure. |
---|
| 77 | |
---|
| 78 | Please see $logfile on $(hostname) for more details. |
---|
| 79 | |
---|
| 80 | Autolivebuilder will stop running until $suppress is removed. |
---|
| 81 | EOF |
---|
| 82 | |
---|
| 83 | if [ -n "$session" ]; then |
---|
| 84 | schroot -ec "$session" |
---|
| 85 | fi |
---|
| 86 | |
---|
| 87 | exit $err |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | trap clean_up ERR |
---|
| 91 | set -e |
---|
| 92 | |
---|
[24353] | 93 | cd $HOME/live |
---|
[23981] | 94 | |
---|
[23986] | 95 | if ! [ -d debathena-live ]; then |
---|
| 96 | echo "E: The Debathena Live CD builder is not checked out." |
---|
| 97 | echo "E: Run 'git clone file:///mit/debathena/git/debathena-live.git' in" |
---|
[24353] | 98 | echo "E: $HOME/live" |
---|
[23986] | 99 | false |
---|
[23981] | 100 | fi |
---|
| 101 | pushd debathena-live |
---|
| 102 | # This will break if we ever add an epoch. So don't do that. |
---|
| 103 | version="$(dpkg-parsechangelog | sed -ne 's/^Version: //p')" |
---|
| 104 | debuild -us -uc -b |
---|
| 105 | popd |
---|
| 106 | |
---|
| 107 | iso="ubuntu-${release_version}-desktop-${arch}.iso" |
---|
| 108 | wget -N "http://${mirror}/ubuntu-releases/${release_version}/$iso" |
---|
| 109 | |
---|
| 110 | wget -N "http://${mirror}/ubuntu-releases/${release_version}/SHA1SUMS" |
---|
| 111 | wget -N "http://${mirror}/ubuntu-releases/${release_version}/SHA1SUMS.gpg" |
---|
| 112 | |
---|
| 113 | gpg --verify SHA1SUMS.gpg SHA1SUMS |
---|
| 114 | grep "$iso" SHA1SUMS | sha1sum -c |
---|
| 115 | |
---|
| 116 | session="$(schroot -bc "${release}-${arch}-sbuild")" |
---|
| 117 | |
---|
[24356] | 118 | schroot -rc "$session" -u root -- sh -c 'apt-get update && apt-get -y dist-upgrade && apt-get -y autoremove' |
---|
[23981] | 119 | schroot -rc "$session" -u root -- dpkg -i "debathena-livecd-tools_${version}_all.deb" || : |
---|
| 120 | schroot -rc "$session" -u root -- apt-get install -y -f |
---|
| 121 | |
---|
| 122 | date="$(date "+%Y%m%d")" |
---|
| 123 | da_iso="ubuntu-${release_version}-debathena-${date}-${arch}.iso" |
---|
[23991] | 124 | da_dvd_iso="ubuntu-${release_version}-debathena-${date}-${arch}-dvd.iso" |
---|
[23981] | 125 | |
---|
| 126 | schroot -rc "$session" -u root -- debathena-livecd-convert "$iso" "$da_iso" |
---|
| 127 | schroot -rc "$session" -u root -- debathena-livecd-convert --dvd "$iso" "$da_dvd_iso" |
---|
| 128 | |
---|
[24020] | 129 | cp "$da_iso" "$da_dvd_iso" "${live_dir}" |
---|
| 130 | sha1sum "$da_iso" >"${live_dir}/${da_iso}.sha1sum" |
---|
| 131 | sha512sum "$da_iso" >"${live_dir}/${da_iso}.sha512sum" |
---|
| 132 | sha1sum "$da_dvd_iso" >"${live_dir}/${da_dvd_iso}.sha1sum" |
---|
| 133 | sha512sum "$da_dvd_iso" >"${live_dir}/${da_dvd_iso}.sha512sum" |
---|
[23981] | 134 | |
---|
[24020] | 135 | gpg --batch --yes "${gpg_opts[@]}" -a -b "${live_dir}/${da_iso}.sha1sum" |
---|
| 136 | gpg --batch --yes "${gpg_opts[@]}" -a -b "${live_dir}/${da_iso}.sha512sum" |
---|
| 137 | gpg --batch --yes "${gpg_opts[@]}" -a -b "${live_dir}/${da_dvd_iso}.sha1sum" |
---|
| 138 | gpg --batch --yes "${gpg_opts[@]}" -a -b "${live_dir}/${da_dvd_iso}.sha512sum" |
---|
[23982] | 139 | |
---|
| 140 | kdestroy |
---|
| 141 | rm -f "$runfile" |
---|