3 # Builds bootmanager.sh[.sgn], which is the PlanetLab Boot Manager script.
5 # The bootmanager.sh script contains in it a uuencoded tarball of the
6 # Boot Manager, customized for this PLC installation.
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
13 # $Id: build.sh,v 1.5 2006/04/03 19:40:55 mlhuang Exp $
16 # Source PLC configuration
17 if [ -f /etc/planetlab/plc_config ] ; then
18 . /etc/planetlab/plc_config
20 PLC_BOOT_HOST=boot.planet-lab.org
21 PLC_API_HOST=www.planet-lab.org
25 # Do not tolerate errors
31 if [ -n "$NODEGROUP" ] ; then
32 BOOTSTRAPDIR="/boot/$NODEGROUP"
36 # Change to our source directory
37 srcdir=$(cd $(dirname $0) && pwd -P)
39 # Translate configuration file
40 sed -i -e "s|SUPPORT_FILE_DIR=.*|SUPPORT_FILE_DIR=$BOOTSTRAPDIR|" $srcdir/source/configuration
42 # Source bootmanager configuration
43 . $srcdir/source/configuration
45 # Write boot script. plc_www/boot/index.php writes this script out
46 # after a nonce check.
48 DEST_SCRIPT=bootmanager.sh
49 if [ -n "$NODEGROUP" ] ; then
50 DEST_SCRIPT="${NODEGROUP}_bootmanager.sh"
51 # Remove the old version or any sym links prior to re-writing
53 rm -f ${DEST_SCRIPT}.sgn
56 cat > $DEST_SCRIPT <<EOF
59 # PlanetLab Boot Manager $VERSION
61 # DO NOT EDIT. Generated by $USER@$HOSTNAME at
65 # Do not tolerate errors
68 UUDECODE=/usr/bin/uudecode
70 # once we get the beta cds out of use, this can be removed
71 if [ ! -x \$UUDECODE ]; then
72 UUDECODE=/tmp/uudecode
73 curl -s http://$PLC_BOOT_HOST/boot/uudecode.gz | gzip -d -c > \$UUDECODE
79 echo '($UUDECODE | /bin/tar -C /tmp -xj) << _EOF_' >> $DEST_SCRIPT
81 # XXX Currently, the value of PLC_API_PORT is set to 80 by default, so
82 # that the portions of the web site that still use oldapi can continue
83 # to work. However, the Boot Manager supports HTTPS access, which we
84 # want to remain the default, so hard code 443 here.
85 sed -i -e "s@^BOOT_API_SERVER.*@BOOT_API_SERVER=https://$PLC_API_HOST:443/$PLC_API_PATH/@" \
86 $srcdir/source/configuration
88 sed -i -e "s@^BOOT_SERVER.*@BOOT_SERVER=$PLC_BOOT_HOST@" $srcdir/source/configuration
89 if [ "$PLC_MONITOR_ENABLED" = "1" ]; then
90 MONITOR_SERVER=$PLC_MONITOR_HOST
92 MONITOR_SERVER=$PLC_BOOT_HOST
94 sed -i -e "s@^MONITOR_SERVER.*@MONITOR_SERVER=$MONITOR_SERVER@" $srcdir/source/configuration
96 install -D -m 644 $PLC_BOOT_CA_SSL_CRT $srcdir/source/cacert/$PLC_BOOT_HOST/cacert.pem
97 if [ -f $PLC_MONITOR_CA_SSL_CRT ] ; then
98 install -D -m 644 $PLC_MONITOR_CA_SSL_CRT $srcdir/source/cacert/$PLC_MONITOR_HOST/cacert.pem
101 # Replace the default debug SSH key
102 if [ -f "$PLC_DEBUG_SSH_KEY_PUB" ] ; then
103 install -D -m 644 "$PLC_DEBUG_SSH_KEY_PUB" $srcdir/source/debug_files/debug_root_ssh_key
106 # Add python code from the following packages
107 # make sure they are in the 'Requires' header of the specfile
108 required_rpms="pypcilib pyplnet monitor-runlevelagent"
109 extra_libs=`mktemp -d "/tmp/.bootmanager.XXXXXX"`
110 mkdir $extra_libs/source
111 cp -p $(rpm -ql $required_rpms | grep -v '\.py[co]$') $extra_libs/source
113 # Embed the uuencoded tarball in the script
114 tar -cj -C $srcdir source/ -C $extra_libs source/ | uuencode -m - >> $DEST_SCRIPT
116 # Remove temp directory
119 echo '_EOF_' >> $DEST_SCRIPT
120 echo 'cd /tmp/source' >> $DEST_SCRIPT
121 echo 'chmod +x BootManager.py && ./BootManager.py' >> $DEST_SCRIPT
123 # Sign the whole script, if the keyring is on this machine.
124 if [ -f "$PLC_ROOT_GPG_KEY" -a -f "$PLC_ROOT_GPG_KEY_PUB" ] ; then
125 gpg --homedir=/root \
126 --no-default-keyring \
127 --keyring "$PLC_ROOT_GPG_KEY_PUB" \
128 --secret-keyring "$PLC_ROOT_GPG_KEY" \
129 --yes --sign --output $DEST_SCRIPT.sgn \
132 echo "Warning: Remember to sign $PWD/$DEST_SCRIPT!" >&2