X-Git-Url: http://git.onelab.eu/?p=bootmanager.git;a=blobdiff_plain;f=build.sh;h=2e8c4400a1080322ea527f8c54ac8ec5c299ea0c;hp=36e8ee73ec2633e6b81caee1fed154d33d9d2631;hb=HEAD;hpb=b348c942f4b74f5a1c82dda9de9e9140c7a0fea9 diff --git a/build.sh b/build.sh index 36e8ee7..2e8c440 100755 --- a/build.sh +++ b/build.sh @@ -1,26 +1,115 @@ #!/bin/bash +# +# Builds bootmanager.sh[.sgn], which is the PlanetLab Boot Manager script. +# +# The bootmanager.sh script contains in it a uuencoded tarball of the +# Boot Manager, customized for this PLC installation. +# +# Aaron Klingaman +# Mark Huang +# Marc E. Fiuczynski +# Copyright (C) 2004-2007 The Trustees of Princeton University +# -# build a bash script that can be executed by the boot cd, -# and contains embedded in it the boot manager. +# Source PLC configuration +source /etc/planetlab/plc_config -DEST_SCRIPT=bootmanager.sh +# Do not tolerate errors +set -e + +# this is set by plc.d/bootmanager +DEPLOYMENT=$1 + +BOOTSTRAPDIR="/boot" + +# Change to our source directory +cd $(dirname $0) + +# Source bootmanager configuration +source source/configuration + +# Write boot script. nodeconfig/boot/index.php retrieves the contents of this script +# after checking the node id + +BMDIR=/var/www/html/boot +mkdir -p $BMDIR + +DEST_SCRIPT="$BMDIR/bootmanager_${DEPLOYMENT}.sh" +# Remove the old version or any sym links prior to re-writing +rm -f ${DEST_SCRIPT} +rm -f ${DEST_SCRIPT}.sgn + + +# hard code 443 here. +sed -i -e "s@^BOOT_API_SERVER.*@BOOT_API_SERVER=https://$PLC_API_HOST:443/$PLC_API_PATH/@" source/configuration + +sed -i -e "s@^BOOT_SERVER.*@BOOT_SERVER=$PLC_BOOT_HOST@" source/configuration +if [ "$PLC_MONITOR_ENABLED" = "1" ]; then + MONITOR_SERVER=$PLC_MONITOR_HOST +else + MONITOR_SERVER=$PLC_BOOT_HOST +fi +sed -i -e "s@^MONITOR_SERVER.*@MONITOR_SERVER=$MONITOR_SERVER@" source/configuration -cat > $DEST_SCRIPT << '_EOF_' +install -D -m 644 $PLC_BOOT_CA_SSL_CRT source/cacert/$PLC_BOOT_HOST/cacert.pem +if [ -f "$PLC_MONITOR_CA_SSL_CRT" ] ; then + install -D -m 644 "$PLC_MONITOR_CA_SSL_CRT" source/cacert/$PLC_MONITOR_HOST/cacert.pem +fi + +# Replace the default debug SSH key +if [ -f "$PLC_DEBUG_SSH_KEY_PUB" ] ; then + install -D -m 644 "$PLC_DEBUG_SSH_KEY_PUB" source/debug_files/debug_root_ssh_key +fi + +# Add python code from the following packages +# make sure they are in the 'Requires' header of the specfile +required_rpms="pypcilib pyplnet" +extra_libs=$(mktemp -d "/tmp/.bootmanager.XXXXXX") +mkdir $extra_libs/source +for entry in $(rpm -ql $required_rpms | grep -v '\.py[co]$'); do + if [ -d $entry ]; then + continue + fi + cp -p $entry $extra_libs/source +done + + +########## create the bootmanager script +cat < $DEST_SCRIPT #!/bin/bash +# +# PlanetLab Boot Manager $VERSION +# +# DO NOT EDIT. Generated by $USER@$HOSTNAME at +# $(date) +# + +# Do not tolerate errors set -e -UUDECODE=/usr/bin/uudecode +(/usr/bin/uudecode | /bin/tar -C /tmp -xj) << _EOF_ +EOF -# once we get the beta cds out of use, this can be removed -if [ ! -x $UUDECODE ]; then - UUDECODE=/tmp/uudecode - curl -s http://boot.planet-lab.org/boot/uudecode.gz | gzip -d -c > $UUDECODE - chmod +x $UUDECODE -fi -_EOF_ -echo '($UUDECODE | /bin/tar -C /tmp -xj) << _EOF_' >> $DEST_SCRIPT -tar -cj source/ | uuencode -m - >> $DEST_SCRIPT +# Embed the uuencoded tarball in the script +tar -cj source/ -C $extra_libs source/ | uuencode -m - >> $DEST_SCRIPT + +# wrap up the script echo '_EOF_' >> $DEST_SCRIPT echo 'cd /tmp/source' >> $DEST_SCRIPT echo 'chmod +x BootManager.py && ./BootManager.py' >> $DEST_SCRIPT + +# Remove temp directory +rm -fr $extra_libs + +# Sign the whole script, if the keyring is on this machine. +if [ -f "$PLC_ROOT_GPG_KEY" -a -f "$PLC_ROOT_GPG_KEY_PUB" ] ; then + gpg --homedir=/root \ + --no-default-keyring \ + --keyring "$PLC_ROOT_GPG_KEY_PUB" \ + --secret-keyring "$PLC_ROOT_GPG_KEY" \ + --yes --sign --output $DEST_SCRIPT.sgn \ + $DEST_SCRIPT +else + echo "Warning: Remember to sign $PWD/$DEST_SCRIPT!" >&2 +fi