Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: image_to_live.sh

Issue 3393019: Add verify option to image_to_live. (Closed) Base URL: http://git.chromium.org/git/crosutils.git
Patch Set: Last stuff Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « bin/cros_run_vm_update ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash 1 #!/bin/bash
2 2
3 # Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 # Script to update an image onto a live running ChromiumOS instance. 7 # Script to update an image onto a live running ChromiumOS instance.
8 8
9 # Load common constants. This should be the first executable line. 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. 10 # The path to common.sh should be relative to your script's location.
11 11
12 . "$(dirname $0)/common.sh" 12 . "$(dirname $0)/common.sh"
13 . "$(dirname $0)/remote_access.sh" 13 . "$(dirname $0)/remote_access.sh"
14 14
15 # Flags to control image_to_live. 15 # Flags to control image_to_live.
16 DEFINE_boolean ignore_hostname ${FLAGS_TRUE} \ 16 DEFINE_boolean ignore_hostname ${FLAGS_TRUE} \
17 "Ignore existing AU hostname on running instance use this hostname." 17 "Ignore existing AU hostname on running instance use this hostname."
18 DEFINE_boolean ignore_version ${FLAGS_TRUE} \ 18 DEFINE_boolean ignore_version ${FLAGS_TRUE} \
19 "Ignore existing version on running instance and always update." 19 "Ignore existing version on running instance and always update."
20 DEFINE_string server_log "dev_server.log" \ 20 DEFINE_string server_log "dev_server.log" \
21 "Path to log for the devserver." 21 "Path to log for the devserver."
22 DEFINE_boolean update "${FLAGS_TRUE}" \ 22 DEFINE_boolean update "${FLAGS_TRUE}" \
23 "Perform update of root partition." 23 "Perform update of root partition."
24 DEFINE_boolean update_known_hosts ${FLAGS_FALSE} \ 24 DEFINE_boolean update_known_hosts ${FLAGS_FALSE} \
25 "Update your known_hosts with the new remote instance's key." 25 "Update your known_hosts with the new remote instance's key."
26 DEFINE_string update_log "update_engine.log" \ 26 DEFINE_string update_log "update_engine.log" \
27 "Path to log for the update_engine." 27 "Path to log for the update_engine."
28 DEFINE_boolean verify ${FLAGS_TRUE} "Verify image on device after update."
28 29
29 # Flags for devserver. 30 # Flags for devserver.
30 DEFINE_string archive_dir "" \ 31 DEFINE_string archive_dir "" \
31 "Update using the test image in the image.zip in this directory." a 32 "Update using the test image in the image.zip in this directory." a
32 DEFINE_integer devserver_port 8080 \ 33 DEFINE_integer devserver_port 8080 \
33 "Port to use for devserver." 34 "Port to use for devserver."
34 DEFINE_string image "" \ 35 DEFINE_string image "" \
35 "Update with this image path that is in this source checkout." i 36 "Update with this image path that is in this source checkout." i
37 DEFINE_boolean update_stateful ${FLAGS_TRUE} \
38 "Perform update of stateful partition e.g. /var /usr/local."
36 DEFINE_string update_url "" "Full url of an update image." 39 DEFINE_string update_url "" "Full url of an update image."
37 40
38 # Flags for stateful update. 41 # Flags for stateful update.
39 DEFINE_string stateful_update_flag "" \ 42 DEFINE_string stateful_update_flag "" \
40 "Flag to pass to stateful update e.g. old, clean, etc." s 43 "Flag to pass to stateful update e.g. old, clean, etc." s
41 44
42 UPDATER_BIN='/usr/bin/update_engine_client' 45 UPDATER_BIN="/usr/bin/update_engine_client"
43 UPDATER_IDLE='UPDATE_STATUS_IDLE' 46 UPDATER_IDLE="UPDATE_STATUS_IDLE"
44 UPDATER_NEED_REBOOT='UPDATE_STATUS_UPDATED_NEED_REBOOT' 47 UPDATER_NEED_REBOOT="UPDATE_STATUS_UPDATED_NEED_REBOOT"
45 UPDATER_UPDATE_CHECK='UPDATE_STATUS_CHECKING_FOR_UPDATE' 48 UPDATER_UPDATE_CHECK="UPDATE_STATUS_CHECKING_FOR_UPDATE"
46 UPDATER_DOWNLOADING='UPDATE_STATUS_DOWNLOADING' 49 UPDATER_DOWNLOADING="UPDATE_STATUS_DOWNLOADING"
50
51 IMAGE_PATH=""
47 52
48 function kill_all_devservers { 53 function kill_all_devservers {
49 # Using ! here to avoid exiting with set -e is insufficient, so use 54 # Using ! here to avoid exiting with set -e is insufficient, so use
50 # || true instead. 55 # || true instead.
51 sudo pkill -f devserver\.py || true 56 sudo pkill -f devserver\.py || true
52 } 57 }
53 58
54 function cleanup { 59 function cleanup {
55 if [ -z "${FLAGS_update_url}" ]; then 60 if [ -z "${FLAGS_update_url}" ]; then
56 kill_all_devservers 61 kill_all_devservers
(...skipping 25 matching lines...) Expand all
82 echo "/home/${USER}/trunk/${relative_path}" 87 echo "/home/${USER}/trunk/${relative_path}"
83 } 88 }
84 89
85 function start_dev_server { 90 function start_dev_server {
86 kill_all_devservers 91 kill_all_devservers
87 local devserver_flags=${FLAGS_devserver_port} 92 local devserver_flags=${FLAGS_devserver_port}
88 # Parse devserver flags. 93 # Parse devserver flags.
89 if [ -n "${FLAGS_image}" ]; then 94 if [ -n "${FLAGS_image}" ]; then
90 devserver_flags="${devserver_flags} \ 95 devserver_flags="${devserver_flags} \
91 --image $(reinterpret_path_for_chroot ${FLAGS_image})" 96 --image $(reinterpret_path_for_chroot ${FLAGS_image})"
97 IMAGE_PATH="${FLAGS_image}"
98
92 elif [ -n "${FLAGS_archive_dir}" ]; then 99 elif [ -n "${FLAGS_archive_dir}" ]; then
93 devserver_flags="${devserver_flags} \ 100 devserver_flags="${devserver_flags} \
94 --archive_dir $(reinterpret_path_for_chroot ${FLAGS_archive_dir}) -t" 101 --archive_dir $(reinterpret_path_for_chroot ${FLAGS_archive_dir}) -t"
102 IMAGE_PATH="${FLAGS_archive_dir}/chromiumos_test_image.bin"
95 fi 103 fi
96 104
97 info "Starting devserver with flags ${devserver_flags}" 105 info "Starting devserver with flags ${devserver_flags}"
98 ./enter_chroot.sh "sudo ./start_devserver ${devserver_flags} \ 106 ./enter_chroot.sh "sudo ./start_devserver ${devserver_flags} \
99 --client_prefix=ChromeOSUpdateEngine > ${FLAGS_server_log} 2>&1" & 107 --client_prefix=ChromeOSUpdateEngine > ${FLAGS_server_log} 2>&1" &
100 108
101 echo -n "Waiting on devserver to start" 109 echo -n "Waiting on devserver to start"
102 until netstat -anp 2>&1 | grep 0.0.0.0:${FLAGS_devserver_port} > /dev/null 110 until netstat -anp 2>&1 | grep 0.0.0.0:${FLAGS_devserver_port} > /dev/null
103 do 111 do
104 sleep .5 112 sleep .5
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 info "Not yet rebooted" 259 info "Not yet rebooted"
252 else 260 else
253 info "Rebooted and responding" 261 info "Rebooted and responding"
254 break 262 break
255 fi 263 fi
256 fi 264 fi
257 sleep .5 265 sleep .5
258 done 266 done
259 } 267 }
260 268
269 function verify_image {
270 info "Verifying image."
271 "${SCRIPTS_DIR}/mount_gpt_image.sh" --from "$(dirname ${IMAGE_PATH})" \
272 --image "$(basename ${IMAGE_PATH})" \
273 --read_only
274
275 local lsb_release=$(cat /tmp/m/etc/lsb-release)
276 info "Verifying image with release:"
277 echo ${lsb_release}
278
279 "${SCRIPTS_DIR}/mount_gpt_image.sh" --unmount
280
281 remote_sh "cat /etc/lsb-release"
282 info "Remote image reports:"
283 echo ${REMOTE_OUT}
284
285 if [ "${lsb_release}" = "${REMOTE_OUT}" ]; then
286 info "Update was successful and image verified as ${lsb_release}."
287 return 0
288 else
289 warn "Image verification failed."
290 return 1
291 fi
292 }
293
261 function main() { 294 function main() {
262 assert_outside_chroot 295 assert_outside_chroot
263 296
264 cd $(dirname "$0") 297 cd $(dirname "$0")
265 298
266 FLAGS "$@" || exit 1 299 FLAGS "$@" || exit 1
267 eval set -- "${FLAGS_ARGV}" 300 eval set -- "${FLAGS_ARGV}"
268 301
269 set -e 302 set -e
270 303
304 if [ ${FLAGS_verify} -eq ${FLAGS_TRUE} ] && \
305 [ -n "${FLAGS_update_url}" ]; then
306 warn "Verify is not compatible with setting an update url."
307 FLAGS_verify=${FLAGS_FALSE}
308 fi
309
271 trap cleanup EXIT 310 trap cleanup EXIT
272 311
273 TMP=$(mktemp -d /tmp/image_to_live.XXXX) 312 TMP=$(mktemp -d /tmp/image_to_live.XXXX)
274 313
275 remote_access_init 314 remote_access_init
276 315
277 if [ "$(get_update_var CURRENT_OP)" != "${UPDATER_IDLE}" ]; then 316 if [ "$(get_update_var CURRENT_OP)" != "${UPDATER_IDLE}" ]; then
278 warn "Machine is in a bad state. Rebooting it now." 317 warn "Machine is in a bad state. Rebooting it now."
279 remote_reboot 318 remote_reboot
280 fi 319 fi
281 320
282 if [ -z "${FLAGS_update_url}" ]; then 321 if [ -z "${FLAGS_update_url}" ]; then
283 # Start local devserver if no update url specified. 322 # Start local devserver if no update url specified.
284 start_dev_server 323 start_dev_server
285 fi 324 fi
286 325
287 if [ "${FLAGS_update}" -eq "${FLAGS_TRUE}" ] && ! run_auto_update; then 326 if [ ${FLAGS_update} -eq ${FLAGS_TRUE} ] && ! run_auto_update; then
288 die "Update was not successful." 327 die "Update was not successful."
289 fi 328 fi
290 329
291 if ! run_stateful_update; then 330 if [ ${FLAGS_update_stateful} -eq ${FLAGS_TRUE} ] && \
331 ! run_stateful_update; then
292 warn "Stateful update was not successful." 332 warn "Stateful update was not successful."
293 fi 333 fi
294 334
295 remote_reboot 335 remote_reboot
296 336
297 if [[ ${FLAGS_update_hostkey} -eq ${FLAGS_TRUE} ]]; then 337 if [[ ${FLAGS_update_hostkey} -eq ${FLAGS_TRUE} ]]; then
298 local known_hosts="${HOME}/.ssh/known_hosts" 338 local known_hosts="${HOME}/.ssh/known_hosts"
299 cp "${known_hosts}" "${known_hosts}~" 339 cp "${known_hosts}" "${known_hosts}~"
300 grep -v "^${FLAGS_remote} " "${known_hosts}" > "${TMP}/new_known_hosts" 340 grep -v "^${FLAGS_remote} " "${known_hosts}" > "${TMP}/new_known_hosts"
301 cat "${TMP}/new_known_hosts" "${TMP_KNOWN_HOSTS}" > "${known_hosts}" 341 cat "${TMP}/new_known_hosts" "${TMP_KNOWN_HOSTS}" > "${known_hosts}"
302 chmod 0640 "${known_hosts}" 342 chmod 0640 "${known_hosts}"
303 info "New updated in ${known_hosts}, backup made." 343 info "New updated in ${known_hosts}, backup made."
304 fi 344 fi
305 345
306 remote_sh "grep ^CHROMEOS_RELEASE_DESCRIPTION= /etc/lsb-release" 346 remote_sh "grep ^CHROMEOS_RELEASE_DESCRIPTION= /etc/lsb-release"
307 local release_description=$(echo ${REMOTE_OUT} | cut -d '=' -f 2) 347 if [ ${FLAGS_verify} -eq ${FLAGS_TRUE} ]; then
308 info "Update was successful and rebooted to $release_description" 348 verify_image
349 else
350 local release_description=$(echo ${REMOTE_OUT} | cut -d '=' -f 2)
351 info "Update was successful and rebooted to $release_description"
352 fi
309 353
310 return 0 354 exit 0
311 } 355 }
312 356
313 main $@ 357 main $@
OLDNEW
« no previous file with comments | « bin/cros_run_vm_update ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698