From e87403d8f89f6430bc26b383afa742f9dd9aabe7 Mon Sep 17 00:00:00 2001 From: Chris Wolfe Date: Tue, 8 Nov 2011 10:28:19 -0500 Subject: [PATCH] image_to_usb: Add flag to choose disk by product. This adds a --to_product flag which chooses the destination disk with a product value matching the specified pattern. For the case where a developer is regularly writing to an external USB drive, the product name may be more stable than the raw device name. Also added a help string for the --to flag. This was accidentally deleted during some refactoring in 2010. Tested with local cbuildbot internal pfq and manually: ./image_to_usb.sh ./image_to_usb.sh --to=/dev/sde ./image_to_usb.sh --to_product=\*Memory ./image_to_usb.sh --to_product=\* # errors on multiple BUG=chromium-os:22674 TEST=None Change-Id: Ie7137e8c605217a3202c46d75896170fc6b7c4a5 Reviewed-on: https://gerrit.chromium.org/gerrit/11322 Reviewed-by: Chris Sosa Tested-by: Chris Wolfe Commit-Ready: Chris Wolfe --- image_to_usb.sh | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/image_to_usb.sh b/image_to_usb.sh index 737908e3de..606bd07700 100755 --- a/image_to_usb.sh +++ b/image_to_usb.sh @@ -44,7 +44,9 @@ get_default_board DEFINE_string board "${DEFAULT_BOARD}" "Board for which the image was built" DEFINE_string from "" \ "Directory containing ${CHROMEOS_IMAGE_NAME}, or filename" -DEFINE_string to "/dev/sdX" "${DEFAULT_TO_HELP}" +DEFINE_string to "/dev/sdX" "Write to a specific disk or image file." +DEFINE_string to_product "" \ + "Write to a disk with product name matching a pattern." DEFINE_boolean yes ${FLAGS_FALSE} "Answer yes to all prompts" "y" DEFINE_boolean force_copy ${FLAGS_FALSE} "Always rebuild test image" DEFINE_boolean force_non_usb ${FLAGS_FALSE} \ @@ -122,8 +124,35 @@ if [ ! -d "${FLAGS_from}" ] ; then exit 1 fi +if [ -n "${FLAGS_to_product}" ]; then + if [ "${FLAGS_to}" != "/dev/sdX" ]; then + echo "Cannot specify both --to and --to_product" + exit 1 + fi + + match="" + for disk in $(list_usb_disks) $(list_mmc_disks); do + if [[ "$(get_disk_info $disk product)" = ${FLAGS_to_product} ]]; then + if [ -n "${match}" ]; then + echo "Found multiple devices matching product" \ + "'${FLAGS_to_product}'; aborting." + exit 1 + fi + match="$disk" + fi + done + + if [ -z "${match}" ]; then + echo "Failed to find a devices matching product '${FLAGS_to_product}'" + # Leave FLAGS_to set to its default and fall through to the error report. + else + FLAGS_to="/dev/${match}" + fi +fi + if [ "${FLAGS_to}" == "/dev/sdX" ]; then - echo "You must specify a file or device to write to using --to." + echo "You must specify a file or device to write to using one of" \ + "--to or --to_product." disks="$(list_usb_disks) $(list_mmc_disks)" if [ -n "$disks" ]; then echo "Available USB & MMC disks:"