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 $
17 # Source PLC configuration
18 . /etc/planetlab/plc_config
20 # Do not tolerate errors
23 # this is set by plc.d/bootmanager
28 # Change to our source directory
31 # Translate configuration file
32 sed -i -e "s|SUPPORT_FILE_DIR=.*|SUPPORT_FILE_DIR=$BOOTSTRAPDIR|" source/configuration
34 # Source bootmanager configuration
35 . $srcdir/source/configuration
37 # Write boot script. nodeconfig/boot/index.php retrieves the contents of this script
38 # after checking the node id
40 BMDIR=/var/www/html/bootmanager
43 DEST_SCRIPT="$BMDIR/${DEPLOYMENT}_bootmanager.sh"
44 # Remove the old version or any sym links prior to re-writing
46 rm -f ${DEST_SCRIPT}.sgn
50 sed -i -e "s@^BOOT_API_SERVER.*@BOOT_API_SERVER=https://$PLC_API_HOST:443/$PLC_API_PATH/@" source/configuration
52 sed -i -e "s@^BOOT_SERVER.*@BOOT_SERVER=$PLC_BOOT_HOST@" source/configuration
53 if [ "$PLC_MONITOR_ENABLED" = "1" ]; then
54 MONITOR_SERVER=$PLC_MONITOR_HOST
56 MONITOR_SERVER=$PLC_BOOT_HOST
58 sed -i -e "s@^MONITOR_SERVER.*@MONITOR_SERVER=$MONITOR_SERVER@" source/configuration
60 install -D -m 644 $PLC_BOOT_CA_SSL_CRT source/cacert/$PLC_BOOT_HOST/cacert.pem
61 if [ -f $PLC_MONITOR_CA_SSL_CRT ] ; then
62 install -D -m 644 $PLC_MONITOR_CA_SSL_CRT source/cacert/$PLC_MONITOR_HOST/cacert.pem
65 # Replace the default debug SSH key
66 if [ -f "$PLC_DEBUG_SSH_KEY_PUB" ] ; then
67 install -D -m 644 "$PLC_DEBUG_SSH_KEY_PUB" source/debug_files/debug_root_ssh_key
70 # Add python code from the following packages
71 # make sure they are in the 'Requires' header of the specfile
72 required_rpms="pypcilib pyplnet monitor-runlevelagent"
73 extra_libs=`mktemp -d "/tmp/.bootmanager.XXXXXX"`
74 mkdir $extra_libs/source
75 cp -p $(rpm -ql $required_rpms | grep -v '\.py[co]$') $extra_libs/source
78 ########## create the bootmanager script
79 cat <<EOF > $DEST_SCRIPT
82 # PlanetLab Boot Manager $VERSION
84 # DO NOT EDIT. Generated by $USER@$HOSTNAME at
88 # Do not tolerate errors
91 UUDECODE=/usr/bin/uudecode
93 # once we get the beta cds out of use, this can be removed
94 if [ ! -x \$UUDECODE ]; then
95 UUDECODE=/tmp/uudecode
96 curl -s http://$PLC_BOOT_HOST/boot/uudecode.gz | gzip -d -c > \$UUDECODE
100 ($UUDECODE | /bin/tar -C /tmp -xj) << _EOF_
104 # Embed the uuencoded tarball in the script
105 tar -cj -C $srcdir source/ -C $extra_libs source/ | uuencode -m - >> $DEST_SCRIPT
108 echo '_EOF_' >> $DEST_SCRIPT
109 echo 'cd /tmp/source' >> $DEST_SCRIPT
110 echo 'chmod +x BootManager.py && ./BootManager.py' >> $DEST_SCRIPT
112 # Remove temp directory
115 # Sign the whole script, if the keyring is on this machine.
116 if [ -f "$PLC_ROOT_GPG_KEY" -a -f "$PLC_ROOT_GPG_KEY_PUB" ] ; then
117 gpg --homedir=/root \
118 --no-default-keyring \
119 --keyring "$PLC_ROOT_GPG_KEY_PUB" \
120 --secret-keyring "$PLC_ROOT_GPG_KEY" \
121 --yes --sign --output $DEST_SCRIPT.sgn \
124 echo "Warning: Remember to sign $PWD/$DEST_SCRIPT!" >&2