Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/bin/bash | |
| 2 | |
| 3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 | |
| 7 # Script to convert the output of build_image.sh to a usb image. | |
|
petkov
2009/12/23 02:00:39
Please change description.
| |
| 8 | |
| 9 # Load common constants. This should be the first executable line. | |
| 10 # The path to common.sh should be relative to your script's location. | |
| 11 . "$(dirname "$0")/common.sh" | |
| 12 | |
| 13 assert_outside_chroot | |
| 14 | |
| 15 cd $(dirname "$0") | |
| 16 | |
| 17 DEFAULT_PRIVATE_KEY="$SRC_ROOT/platform/testing/testing_rsa" | |
| 18 | |
| 19 DEFINE_string ip "" "IP address of running Chromium OS instance" | |
| 20 DEFINE_boolean ignore_version $FLAGS_TRUE \ | |
| 21 "Ignore existing version on running instance and always update" | |
| 22 DEFINE_boolean ignore_hostname $FLAGS_TRUE \ | |
| 23 "Ignore existing AU hostname on running instance use this hostname" | |
| 24 DEFINE_string private_key "$DEFAULT_PRIVATE_KEY" \ | |
| 25 "Private key of root account on instance" | |
| 26 | |
| 27 FLAGS "$@" || exit 1 | |
| 28 eval set -- "${FLAGS_ARGV}" | |
| 29 | |
| 30 set -e | |
| 31 | |
| 32 if [ -z "$FLAGS_ip" ]; then | |
| 33 echo "Please specify the IP of the Chromium OS instance" | |
| 34 exit 1 | |
| 35 fi | |
| 36 | |
| 37 TMP=$(mktemp -d /tmp/image_to_live.XXXX) | |
| 38 TMP_PRIVATE_KEY=$TMP/private_key | |
| 39 TMP_KNOWN_HOSTS=$TMP/known_hosts | |
| 40 | |
| 41 function kill_all_devservers { | |
| 42 ! pkill -f 'python devserver.py' | |
| 43 } | |
| 44 | |
| 45 function cleanup { | |
| 46 kill_all_devservers | |
| 47 rm -rf $TMP | |
| 48 } | |
| 49 | |
| 50 trap cleanup EXIT | |
| 51 | |
| 52 function remote_sh { | |
| 53 # Disable strict host checking so that we don't prompt the user when | |
| 54 # the host key file is removed and just go ahead and add it. | |
| 55 REMOTE_OUT=$(ssh -o StrictHostKeyChecking=no -o \ | |
| 56 UserKnownHostsFile=$TMP_KNOWN_HOSTS root@$FLAGS_ip "$@") | |
| 57 return ${PIPESTATUS[0]} | |
| 58 } | |
| 59 | |
| 60 function remote_reboot_sh { | |
|
petkov
2009/12/23 02:00:39
A bit confusing name because the routine has nothi
| |
| 61 rm -f $TMP_KNOWN_HOSTS | |
| 62 remote_sh "$@" | |
| 63 } | |
| 64 | |
| 65 function set_up_remote_access { | |
| 66 if [ -z "$SSH_AGENT_PID" ]; then | |
| 67 eval `ssh-agent` | |
| 68 fi | |
| 69 cp $FLAGS_private_key $TMP_PRIVATE_KEY | |
| 70 chmod 0400 $TMP_PRIVATE_KEY | |
| 71 ssh-add $TMP_PRIVATE_KEY | |
| 72 | |
| 73 # Verify the client is reachable before continuing | |
| 74 remote_sh "true" | |
| 75 } | |
| 76 | |
| 77 function start_dev_server { | |
| 78 kill_all_devservers | |
| 79 sudo -v | |
| 80 ./enter_chroot.sh "cd ../platform/dev; ./start-devserver.sh>/dev/null 2>&1" & | |
| 81 echo -n "Waiting on devserver to start" | |
| 82 until netstat -anp 2>&1 | grep 8080 > /dev/null; do | |
| 83 sleep .5 | |
| 84 echo -n "." | |
| 85 done | |
| 86 echo "" | |
| 87 } | |
| 88 | |
| 89 function prepare_update_metadata { | |
| 90 remote_sh "mount -norw,remount /" | |
| 91 | |
| 92 if [ $FLAGS_ignore_version -eq $FLAGS_TRUE ]; then | |
| 93 echo "Forcing update independent of the current version" | |
|
petkov
2009/12/23 02:00:39
This change adds an -f flag to force update.
http:
| |
| 94 remote_sh "cat /etc/lsb-release |\ | |
| 95 grep -v CHROMEOS_RELEASE_VERSION > /etc/lsb-release~;\ | |
| 96 mv /etc/lsb-release~ /etc/lsb-release; \ | |
| 97 echo 'CHROMEOS_RELEASE_VERSION=0.0.0.0' >> /etc/lsb-release" | |
| 98 fi | |
| 99 | |
| 100 if [ $FLAGS_ignore_hostname -eq $FLAGS_TRUE ]; then | |
| 101 echo "Forcing update from $HOSTNAME" | |
| 102 remote_sh "cat /etc/lsb-release |\ | |
| 103 grep -v '^CHROMEOS_AUSERVER=' |\ | |
| 104 grep -v '^CHROMEOS_DEVSERVER=' > /etc/lsb-release~;\ | |
| 105 mv /etc/lsb-release~ /etc/lsb-release; \ | |
| 106 echo 'CHROMEOS_AUSERVER=http://$HOSTNAME:8080/update' >> \ | |
| 107 /etc/lsb-release; \ | |
| 108 echo 'CHROMEOS_DEVSERVER=http://$HOSTNAME:8080' >> /etc/lsb-release" | |
| 109 fi | |
| 110 | |
| 111 remote_sh "mount -noro,remount /" | |
| 112 } | |
| 113 | |
| 114 function run_auto_update { | |
| 115 echo "Starting update and clear away prior" | |
| 116 UPDATE_FILE=/var/log/softwareupdate.log | |
| 117 # Clear it out so we don't see a prior run and make sure it | |
| 118 # exists so the first tail below can't fail if it races the | |
| 119 # memento updater first write and wins. | |
| 120 remote_sh "rm -f $UPDATE_FILE; touch $UPDATE_FILE; \ | |
| 121 /opt/google/memento_updater/memento_updater.sh</dev/null>&/dev/null&" | |
| 122 | |
| 123 local update_error | |
| 124 local output_file | |
| 125 local progress | |
| 126 | |
| 127 update_error=1 | |
| 128 output_file=$TMP/output | |
| 129 | |
| 130 while true; do | |
| 131 # The softwareupdate.log gets pretty bit with download progress | |
|
petkov
2009/12/23 02:00:39
s/bit/big/
| |
| 132 # lines so only look in the last 100 lines for status. | |
| 133 remote_sh "tail -100 $UPDATE_FILE" | |
| 134 echo "$REMOTE_OUT" > $output_file | |
| 135 progress=$(tail -4 $output_file | grep 0K | head -1) | |
| 136 if [ -n "$progress" ]; then | |
| 137 echo "Image fetching progress: $progress" | |
| 138 fi | |
| 139 if grep -q 'updatecheck status="noupdate"' $output_file; then | |
| 140 echo "devserver is claiming there is no update available." | |
| 141 echo "Consider setting --ignore_version." | |
| 142 break | |
| 143 fi | |
| 144 if grep -q 'Autoupdate applied. You should now reboot' $output_file; then | |
| 145 echo "Autoupdate was successful." | |
| 146 update_error=0 | |
| 147 fi | |
| 148 if grep -q 'Memento AutoUpdate terminating' $output_file; then | |
| 149 break | |
| 150 fi | |
| 151 # Sleep for a while so that ssh handling doesn't slow down the install | |
| 152 sleep 2 | |
| 153 done | |
| 154 | |
| 155 return $update_error | |
| 156 } | |
| 157 | |
| 158 function remote_reboot { | |
| 159 echo "Rebooting." | |
| 160 remote_sh "touch /tmp/awaiting_reboot; reboot" | |
| 161 local output_file | |
| 162 output_file=$TMP/output | |
| 163 | |
| 164 while true; do | |
| 165 REMOTE_OUT="" | |
| 166 # This may fail while the machine is done so generate output and a | |
|
petkov
2009/12/23 02:00:39
The "right" way to do this is to babysit the boot
| |
| 167 # boolean result to distinguish between down/timeout and real failure | |
| 168 ! remote_reboot_sh "echo 0; [ -e /tmp/awaiting_reboot ] && echo '1'; true" | |
| 169 echo "$REMOTE_OUT" > $output_file | |
| 170 if grep -q "0" $output_file; then | |
| 171 if grep -q "1" $output_file; then | |
| 172 echo "Not yet rebooted" | |
| 173 else | |
| 174 echo "Rebooted and responding" | |
| 175 break | |
| 176 fi | |
| 177 fi | |
| 178 sleep .5 | |
| 179 done | |
| 180 } | |
| 181 | |
| 182 set_up_remote_access | |
| 183 | |
| 184 if remote_sh [ -e /tmp/memento_autoupdate_completed ]; then | |
| 185 echo "Machine has been updated but not yet rebooted. Rebooting it now." | |
| 186 echo "Rerun this script if you still wish to update it." | |
| 187 remote_reboot | |
| 188 exit 1 | |
| 189 fi | |
| 190 | |
| 191 start_dev_server | |
| 192 | |
| 193 prepare_update_metadata | |
| 194 | |
| 195 if ! run_auto_update; then | |
| 196 echo "Update was not successful." | |
| 197 exit | |
| 198 fi | |
| 199 | |
| 200 remote_reboot | |
| 201 | |
| 202 remote_sh "grep ^CHROMEOS_RELEASE_DESCRIPTION= /etc/lsb-release" | |
| 203 RELEASE_DESCRIPTION=$(echo $REMOTE_OUT | cut -d '=' -f 2) | |
| 204 echo "Update was successful and rebooted to $RELEASE_DESCRIPTION" | |
| OLD | NEW |