* Removed building PlanetLab-Bootstrap.tar.bz2 from the package. It
[bootmanager.git] / build.sh
1 #!/bin/bash
2 #
3 # Builds bootmanager.sh[.sgn], which is the PlanetLab Boot Manager script.
4 #
5 # The bootmanager.sh script contains in it a uuencoded tarball of the
6 # Boot Manager, customized for this PLC installation.
7 #
8 # Aaron Klingaman <alk@absarokasoft.com>
9 # Mark Huang <mlhuang@cs.princeton.edu>
10 # Marc E. Fiuczynski <mef@cs.princeton.edu>
11 # Copyright (C) 2004-2007 The Trustees of Princeton University
12 #
13 # $Id: build.sh,v 1.5 2006/04/03 19:40:55 mlhuang Exp $
14 #
15
16 # Source PLC configuration
17 if [ -f /etc/planetlab/plc_config ] ; then
18     . /etc/planetlab/plc_config
19 else
20     PLC_BOOT_HOST=boot.planet-lab.org
21     PLC_API_HOST=www.planet-lab.org
22     PLC_API_PATH=PLCAPI
23 fi
24
25 # Do not tolerate errors
26 set -e
27
28 # Change to our source directory
29 srcdir=$(cd $(dirname $0) && pwd -P)
30
31 # Source bootmanager configuration
32 . $srcdir/source/configuration
33
34 # Write boot script. plc_www/boot/index.php writes this script out
35 # after a nonce check.
36
37 DEST_SCRIPT=bootmanager.sh
38
39 cat > $DEST_SCRIPT <<EOF
40 #!/bin/bash
41 #
42 # PlanetLab Boot Manager $VERSION
43 #
44 # DO NOT EDIT. Generated by $USER@$HOSTNAME at
45 # $(date) 
46 #
47
48 # Do not tolerate errors
49 set -e
50
51 UUDECODE=/usr/bin/uudecode
52
53 # once we get the beta cds out of use, this can be removed
54 if [ ! -x \$UUDECODE ]; then
55   UUDECODE=/tmp/uudecode
56   curl -s http://$PLC_BOOT_HOST/boot/uudecode.gz | gzip -d -c > \$UUDECODE
57   chmod +x \$UUDECODE
58 fi
59
60 EOF
61
62 echo '($UUDECODE | /bin/tar -C /tmp -xj) << _EOF_' >> $DEST_SCRIPT
63
64 # XXX Currently, the value of PLC_API_PORT is set to 80 by default, so
65 # that the portions of the web site that still use oldapi can continue
66 # to work. However, the Boot Manager supports HTTPS access, which we
67 # want to remain the default, so hard code 443 here.
68 sed -i -e "s@^BOOT_API_SERVER.*@BOOT_API_SERVER=https://$PLC_API_HOST:443/$PLC_API_PATH/@" \
69     $srcdir/source/configuration
70
71 # Replace the default debug SSH key
72 if [ -f "$PLC_DEBUG_SSH_KEY_PUB" ] ; then
73     install -D -m 644 "$PLC_DEBUG_SSH_KEY_PUB" $srcdir/source/debug_files/debug_root_ssh_key
74 fi
75
76 # Embed the uuencoded tarball in the script
77 tar -cj -C $srcdir source/ | uuencode -m - >> $DEST_SCRIPT
78
79 echo '_EOF_' >> $DEST_SCRIPT
80 echo 'cd /tmp/source' >> $DEST_SCRIPT
81 echo 'chmod +x BootManager.py && ./BootManager.py' >> $DEST_SCRIPT
82
83 # Sign the whole script, if the keyring is on this machine.
84 if [ -f "$PLC_ROOT_GPG_KEY" -a -f "$PLC_ROOT_GPG_KEY_PUB" ] ; then
85     gpg --homedir=/root \
86         --no-default-keyring \
87         --keyring "$PLC_ROOT_GPG_KEY_PUB" \
88         --secret-keyring "$PLC_ROOT_GPG_KEY" \
89         --yes --sign --output $DEST_SCRIPT.sgn \
90         $DEST_SCRIPT
91 else
92     echo "Warning: Remember to sign $PWD/$DEST_SCRIPT!" >&2
93 fi