image_to_usb.sh: cleanup and dead code removal

Migrated function definition to the beginning of the code; some minor
cosmetics.  This is a preliminary fix to the actual feature mentioned in
the cited issue.

BUG=chromium-os:26010
TEST=Executed in chroot environment with various combinations of flags
and connected devices

Change-Id: Ib73328e738ebecc38e6faafbd4feb33ced8804ad
Reviewed-on: https://gerrit.chromium.org/gerrit/15438
Reviewed-by: Chris Sosa <sosa@chromium.org>
Commit-Ready: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
This commit is contained in:
Gilad Arnold 2012-02-07 14:39:41 -08:00 committed by Gerrit
parent 602d1a17f6
commit 0ddf0241d4

View File

@ -70,10 +70,26 @@ DEFINE_string arch "" "Architecture of the image."
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then
if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] ; then
die "Factory test image is incompatible with factory install shim"
# Generates a descriptive string of a removable device. Includes the
# manufacturer (if non-empty), product and a human-readable size.
function get_disk_string() {
local disk="${1##*/}"
local manufacturer_string=$(get_disk_info $disk manufacturer)
local product_string=$(get_disk_info $disk product)
local disk_size=$(sudo fdisk -l /dev/$disk 2>/dev/null | grep Disk |
head -n 1 | cut -d' ' -f3-4 | sed 's/,//g')
# I've seen one case where manufacturer only contains spaces, hence the test.
if [ -n "${manufacturer_string// }" ]; then
echo -n "${manufacturer_string} "
fi
echo "${product_string}, ${disk_size}"
}
# Prohibit mutually exclusive factory/install flags.
if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} -a \
${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] ; then
die "Factory test image is incompatible with factory install shim"
fi
# Allow --from /foo/file.bin
@ -84,7 +100,6 @@ if [ -f "${FLAGS_from}" ]; then
FLAGS_from="${pathname}"
fi
# Require autotest for manucaturing image.
if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then
echo "Factory image requires --test_image, setting."
@ -145,21 +160,6 @@ if [ -n "${FLAGS_to_product}" ]; then
fi
fi
# Generates a descriptive string of a removable device. Includes the
# manufacturer (if non-empty), product and a human-readable size.
function get_disk_string() {
local disk="${1##*/}"
local manufacturer_string=$(get_disk_info $disk manufacturer)
local product_string=$(get_disk_info $disk product)
local disk_size=$(sudo fdisk -l /dev/$disk 2>/dev/null | grep Disk |
head -n 1 | cut -d' ' -f3-4 | sed 's/,//g')
# I've seen one case where manufacturer only contains spaces, hence the test.
if [ -n "${manufacturer_string// }" ]; then
echo -n "${manufacturer_string} "
fi
echo "${product_string}, ${disk_size}"
}
# No target provided, attempt autodetection.
if [ "${FLAGS_to}" == "/dev/sdX" ]; then
echo "No target device was specified, autodetecting..."
@ -225,16 +225,6 @@ fi
STATEFUL_DIR="${FLAGS_from}/stateful_partition"
mkdir -p "${STATEFUL_DIR}"
function do_cleanup {
echo "Cleaning loopback devices: ${STATEFUL_LOOP_DEV}"
if [ "${STATEFUL_LOOP_DEV}" != "" ]; then
sudo umount "${STATEFUL_DIR}"
sudo losetup -d "${STATEFUL_LOOP_DEV}"
rmdir "${STATEFUL_DIR}"
echo "Cleaned"
fi
}
if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then
# Make a test image - this returns the test filename in CHROMEOS_RETURN_VAL
prepare_test_image "${FLAGS_from}" "${FLAGS_image_name}"