From f9c49add4466e36205c1067fb168279e20e90f66 Mon Sep 17 00:00:00 2001 From: Nick Sanders Date: Mon, 21 Mar 2011 18:56:04 -0700 Subject: [PATCH] Allow file in --from arg * mount_gpt_image.sh * image_to_usb.sh BUG=chromium-os:12367 TEST=mount w/ --from file, check failure with file and -i, block dev and -i, check unmount, check image_to_usb, check --from dir -i file Change-Id: I8d8604ee7ee83513edd687b0a66cda44f64db1f8 Review URL: http://codereview.chromium.org/6685101 --- image_to_usb.sh | 11 ++++++++++- mount_gpt_image.sh | 22 +++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/image_to_usb.sh b/image_to_usb.sh index e957e2f372..e0c251e539 100755 --- a/image_to_usb.sh +++ b/image_to_usb.sh @@ -40,7 +40,7 @@ get_default_board # Flags DEFINE_string board "${DEFAULT_BOARD}" "Board for which the image was built" DEFINE_string from "" \ - "Directory containing ${CHROMEOS_IMAGE_NAME}" + "Directory containing ${CHROMEOS_IMAGE_NAME}, or filename" DEFINE_string to "/dev/sdX" "${DEFAULT_TO_HELP}" DEFINE_boolean yes ${FLAGS_FALSE} "Answer yes to all prompts" "y" DEFINE_boolean force_copy ${FLAGS_FALSE} "Always rebuild test image" @@ -72,6 +72,15 @@ if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then fi fi +# Allow --from /foo/file.bin +if [ -f "${FLAGS_from}" ]; then + pathname=$(dirname "${FLAGS_from}") + filename=$(basename "${FLAGS_from}") + FLAGS_image_name="${filename}" + FLAGS_from="${pathname}" +fi + + # Require autotest for manucaturing image. if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then echo "Factory image requires --test_image, setting." diff --git a/mount_gpt_image.sh b/mount_gpt_image.sh index 87324cbbbe..dc0491a5d1 100755 --- a/mount_gpt_image.sh +++ b/mount_gpt_image.sh @@ -51,7 +51,7 @@ DEFINE_boolean safe $FLAGS_FALSE \ DEFINE_boolean unmount $FLAGS_FALSE \ "Unmount previously mounted dir." u DEFINE_string from "/dev/sdc" \ - "Directory containing image or device with image on it" f + "Directory, image, or device with image on it" f DEFINE_string image "chromiumos_image.bin"\ "Name of the bin file if a directory is specified in the from flag" i DEFINE_string "rootfs_mountpt" "/tmp/m" "Mount point for rootfs" "r" @@ -68,6 +68,26 @@ eval set -- "${FLAGS_ARGV}" # Die on error set -e +# Check for conflicting args. +# If --from is a block device, --image can't also be specified. +if [ -b "${FLAGS_from}" ]; then + if [ "${FLAGS_image}" != "chromiumos_image.bin" ]; then + die "-i ${FLAGS_image} can't be used with block device ${FLAGS_from}" + fi +fi + +# Allow --from /foo/file.bin +if [ -f "${FLAGS_from}" ]; then + # If --from is specified as a file, --image cannot be also specified. + if [ "${FLAGS_image}" != "chromiumos_image.bin" ]; then + die "-i ${FLAGS_image} can't be used with --from file ${FLAGS_from}" + fi + pathname=$(dirname "${FLAGS_from}") + filename=$(basename "${FLAGS_from}") + FLAGS_image="${filename}" + FLAGS_from="${pathname}" +fi + # Common unmounts for either a device or directory function unmount_image() { echo "Unmounting image from ${FLAGS_stateful_mountpt}" \