mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-11 06:56:58 +02:00
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:
parent
602d1a17f6
commit
0ddf0241d4
@ -70,10 +70,26 @@ DEFINE_string arch "" "Architecture of the image."
|
|||||||
FLAGS "$@" || exit 1
|
FLAGS "$@" || exit 1
|
||||||
eval set -- "${FLAGS_ARGV}"
|
eval set -- "${FLAGS_ARGV}"
|
||||||
|
|
||||||
if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then
|
# Generates a descriptive string of a removable device. Includes the
|
||||||
if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] ; then
|
# manufacturer (if non-empty), product and a human-readable size.
|
||||||
die "Factory test image is incompatible with factory install shim"
|
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
|
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
|
fi
|
||||||
|
|
||||||
# Allow --from /foo/file.bin
|
# Allow --from /foo/file.bin
|
||||||
@ -84,7 +100,6 @@ if [ -f "${FLAGS_from}" ]; then
|
|||||||
FLAGS_from="${pathname}"
|
FLAGS_from="${pathname}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Require autotest for manucaturing image.
|
# Require autotest for manucaturing image.
|
||||||
if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then
|
if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then
|
||||||
echo "Factory image requires --test_image, setting."
|
echo "Factory image requires --test_image, setting."
|
||||||
@ -145,21 +160,6 @@ if [ -n "${FLAGS_to_product}" ]; then
|
|||||||
fi
|
fi
|
||||||
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.
|
# No target provided, attempt autodetection.
|
||||||
if [ "${FLAGS_to}" == "/dev/sdX" ]; then
|
if [ "${FLAGS_to}" == "/dev/sdX" ]; then
|
||||||
echo "No target device was specified, autodetecting..."
|
echo "No target device was specified, autodetecting..."
|
||||||
@ -225,16 +225,6 @@ fi
|
|||||||
STATEFUL_DIR="${FLAGS_from}/stateful_partition"
|
STATEFUL_DIR="${FLAGS_from}/stateful_partition"
|
||||||
mkdir -p "${STATEFUL_DIR}"
|
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
|
if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then
|
||||||
# Make a test image - this returns the test filename in CHROMEOS_RETURN_VAL
|
# Make a test image - this returns the test filename in CHROMEOS_RETURN_VAL
|
||||||
prepare_test_image "${FLAGS_from}" "${FLAGS_image_name}"
|
prepare_test_image "${FLAGS_from}" "${FLAGS_image_name}"
|
||||||
|
Loading…
Reference in New Issue
Block a user