iterate
[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 # $URL$
15 #
16
17 # Source PLC configuration
18 . /etc/planetlab/plc_config
19
20 # Do not tolerate errors
21 set -e
22
23 # this is set by plc.d/bootmanager
24 DEPLOYMENT=$1
25
26 BOOTSTRAPDIR="/boot"
27
28 # Change to our source directory
29 cd $(dirname $0)
30
31 # Translate configuration file
32 sed -i -e "s|SUPPORT_FILE_DIR=.*|SUPPORT_FILE_DIR=$BOOTSTRAPDIR|" source/configuration
33
34 # Source bootmanager configuration
35 . source/configuration
36
37 # Write boot script. nodeconfig/boot/index.php retrieves the contents of this script
38 # after checking the node id
39
40 BMDIR=/var/www/html/boot
41 mkdir -p $BMDIR
42
43 DEST_SCRIPT="$BMDIR/bootmanager_${DEPLOYMENT}.sh"
44 # Remove the old version or any sym links prior to re-writing
45 rm -f ${DEST_SCRIPT}
46 rm -f ${DEST_SCRIPT}.sgn
47
48
49 # hard code 443 here.
50 sed -i -e "s@^BOOT_API_SERVER.*@BOOT_API_SERVER=https://$PLC_API_HOST:443/$PLC_API_PATH/@" source/configuration
51
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
55 else
56     MONITOR_SERVER=$PLC_BOOT_HOST
57 fi
58 sed -i -e "s@^MONITOR_SERVER.*@MONITOR_SERVER=$MONITOR_SERVER@" source/configuration
59
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
63 fi
64
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
68 fi
69
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
76
77
78 ########## create the bootmanager script
79 cat <<EOF > $DEST_SCRIPT
80 #!/bin/bash
81 #
82 # PlanetLab Boot Manager $VERSION
83 #
84 # DO NOT EDIT. Generated by $USER@$HOSTNAME at
85 # $(date) 
86 #
87
88 # Do not tolerate errors
89 set -e
90
91 (/usr/bin/uudecode | /bin/tar -C /tmp -xj) << _EOF_
92 EOF
93
94
95 # Embed the uuencoded tarball in the script
96 tar -cj source/ -C $extra_libs source/ | uuencode -m - >> $DEST_SCRIPT
97
98 # wrap up the script
99 echo '_EOF_' >> $DEST_SCRIPT
100 echo 'cd /tmp/source' >> $DEST_SCRIPT
101 echo 'chmod +x BootManager.py && ./BootManager.py' >> $DEST_SCRIPT
102
103 # Remove temp directory
104 rm -fr $extra_libs
105
106 # Sign the whole script, if the keyring is on this machine.
107 if [ -f "$PLC_ROOT_GPG_KEY" -a -f "$PLC_ROOT_GPG_KEY_PUB" ] ; then
108     gpg --homedir=/root \
109         --no-default-keyring \
110         --keyring "$PLC_ROOT_GPG_KEY_PUB" \
111         --secret-keyring "$PLC_ROOT_GPG_KEY" \
112         --yes --sign --output $DEST_SCRIPT.sgn \
113         $DEST_SCRIPT
114 else
115     echo "Warning: Remember to sign $PWD/$DEST_SCRIPT!" >&2
116 fi
117