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

Unified Diff: src/scripts/image_to_usb.sh

Issue 2269003: Add more safeguards to image_to_usb.sh. List USB drives if --to is omitted (Closed) Base URL: ssh://gitrw.chromium.org/chromiumos
Patch Set: Clean up style consistency Created 10 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/platform/installer/chromeos-common.sh ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scripts/image_to_usb.sh
diff --git a/src/scripts/image_to_usb.sh b/src/scripts/image_to_usb.sh
index 844e3758f1d6951edf2faf48a1440ff6ebe1ff45..47f383ed4111d4257a19d0a4fd840bf93d0c0ab3 100755
--- a/src/scripts/image_to_usb.sh
+++ b/src/scripts/image_to_usb.sh
@@ -22,6 +22,8 @@ DEFINE_string from "" \
DEFINE_string to "" "${DEFAULT_TO_HELP}"
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} \
+ "Write out image even if target (--to) doesn't look like a USB disk"
DEFINE_boolean factory_install ${FLAGS_FALSE} \
"Whether to generate a factory install shim."
DEFINE_boolean factory ${FLAGS_FALSE} \
@@ -81,6 +83,15 @@ fi
if [ -z "${FLAGS_to}" ]; then
echo "You must specify a file or device to write to using --to."
+ disks=$(list_usb_disks)
+ if [ -n "$disks" ]; then
+ echo "Available USB disks:"
+ for disk in $disks; do
+ echo " /dev/$disk:"
+ echo " Manufacturer: $(get_disk_info $disk manufacturer)"
+ echo " Product: $(get_disk_info $disk product)"
+ done
+ fi
exit 1
fi
@@ -89,6 +100,17 @@ fi
FLAGS_from=`eval readlink -f ${FLAGS_from}`
FLAGS_to=`eval readlink -f ${FLAGS_to}`
+# One last check to make sure user is not shooting themselves in the foot
+if [ -b "${FLAGS_to}" ] &&
+ ! list_usb_disks | grep -q '^'${FLAGS_to##*/}'$' &&
+ [ ${FLAGS_force_non_usb} -ne ${FLAGS_TRUE} ]
+then
+ # Safeguard against writing to a real non-USB disk
+ echo "Error: Device ${FLAGS_to} does not appear to be a USB disk!"
+ echo " To override this safeguard, use the --force_non_usb flag"
+ exit 1
+fi
+
# Use this image as the source image to copy
SRC_IMAGE="${FLAGS_from}/${FLAGS_image_name}"
« no previous file with comments | « src/platform/installer/chromeos-common.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698