get rid of the old dirty trick that allowed to spot the right bootstrapfs for alpha...
[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 # Source bootmanager configuration
32 . source/configuration
33
34 # Write boot script. nodeconfig/boot/index.php retrieves the contents of this script
35 # after checking the node id
36
37 BMDIR=/var/www/html/boot
38 mkdir -p $BMDIR
39
40 DEST_SCRIPT="$BMDIR/bootmanager_${DEPLOYMENT}.sh"
41 # Remove the old version or any sym links prior to re-writing
42 rm -f ${DEST_SCRIPT}
43 rm -f ${DEST_SCRIPT}.sgn
44
45
46 # hard code 443 here.
47 sed -i -e "s@^BOOT_API_SERVER.*@BOOT_API_SERVER=https://$PLC_API_HOST:443/$PLC_API_PATH/@" source/configuration
48
49 sed -i -e "s@^BOOT_SERVER.*@BOOT_SERVER=$PLC_BOOT_HOST@" source/configuration
50 if [ "$PLC_MONITOR_ENABLED" = "1" ]; then
51     MONITOR_SERVER=$PLC_MONITOR_HOST
52 else
53     MONITOR_SERVER=$PLC_BOOT_HOST
54 fi
55 sed -i -e "s@^MONITOR_SERVER.*@MONITOR_SERVER=$MONITOR_SERVER@" source/configuration
56
57 install -D -m 644 $PLC_BOOT_CA_SSL_CRT source/cacert/$PLC_BOOT_HOST/cacert.pem
58 if [ -f $PLC_MONITOR_CA_SSL_CRT ] ; then 
59         install -D -m 644 $PLC_MONITOR_CA_SSL_CRT source/cacert/$PLC_MONITOR_HOST/cacert.pem
60 fi
61
62 # Replace the default debug SSH key
63 if [ -f "$PLC_DEBUG_SSH_KEY_PUB" ] ; then
64     install -D -m 644 "$PLC_DEBUG_SSH_KEY_PUB" source/debug_files/debug_root_ssh_key
65 fi
66
67 # Add python code from the following packages
68 # make sure they are in the 'Requires' header of the specfile
69 required_rpms="pypcilib pyplnet monitor-runlevelagent"
70 extra_libs=`mktemp -d "/tmp/.bootmanager.XXXXXX"`
71 mkdir $extra_libs/source
72 cp -p $(rpm -ql $required_rpms | grep -v '\.py[co]$') $extra_libs/source
73
74
75 ########## create the bootmanager script
76 cat <<EOF > $DEST_SCRIPT
77 #!/bin/bash
78 #
79 # PlanetLab Boot Manager $VERSION
80 #
81 # DO NOT EDIT. Generated by $USER@$HOSTNAME at
82 # $(date) 
83 #
84
85 # Do not tolerate errors
86 set -e
87
88 (/usr/bin/uudecode | /bin/tar -C /tmp -xj) << _EOF_
89 EOF
90
91
92 # Embed the uuencoded tarball in the script
93 tar -cj source/ -C $extra_libs source/ | uuencode -m - >> $DEST_SCRIPT
94
95 # wrap up the script
96 echo '_EOF_' >> $DEST_SCRIPT
97 echo 'cd /tmp/source' >> $DEST_SCRIPT
98 echo 'chmod +x BootManager.py && ./BootManager.py' >> $DEST_SCRIPT
99
100 # Remove temp directory
101 rm -fr $extra_libs
102
103 # Sign the whole script, if the keyring is on this machine.
104 if [ -f "$PLC_ROOT_GPG_KEY" -a -f "$PLC_ROOT_GPG_KEY_PUB" ] ; then
105     gpg --homedir=/root \
106         --no-default-keyring \
107         --keyring "$PLC_ROOT_GPG_KEY_PUB" \
108         --secret-keyring "$PLC_ROOT_GPG_KEY" \
109         --yes --sign --output $DEST_SCRIPT.sgn \
110         $DEST_SCRIPT
111 else
112     echo "Warning: Remember to sign $PWD/$DEST_SCRIPT!" >&2
113 fi
114