3 . /etc/init.d/pl_functions
7 # Run gpg once to create default options
10 /usr/bin/gpg --yes 2>/dev/null </dev/null
12 # if this file is present, cancel the boot (exit this script)
13 CANCEL_BOOT_FLAG=/tmp/CANCEL_BOOT
15 # how many times to fail in attempting to contact primary server
16 # before falling back to original. if the backup fails this many times
17 # too, then the process is repeated started with the primary server
18 ATTEMPTS_BEFORE_BACKUP=3
20 # where all the configuration files for contacting
21 # the boot server are stored
24 # get the server we are going to be contacting
25 BOOT_SERVER=$(cat $BOOT_DIR/boot_server)
26 BOOT_SERVER_PORT=$(cat $BOOT_DIR/boot_server_port)
28 # the file to request from the boot server
29 BOOT_SERVER_PATH=$(cat $BOOT_DIR/boot_server_path)
31 # location of the cacert for this boot server
32 BOOT_SERVER_CACERT=$BOOT_DIR/cacert.pem
34 # location of the gpg key ring to verify scripts
35 BOOT_SERVER_GPG_KEYRING=$BOOT_DIR/pubring.gpg
37 # get the backup server we are going to be contacting
38 BACKUP_BOOT_SERVER=$(cat $BOOT_DIR/backup/boot_server)
39 BACKUP_BOOT_SERVER_PORT=$(cat $BOOT_DIR/backup/boot_server_port)
41 # the file to request from the backup boot server
42 BACKUP_BOOT_SERVER_PATH=$(cat $BOOT_DIR/backup/boot_server_path)
44 # location of the cacert for the backup boot server
45 BACKUP_BOOT_SERVER_CACERT=$BOOT_DIR/backup/cacert.pem
47 # location of the gpg key ring for backup server to verify scripts
48 BACKUP_BOOT_SERVER_GPG_KEYRING=$BOOT_DIR/backup/pubring.gpg
50 # location of a file containing this boot cd version
51 BOOT_VERSION_FILE=/pl_version
53 # the locations of the downloaded scripts
54 UNVERIFIED_SCRIPT=/tmp/bootscript.gpg
55 VERIFIED_SCRIPT=/tmp/bootscript
58 # --------------------------
61 # now, contact the boot server, run the script, and do it over again.
64 # set to one when we are trying to contact backup server
67 # start out contacting the primary servers
68 CONNECT_BOOT_SERVER=$BOOT_SERVER
69 CONNECT_BOOT_SERVER_PORT=$BOOT_SERVER_PORT
70 CONNECT_BOOT_SERVER_PATH=$BOOT_SERVER_PATH
71 CONNECT_BOOT_SERVER_GPG_KEYRING=$BOOT_SERVER_GPG_KEYRING
72 CONNECT_BOOT_SERVER_CACERT=$BOOT_SERVER_CACERT
76 if [[ -f $CANCEL_BOOT_FLAG ]]; then
77 echo $(date "+%H:%M:%S") " pl_boot: got request to cancel boot, exiting"
81 if [[ $contact_count -ge $ATTEMPTS_BEFORE_BACKUP ]]; then
85 if [[ $on_backup_server == 1 ]]; then
86 echo $(date "+%H:%M:%S") " pl_boot: failed to contact backup server, trying primary $BOOT_SERVER"
90 CONNECT_BOOT_SERVER=$BOOT_SERVER
91 CONNECT_BOOT_SERVER_PORT=$BOOT_SERVER_PORT
92 CONNECT_BOOT_SERVER_PATH=$BOOT_SERVER_PATH
93 CONNECT_BOOT_SERVER_GPG_KEYRING=$BOOT_SERVER_GPG_KEYRING
94 CONNECT_BOOT_SERVER_CACERT=$BOOT_SERVER_CACERT
96 echo $(date "+%H:%M:%S") " pl_boot: failed to contact primary server, trying backup $BACKUP_BOOT_SERVER"
100 CONNECT_BOOT_SERVER=$BACKUP_BOOT_SERVER
101 CONNECT_BOOT_SERVER_PORT=$BACKUP_BOOT_SERVER_PORT
102 CONNECT_BOOT_SERVER_PATH=$BACKUP_BOOT_SERVER_PATH
103 CONNECT_BOOT_SERVER_GPG_KEYRING=$BACKUP_BOOT_SERVER_GPG_KEYRING
104 CONNECT_BOOT_SERVER_CACERT=$BACKUP_BOOT_SERVER_CACERT
108 if [[ $contact_count != 0 ]]; then
110 echo $(date "+%H:%M:%S") " pl_boot: next attempt in 30s, to fetch script from server at $CONNECT_BOOT_SERVER"
114 # assemble the curl transaction
115 CURL_CMD="/usr/bin/curl \
116 --connect-timeout 60 \
118 --form version=<$BOOT_VERSION_FILE \
119 --form cmdline=</proc/cmdline \
120 --form uptime=</proc/uptime \
121 --form ifconfig=</tmp/ifconfig \
122 --form nonce=</tmp/nonce \
124 --output $UNVERIFIED_SCRIPT \
129 --stderr /tmp/curl_errors \
130 --cacert $CONNECT_BOOT_SERVER_CACERT \
131 https://$CONNECT_BOOT_SERVER:$CONNECT_BOOT_SERVER_PORT/$CONNECT_BOOT_SERVER_PATH"
133 # assemble the gpg command line
134 GPG_CMD="/usr/bin/gpg \
135 --no-default-keyring \
136 --keyring $CONNECT_BOOT_SERVER_GPG_KEYRING \
137 --output $VERIFIED_SCRIPT \
139 --decrypt $UNVERIFIED_SCRIPT"
141 echo $(date "+%H:%M:%S") " pl_boot: generating new nonce"
142 /usr/bin/head --bytes=32 /dev/urandom | \
143 /usr/bin/od -tx1 -An --width=32 | \
144 /bin/sed 's/ //g' > /tmp/nonce
146 echo $(date "+%H:%M:%S") " pl_boot: fetching script from boot server $CONNECT_BOOT_SERVER"
148 rm -f $UNVERIFIED_SCRIPT
151 if [ $curl_err -ne 0 ]; then
152 echo $(date "+%H:%M:%S") " pl_boot: curl request failed with error $curl_err:"
155 if [ -n "$DISCONNECTED_OPERATION" ]; then
156 mkdir /tmp/boot-media
157 mount -U "$DISCONNECTED_OPERATION" /tmp/boot-media
158 cp /tmp/boot-media/bootscript.gpg $UNVERIFIED_SCRIPT
159 umount /tmp/boot-media
160 rmdir /tmp/boot-media
164 echo $(date "+%H:%M:%S") " This error likely indicates a networking configuration error. "
165 echo $(date "+%H:%M:%S") " Please, check whether you can ping this machine. If you can, "
166 echo $(date "+%H:%M:%S") " we recommend checking your DNS settings. If you cannot, then "
167 echo $(date "+%H:%M:%S") " please double check your network settings registered at PLC and "
168 echo $(date "+%H:%M:%S") " stored on this Boot Image."
171 echo $(date "+%H:%M:%S") " This error likely indicates that the hardware clock is likely not set "
172 echo $(date "+%H:%M:%S") " to GMT. The result is that authentication between the local and "
173 echo $(date "+%H:%M:%S") " remote site fails. Please double check this machine's system "
174 echo $(date "+%H:%M:%S") " clock, and set it to GMT in the BIOS. If after rebooting the same "
175 echo $(date "+%H:%M:%S") " error occurs, please report the situation to support@planet-lab.org "
176 echo $(date "+%H:%M:%S") " with as much detail as possible."
179 echo $(date "+%H:%M:%S") " The best-practice approach for handling this error is not yet "
180 echo $(date "+%H:%M:%S") " documented. Please report this error to support@planet-lab.org "
181 echo $(date "+%H:%M:%S") " with as much detail as possible."
184 # in any case display as much info as we can (see pl_functions)
185 pl_network_sanity_checks
189 elif [ -n "$DISCONNECTED_OPERATION" ]; then
190 mkdir /tmp/boot-media
191 mount -U "$DISCONNECTED_OPERATION" /tmp/boot-media
192 cp $UNVERIFIED_SCRIPT /tmp/boot-media
193 umount /tmp/boot-media
194 rmdir /tmp/boot-media
197 echo $(date "+%H:%M:%S") " pl_boot: verifying downloaded script"
198 rm -f $VERIFIED_SCRIPT
199 $GPG_CMD 2> /tmp/gpg_errors
200 if [ $? -ne 0 ]; then
201 echo $(date "+%H:%M:%S") " pl_boot: failed to verify file:"
206 echo $(date "+%H:%M:%S") " pl_boot: decrypted and verified script succesfully"
208 echo $(date "+%H:%M:%S") " pl_boot: handing control to download script"
209 rm -f $UNVERIFIED_SCRIPT
210 chmod +x $VERIFIED_SCRIPT
213 echo $(date "+%H:%M:%S") " pl_boot: downloaded script has returned"
216 echo $(date "+%H:%M:%S") " pl_boot: automatic boot process canceled by user"