6 echo pl_boot on console > /dev/console
11 . /etc/init.d/pl_functions
15 # Run gpg once to create default options
18 /usr/bin/gpg --yes 2>/dev/null </dev/null
20 # if this file is present, cancel the boot (exit this script)
21 CANCEL_BOOT_FLAG=/tmp/CANCEL_BOOT
23 # how many times to fail in attempting to contact primary server
24 # before falling back to original. if the backup fails this many times
25 # too, then the process is repeated started with the primary server
26 ATTEMPTS_BEFORE_BACKUP=3
28 # where all the configuration files for contacting
29 # the boot server are stored
32 # get the server we are going to be contacting
33 BOOT_SERVER=$(cat $BOOT_DIR/boot_server)
34 BOOT_SERVER_PORT=$(cat $BOOT_DIR/boot_server_port)
36 # the file to request from the boot server
37 BOOT_SERVER_PATH=$(cat $BOOT_DIR/boot_server_path)
39 # location of the cacert for this boot server
40 BOOT_SERVER_CACERT=$BOOT_DIR/cacert.pem
42 # location of the gpg key ring to verify scripts
43 BOOT_SERVER_GPG_KEYRING=$BOOT_DIR/pubring.gpg
45 # get the backup server we are going to be contacting
46 BACKUP_BOOT_SERVER=$(cat $BOOT_DIR/backup/boot_server)
47 BACKUP_BOOT_SERVER_PORT=$(cat $BOOT_DIR/backup/boot_server_port)
49 # the file to request from the backup boot server
50 BACKUP_BOOT_SERVER_PATH=$(cat $BOOT_DIR/backup/boot_server_path)
52 # location of the cacert for the backup boot server
53 BACKUP_BOOT_SERVER_CACERT=$BOOT_DIR/backup/cacert.pem
55 # location of the gpg key ring for backup server to verify scripts
56 BACKUP_BOOT_SERVER_GPG_KEYRING=$BOOT_DIR/backup/pubring.gpg
58 # location of a file containing this boot cd version
59 BOOT_VERSION_FILE=/pl_version
61 # the locations of the downloaded scripts
62 UNVERIFIED_SCRIPT=/tmp/bootscript.gpg
63 VERIFIED_SCRIPT=/tmp/bootscript
66 # --------------------------
69 # now, contact the boot server, run the script, and do it over again.
72 # set to one when we are trying to contact backup server
75 # start out contacting the primary servers
76 CONNECT_BOOT_SERVER=$BOOT_SERVER
77 CONNECT_BOOT_SERVER_PORT=$BOOT_SERVER_PORT
78 CONNECT_BOOT_SERVER_PATH=$BOOT_SERVER_PATH
79 CONNECT_BOOT_SERVER_GPG_KEYRING=$BOOT_SERVER_GPG_KEYRING
80 CONNECT_BOOT_SERVER_CACERT=$BOOT_SERVER_CACERT
84 if [[ -f $CANCEL_BOOT_FLAG ]]; then
85 echo $(date "+%H:%M:%S") " pl_boot: got request to cancel boot, exiting"
89 if [[ $contact_count -ge $ATTEMPTS_BEFORE_BACKUP ]]; then
93 if [[ $on_backup_server == 1 ]]; then
94 echo $(date "+%H:%M:%S") " pl_boot: failed to contact backup server, trying primary $BOOT_SERVER"
98 CONNECT_BOOT_SERVER=$BOOT_SERVER
99 CONNECT_BOOT_SERVER_PORT=$BOOT_SERVER_PORT
100 CONNECT_BOOT_SERVER_PATH=$BOOT_SERVER_PATH
101 CONNECT_BOOT_SERVER_GPG_KEYRING=$BOOT_SERVER_GPG_KEYRING
102 CONNECT_BOOT_SERVER_CACERT=$BOOT_SERVER_CACERT
104 echo $(date "+%H:%M:%S") " pl_boot: failed to contact primary server, trying backup $BACKUP_BOOT_SERVER"
108 CONNECT_BOOT_SERVER=$BACKUP_BOOT_SERVER
109 CONNECT_BOOT_SERVER_PORT=$BACKUP_BOOT_SERVER_PORT
110 CONNECT_BOOT_SERVER_PATH=$BACKUP_BOOT_SERVER_PATH
111 CONNECT_BOOT_SERVER_GPG_KEYRING=$BACKUP_BOOT_SERVER_GPG_KEYRING
112 CONNECT_BOOT_SERVER_CACERT=$BACKUP_BOOT_SERVER_CACERT
116 if [[ $contact_count != 0 ]]; then
118 echo $(date "+%H:%M:%S") " pl_boot: next attempt in 30s, to fetch script from server at $CONNECT_BOOT_SERVER"
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 echo $(date "+%H:%M:%S") " 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 echo $(date "+%H:%M:%S") " pl_boot: fetching script from boot server $CONNECT_BOOT_SERVER"
156 rm -f $UNVERIFIED_SCRIPT
159 if [ $curl_err -ne 0 ]; then
160 echo $(date "+%H:%M:%S") " 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 echo $(date "+%H:%M:%S") " This error likely indicates a networking configuration error. "
173 echo $(date "+%H:%M:%S") " Please, check whether you can ping this machine. If you can, "
174 echo $(date "+%H:%M:%S") " we recommend checking your DNS settings. If you cannot, then "
175 echo $(date "+%H:%M:%S") " please double check your network settings registered at PLC and "
176 echo $(date "+%H:%M:%S") " stored on this Boot Image."
179 echo $(date "+%H:%M:%S") " This error likely indicates that the hardware clock is likely not set "
180 echo $(date "+%H:%M:%S") " to GMT. The result is that authentication between the local and "
181 echo $(date "+%H:%M:%S") " remote site fails. Please double check this machine's system "
182 echo $(date "+%H:%M:%S") " clock, and set it to GMT in the BIOS. If after rebooting the same "
183 echo $(date "+%H:%M:%S") " error occurs, please report the situation to support@planet-lab.org "
184 echo $(date "+%H:%M:%S") " with as much detail as possible."
187 echo $(date "+%H:%M:%S") " The best-practice approach for handling this error is not yet "
188 echo $(date "+%H:%M:%S") " documented. Please report this error to support@planet-lab.org "
189 echo $(date "+%H:%M:%S") " with as much detail as possible."
192 # in any case display as much info as we can (see pl_functions)
193 pl_network_sanity_checks
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 echo $(date "+%H:%M:%S") " pl_boot: verifying downloaded script"
206 rm -f $VERIFIED_SCRIPT
207 $GPG_CMD 2> /tmp/gpg_errors
208 if [ $? -ne 0 ]; then
209 echo $(date "+%H:%M:%S") " pl_boot: failed to verify file:"
214 echo $(date "+%H:%M:%S") " pl_boot: decrypted and verified script succesfully"
216 echo $(date "+%H:%M:%S") " pl_boot: handing control to download script"
217 rm -f $UNVERIFIED_SCRIPT
218 chmod +x $VERIFIED_SCRIPT
221 echo $(date "+%H:%M:%S") " pl_boot: downloaded script has returned"
224 echo $(date "+%H:%M:%S") " pl_boot: automatic boot process canceled by user"