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