3 ### make sure this output shows up in the console
9 . /etc/init.d/pl_functions
13 # Run gpg once to create default options
16 /usr/bin/gpg --yes 2>/dev/null </dev/null
18 # if this file is present, cancel the boot (exit this script)
19 CANCEL_BOOT_FLAG=/tmp/CANCEL_BOOT
21 # how many times to fail in attempting to contact primary server
22 # before falling back to original. if the backup fails this many times
23 # too, then the process is repeated started with the primary server
24 ATTEMPTS_BEFORE_BACKUP=3
26 # where all the configuration files for contacting
27 # the boot server are stored
30 # get the server we are going to be contacting
31 BOOT_SERVER=$(cat $BOOT_DIR/boot_server)
32 BOOT_SERVER_PORT=$(cat $BOOT_DIR/boot_server_port)
34 # the file to request from the boot server
35 BOOT_SERVER_PATH=$(cat $BOOT_DIR/boot_server_path)
37 # location of the cacert for this boot server
38 BOOT_SERVER_CACERT=$BOOT_DIR/cacert.pem
40 # location of the gpg key ring to verify scripts
41 BOOT_SERVER_GPG_KEYRING=$BOOT_DIR/pubring.gpg
43 # get the backup server we are going to be contacting
44 BACKUP_BOOT_SERVER=$(cat $BOOT_DIR/backup/boot_server)
45 BACKUP_BOOT_SERVER_PORT=$(cat $BOOT_DIR/backup/boot_server_port)
47 # the file to request from the backup boot server
48 BACKUP_BOOT_SERVER_PATH=$(cat $BOOT_DIR/backup/boot_server_path)
50 # location of the cacert for the backup boot server
51 BACKUP_BOOT_SERVER_CACERT=$BOOT_DIR/backup/cacert.pem
53 # location of the gpg key ring for backup server to verify scripts
54 BACKUP_BOOT_SERVER_GPG_KEYRING=$BOOT_DIR/backup/pubring.gpg
56 # location of a file containing this boot cd version
57 BOOT_VERSION_FILE=/pl_version
59 # the locations of the downloaded scripts
60 UNVERIFIED_SCRIPT=/tmp/bootscript.gpg
61 VERIFIED_SCRIPT=/tmp/bootscript
64 # --------------------------
67 # now, contact the boot server, run the script, and do it over again.
70 # set to one when we are trying to contact backup server
73 # start out contacting the primary servers
74 CONNECT_BOOT_SERVER=$BOOT_SERVER
75 CONNECT_BOOT_SERVER_PORT=$BOOT_SERVER_PORT
76 CONNECT_BOOT_SERVER_PATH=$BOOT_SERVER_PATH
77 CONNECT_BOOT_SERVER_GPG_KEYRING=$BOOT_SERVER_GPG_KEYRING
78 CONNECT_BOOT_SERVER_CACERT=$BOOT_SERVER_CACERT
82 if [[ -f $CANCEL_BOOT_FLAG ]]; then
83 verbose-message "pl_boot: got request to cancel boot, exiting"
87 if [[ $contact_count -ge $ATTEMPTS_BEFORE_BACKUP ]]; then
91 if [[ $on_backup_server == 1 ]]; then
92 verbose-message "pl_boot: failed to contact backup server, trying primary $BOOT_SERVER"
96 CONNECT_BOOT_SERVER=$BOOT_SERVER
97 CONNECT_BOOT_SERVER_PORT=$BOOT_SERVER_PORT
98 CONNECT_BOOT_SERVER_PATH=$BOOT_SERVER_PATH
99 CONNECT_BOOT_SERVER_GPG_KEYRING=$BOOT_SERVER_GPG_KEYRING
100 CONNECT_BOOT_SERVER_CACERT=$BOOT_SERVER_CACERT
102 verbose-message "pl_boot: failed to contact primary server, trying backup $BACKUP_BOOT_SERVER"
106 CONNECT_BOOT_SERVER=$BACKUP_BOOT_SERVER
107 CONNECT_BOOT_SERVER_PORT=$BACKUP_BOOT_SERVER_PORT
108 CONNECT_BOOT_SERVER_PATH=$BACKUP_BOOT_SERVER_PATH
109 CONNECT_BOOT_SERVER_GPG_KEYRING=$BACKUP_BOOT_SERVER_GPG_KEYRING
110 CONNECT_BOOT_SERVER_CACERT=$BACKUP_BOOT_SERVER_CACERT
114 if [[ $contact_count != 0 ]]; then
116 verbose-message "pl_boot: next attempt in 30s, to fetch script from server at $CONNECT_BOOT_SERVER"
120 # June 2015 : using --tlsv1 instead of sslv3 that should be available
121 # on all myplc from f14 inclusive
122 # assemble the curl transaction
123 CURL_CMD="/usr/bin/curl \
124 --connect-timeout 60 \
126 --form version=<$BOOT_VERSION_FILE \
127 --form cmdline=</proc/cmdline \
128 --form uptime=</proc/uptime \
129 --form ifconfig=</tmp/ifconfig \
130 --form nonce=</tmp/nonce \
132 --output $UNVERIFIED_SCRIPT \
137 --stderr /tmp/curl_errors \
138 --cacert $CONNECT_BOOT_SERVER_CACERT \
139 https://$CONNECT_BOOT_SERVER:$CONNECT_BOOT_SERVER_PORT/$CONNECT_BOOT_SERVER_PATH"
141 # assemble the gpg command line
142 GPG_CMD="/usr/bin/gpg \
143 --no-default-keyring \
144 --keyring $CONNECT_BOOT_SERVER_GPG_KEYRING \
145 --output $VERIFIED_SCRIPT \
147 --decrypt $UNVERIFIED_SCRIPT"
149 verbose-message "pl_boot: generating new nonce"
150 /usr/bin/head --bytes=32 /dev/urandom | \
151 /usr/bin/od -tx1 -An --width=32 | \
152 /bin/sed 's/ //g' > /tmp/nonce
154 verbose-message "pl_boot: fetching script from boot server $CONNECT_BOOT_SERVER"
156 rm -f $UNVERIFIED_SCRIPT
159 if [ $curl_err -ne 0 ]; then
160 verbose-message "pl_boot: curl request failed with error $curl_err:"
163 if [ -n "$DISCONNECTED_OPERATION" ]; then
164 mkdir /tmp/boot-media
165 mount -U "$DISCONNECTED_OPERATION" /tmp/boot-media
166 cp /tmp/boot-media/bootscript.gpg $UNVERIFIED_SCRIPT
167 umount /tmp/boot-media
168 rmdir /tmp/boot-media
172 verbose-message "This error likely indicates a networking configuration error. "
173 verbose-message "Please, check whether you can ping this machine. If you can, "
174 verbose-message "we recommend checking your DNS settings. If you cannot, then "
175 verbose-message "please double check your network settings registered at PLC and "
176 verbose-message "stored on this Boot Image."
179 verbose-message "This error likely indicates that the hardware clock is likely not set "
180 verbose-message "to GMT. The result is that authentication between the local and "
181 verbose-message "remote site fails. Please double check this machine's system "
182 verbose-message "clock, and set it to GMT in the BIOS. If after rebooting the same "
183 verbose-message "error occurs, please report the situation to support@planet-lab.org "
184 verbose-message "with as much detail as possible."
187 verbose-message "The best-practice approach for handling this error is not yet "
188 verbose-message "documented. Please report this error to support@planet-lab.org "
189 verbose-message "with as much detail as possible."
192 # in any case display as much info as we can (see pl_functions)
193 verbose-forensics "after curl"
197 elif [ -n "$DISCONNECTED_OPERATION" ]; then
198 mkdir /tmp/boot-media
199 mount -U "$DISCONNECTED_OPERATION" /tmp/boot-media
200 cp $UNVERIFIED_SCRIPT /tmp/boot-media
201 umount /tmp/boot-media
202 rmdir /tmp/boot-media
205 verbose-message "pl_boot: verifying downloaded script"
206 rm -f $VERIFIED_SCRIPT
207 $GPG_CMD 2> /tmp/gpg_errors
208 if [ $? -ne 0 ]; then
209 verbose-message "pl_boot: failed to verify file:"
214 verbose-message "pl_boot: decrypted and verified script succesfully"
216 verbose-message "pl_boot: handing control to download script"
217 rm -f $UNVERIFIED_SCRIPT
218 chmod +x $VERIFIED_SCRIPT
221 verbose-message "pl_boot: downloaded script has returned"
224 verbose-message "pl_boot: automatic boot process canceled by user"