3 # Run gpg once to create default options
6 /usr/bin/gpg --yes 2>/dev/null </dev/null
8 # if this file is present, cancel the boot (exit this script)
9 CANCEL_BOOT_FLAG=/tmp/CANCEL_BOOT
11 # how many times to fail in attempting to contact primary server
12 # before falling back to original. if the backup fails this many times
13 # too, then the process is repeated started with the primary server
14 ATTEMPTS_BEFORE_BACKUP=2
16 # where all the configuration files for contacting
17 # the boot server are stored
20 # get the server we are going to be contacting
21 BOOT_SERVER=`cat $BOOT_DIR/boot_server`
22 BOOT_SERVER_PORT=`cat $BOOT_DIR/boot_server_port`
24 # the file to request from the boot server
25 BOOT_SERVER_PATH=`cat $BOOT_DIR/boot_server_path`
27 # location of the cacert for this boot server
28 BOOT_SERVER_CACERT=$BOOT_DIR/cacert.pem
30 # location of the gpg key ring to verify scripts
31 BOOT_SERVER_GPG_KEYRING=$BOOT_DIR/pubring.gpg
33 # get the backup server we are going to be contacting
34 BACKUP_BOOT_SERVER=`cat $BOOT_DIR/backup/boot_server`
35 BACKUP_BOOT_SERVER_PORT=`cat $BOOT_DIR/backup/boot_server_port`
37 # the file to request from the backup boot server
38 BACKUP_BOOT_SERVER_PATH=`cat $BOOT_DIR/backup/boot_server_path`
40 # location of the cacert for the backup boot server
41 BACKUP_BOOT_SERVER_CACERT=$BOOT_DIR/backup/cacert.pem
43 # location of the gpg key ring for backup server to verify scripts
44 BACKUP_BOOT_SERVER_GPG_KEYRING=$BOOT_DIR/backup/pubring.gpg
46 # location of a file containing this boot cd version
47 BOOT_VERSION_FILE=/pl_version
49 # the locations of the downloaded scripts
50 UNVERIFIED_SCRIPT=/tmp/bootscript.gpg
51 VERIFIED_SCRIPT=/tmp/bootscript
54 # --------------------------
57 # now, contact the boot server, run the script, and do it over again.
60 # set to one when we are trying to contact backup server
63 # start out contacting the primary servers
64 CONNECT_BOOT_SERVER=$BOOT_SERVER
65 CONNECT_BOOT_SERVER_PORT=$BOOT_SERVER_PORT
66 CONNECT_BOOT_SERVER_PATH=$BOOT_SERVER_PATH
67 CONNECT_BOOT_SERVER_GPG_KEYRING=$BOOT_SERVER_GPG_KEYRING
68 CONNECT_BOOT_SERVER_CACERT=$BOOT_SERVER_CACERT
72 if [[ -f $CANCEL_BOOT_FLAG ]]; then
73 echo "pl_boot: got request to cancel boot, exiting"
77 if [[ $contact_count -ne 0 ]]; then
78 echo "pl_boot: fetching new script in 30 seconds"
83 if [[ $contact_count > $ATTEMPTS_BEFORE_BACKUP ]]; then
87 if [[ $on_backup_server == 1 ]]; then
88 echo "pl_boot: failed to contact backup server, trying primary."
92 CONNECT_BOOT_SERVER=$BOOT_SERVER
93 CONNECT_BOOT_SERVER_PORT=$BOOT_SERVER_PORT
94 CONNECT_BOOT_SERVER_PATH=$BOOT_SERVER_PATH
95 CONNECT_BOOT_SERVER_GPG_KEYRING=$BOOT_SERVER_GPG_KEYRING
96 CONNECT_BOOT_SERVER_CACERT=$BOOT_SERVER_CACERT
98 echo "pl_boot: failed to contact primary server, trying backup."
102 CONNECT_BOOT_SERVER=$BACKUP_BOOT_SERVER
103 CONNECT_BOOT_SERVER_PORT=$BACKUP_BOOT_SERVER_PORT
104 CONNECT_BOOT_SERVER_PATH=$BACKUP_BOOT_SERVER_PATH
105 CONNECT_BOOT_SERVER_GPG_KEYRING=$BACKUP_BOOT_SERVER_GPG_KEYRING
106 CONNECT_BOOT_SERVER_CACERT=$BACKUP_BOOT_SERVER_CACERT
110 # assemble the curl transaction
111 CURL_CMD="/usr/bin/curl \
112 --connect-timeout 60 \
114 --form version=<$BOOT_VERSION_FILE \
115 --form cmdline=</proc/cmdline \
116 --form uptime=</proc/uptime \
117 --form ifconfig=</tmp/ifconfig \
118 --form nonce=</tmp/nonce \
120 --output $UNVERIFIED_SCRIPT \
125 --stderr /tmp/curl_errors \
126 --cacert $CONNECT_BOOT_SERVER_CACERT \
127 https://$CONNECT_BOOT_SERVER:$CONNECT_BOOT_SERVER_PORT/$CONNECT_BOOT_SERVER_PATH"
129 # assemble the gpg command line
130 GPG_CMD="/usr/bin/gpg \
131 --no-default-keyring \
132 --keyring $CONNECT_BOOT_SERVER_GPG_KEYRING \
133 --output $VERIFIED_SCRIPT \
135 --decrypt $UNVERIFIED_SCRIPT"
137 echo "pl_boot: generating new nonce"
138 /usr/bin/head --bytes=32 /dev/urandom | \
139 /usr/bin/od -tx1 -An --width=32 | \
140 /bin/sed 's/ //g' > /tmp/nonce
142 echo "pl_boot: fetching script from boot server $CONNECT_BOOT_SERVER"
143 rm -f $UNVERIFIED_SCRIPT
146 if [ $curl_err -ne 0 ]; then
147 echo "pl_boot: curl request failed with error $curl_err:"
153 echo "pl_boot: verifying downloaded script"
154 rm -f $VERIFIED_SCRIPT
155 $GPG_CMD 2> /tmp/gpg_errors
156 if [ $? -ne 0 ]; then
157 echo "pl_boot: failed to verify file:"
162 echo "pl_boot: decrypted and verified script succesfully"
164 echo "pl_boot: handing control to download script"
165 rm -f $UNVERIFIED_SCRIPT
166 chmod +x $VERIFIED_SCRIPT
169 echo "pl_boot: downloaded script has returned"
172 echo "pl_boot: automatic boot process canceled by user"