| #!/bin/bash |
| |
| # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| # |
| # Updates an existing vm image with another image. |
| |
| # --- BEGIN COMMON.SH BOILERPLATE --- |
| # Load common CrOS utilities. Inside the chroot this file is installed in |
| # /usr/lib/crosutils. Outside the chroot we find it relative to the script's |
| # location. |
| find_common_sh() { |
| local common_paths=(/usr/lib/crosutils "$(dirname "$(readlink -f "$0")")/..") |
| local path |
| |
| SCRIPT_ROOT= |
| for path in "${common_paths[@]}"; do |
| if [ -r "${path}/common.sh" ]; then |
| SCRIPT_ROOT=${path} |
| break |
| fi |
| done |
| } |
| |
| find_common_sh |
| . "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1) |
| # --- END COMMON.SH BOILERPLATE --- |
| |
| . "${SCRIPT_ROOT}/lib/cros_vm_lib.sh" || die "Unable to load cros_vm_lib.sh" |
| |
| DEFINE_string payload "" "Full name of the payload to update with." |
| DEFINE_string proxy_port "" \ |
| "Have the client request from this proxy instead of devserver." |
| DEFINE_string src_image "" \ |
| "Create a delta update by passing in the image on the remote machine." |
| DEFINE_string stateful_update_flag "" "Flags to pass to stateful update." s |
| DEFINE_string image "" "Path of the image to update to." u |
| DEFINE_string update_url "" "Full url of an update image." |
| DEFINE_string vm_image_path "" "Path of the VM image to update from." v |
| |
| set -e |
| |
| # Parse command line. |
| FLAGS "$@" || exit 1 |
| eval set -- "${FLAGS_ARGV}" |
| |
| [ -n "${FLAGS_vm_image_path}" ] || \ |
| die "You must specify a path to a vm image." |
| |
| trap stop_kvm EXIT |
| start_kvm "${FLAGS_vm_image_path}" |
| retry_until_ssh |
| |
| if [ -n "${FLAGS_image}" ]; then |
| IMAGE_ARGS="--image=$(readlink -f ${FLAGS_image})" |
| fi |
| |
| if [ -n "${FLAGS_payload}" ]; then |
| IMAGE_ARGS="--payload=${FLAGS_payload}" |
| fi |
| |
| if [ -n "${FLAGS_proxy_port}" ]; then |
| IMAGE_ARGS="${IMAGE_ARGS} --proxy_port=${FLAGS_proxy_port}" |
| fi |
| |
| "${SCRIPTS_DIR}/image_to_live.sh" \ |
| --for_vm \ |
| --remote=127.0.0.1 \ |
| --ssh_port=${FLAGS_ssh_port} \ |
| --stateful_update_flag=${FLAGS_stateful_update_flag} \ |
| --src_image="${FLAGS_src_image}" \ |
| --update_url="${FLAGS_update_url}" \ |
| --verify \ |
| ${IMAGE_ARGS} |
| |