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