mirror of
https://github.com/flatcar/scripts.git
synced 2025-11-26 21:11:54 +01:00
Add a few more safeguards to image_to_usb.sh so we don't accidentally overwrite a hard drive. Also without the --to option, list USB drives
I've updated the CL to remove the space in the "] ;". I'm not sure I understand your "size != 0" comment as if the device is just attached for charging, it won't go through the trouble of becoming a USB storage device. Will chat in person. Review URL: http://codereview.chromium.org/2269003
This commit is contained in:
parent
d8d5fff361
commit
66dc143902
@ -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}"
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user