mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-22 14:11:07 +02:00
image_to_usb.sh: do not require chromiumos_image.bin when --test_image is used.
The recent changes to image_to_usb.sh assumed that chromiumos_image.bin is always used for generating a test image. This wasn't the case before these changes were applied, where a preexisting test image would have sufficed. This fix eliminates image autodetection entirely when --test_image it used and falls back to the old behavior: if a test image exists, it will use it; otherwise, it will generate it from the image specified by --image_name, or from the default chromiumos_image.bin. This is not to say that I like this behavior: it is subtle, may lead to errors (e.g. using a stale test image whereas the user assumes a new one should be generated), and inconsistent with other behaviors (e.g. installing a recovery image, where no image generation takes place at all). I believe that long term we should eliminate the generation of test images from image_to_usb.sh and have users invoke the necessary scripts (like mod_image_for_test.sh) explicitly. BUG=chromium-os:26239 TEST=Ran script with different combinations of --test_image, --image_name and image files present. Change-Id: Ib2491a7e45e23eb51ced6ef31d3f129ec7863a25 Reviewed-on: https://gerrit.chromium.org/gerrit/15764 Reviewed-by: Richard Barnette <jrbarnette@chromium.org> Commit-Ready: Gilad Arnold <garnold@chromium.org> Tested-by: Gilad Arnold <garnold@chromium.org>
This commit is contained in:
parent
a0a02f4c3a
commit
dd59d7e9a6
@ -230,54 +230,56 @@ fi
|
|||||||
STATEFUL_DIR="${FLAGS_from}/stateful_partition"
|
STATEFUL_DIR="${FLAGS_from}/stateful_partition"
|
||||||
mkdir -p "${STATEFUL_DIR}"
|
mkdir -p "${STATEFUL_DIR}"
|
||||||
|
|
||||||
# Autodetect image.
|
# Figure out which image to use.
|
||||||
if [ -z "${FLAGS_image_name}" ]; then
|
if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ]; then
|
||||||
echo "No image name specified, autodetecting..."
|
# Test image requested: pass the provided (or otherwise default) image name
|
||||||
|
# to the method that's in charge of preparing a test image (note that this
|
||||||
|
# image may or may not exist). The test image filename is returned in
|
||||||
|
# CHROMEOS_RETURN_VAL.
|
||||||
|
prepare_test_image "${FLAGS_from}" \
|
||||||
|
"${FLAGS_image_name:=${CHROMEOS_IMAGE_NAME}}"
|
||||||
|
SRC_IMAGE="${CHROMEOS_RETURN_VAL}"
|
||||||
|
else
|
||||||
|
# Auto-detect and select an image name if none provided.
|
||||||
|
if [ -z "${FLAGS_image_name}" ]; then
|
||||||
|
echo "No image name specified, autodetecting..."
|
||||||
|
|
||||||
# Obtain list of available images that can be used.
|
# Obtain list of available images that can be used.
|
||||||
image_candidate_list=( "${CHROMEOS_IMAGE_NAME}" )
|
image_candidate_list=( "${CHROMEOS_IMAGE_NAME}"
|
||||||
if [ ${FLAGS_test_image} -eq ${FLAGS_FALSE} ]; then
|
|
||||||
# Generation of test image not signaled, look for other images as well.
|
|
||||||
image_candidate_list=( "${image_candidate_list[@]}"
|
|
||||||
"${CHROMEOS_RECOVERY_IMAGE_NAME}"
|
"${CHROMEOS_RECOVERY_IMAGE_NAME}"
|
||||||
"${CHROMEOS_TEST_IMAGE_NAME}"
|
"${CHROMEOS_TEST_IMAGE_NAME}"
|
||||||
"${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"
|
"${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"
|
||||||
"${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}" )
|
"${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}" )
|
||||||
fi
|
unset image_list
|
||||||
unset image_list
|
for image_candidate in "${image_candidate_list[@]}"; do
|
||||||
for image_candidate in "${image_candidate_list[@]}"; do
|
if [ -f "${FLAGS_from}/${image_candidate}" ]; then
|
||||||
if [ -f "${FLAGS_from}/${image_candidate}" ]; then
|
image_list=( "${image_list[@]}" "${image_candidate}" )
|
||||||
image_list=( "${image_list[@]}" "${image_candidate}" )
|
fi
|
||||||
fi
|
done
|
||||||
done
|
|
||||||
|
|
||||||
num_images=${#image_list[*]}
|
num_images=${#image_list[*]}
|
||||||
if (( ${num_images} == 0 )); then
|
if (( ${num_images} == 0 )); then
|
||||||
die "No candidate images could be detected"
|
die "No candidate images could be detected"
|
||||||
elif (( ${num_images} == 1)); then
|
elif (( ${num_images} == 1)); then
|
||||||
image="${image_list}"
|
image="${image_list}"
|
||||||
echo "Found image ${image}"
|
echo "Found image ${image}"
|
||||||
else
|
else
|
||||||
# Select one from a list of available images; default to the first.
|
# Select one from a list of available images; default to the first.
|
||||||
PS3="Select an image [1]: "
|
PS3="Select an image [1]: "
|
||||||
choose image "${image_list}" "ERROR" "${image_list[@]}"
|
choose image "${image_list}" "ERROR" "${image_list[@]}"
|
||||||
if [ "${image}" == "ERROR" ]; then
|
if [ "${image}" == "ERROR" ]; then
|
||||||
die "Invalid selection"
|
die "Invalid selection"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
FLAGS_image_name="${image}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
FLAGS_image_name="${image}"
|
# Use the selected image.
|
||||||
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}"
|
|
||||||
SRC_IMAGE="${CHROMEOS_RETURN_VAL}"
|
|
||||||
else
|
|
||||||
# Use the standard image
|
|
||||||
SRC_IMAGE="${FLAGS_from}/${FLAGS_image_name}"
|
SRC_IMAGE="${FLAGS_from}/${FLAGS_image_name}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Make sure that the selected image exists.
|
||||||
if [ ! -f "${SRC_IMAGE}" ]; then
|
if [ ! -f "${SRC_IMAGE}" ]; then
|
||||||
die "Image not found: ${SRC_IMAGE}"
|
die "Image not found: ${SRC_IMAGE}"
|
||||||
fi
|
fi
|
||||||
|
@ -78,7 +78,7 @@ if [ $FLAGS_inplace -eq $FLAGS_FALSE ]; then
|
|||||||
copy_image $(basename "$FLAGS_image") $(basename "$TEST_PATHNAME")
|
copy_image $(basename "$FLAGS_image") $(basename "$TEST_PATHNAME")
|
||||||
FLAGS_image="$TEST_PATHNAME"
|
FLAGS_image="$TEST_PATHNAME"
|
||||||
else
|
else
|
||||||
echo "Using cached $(basename "$FLAGS_image")"
|
echo "Using cached $(basename "${TEST_PATHNAME}")"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user