mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-22 22:21:10 +02:00
image_to_usb.sh: prompt when detected image is not the default image.
Having introduced autodetection and autoselection of images, some users may be surprised to find that the script will happily choose to copy an image other than chromiumos_image.bin when only one image is present. Since this is substantially different from the previous behavior, we now present a menu (with a single choice) in this case as well. Also fixing the list of images to be detected and properly prioritizing a default image over others. The code should already work with the future image naming scheme, where chromiumos_image.bin will be a symlink to one of six concrete images (with unique names). BUG=None TEST=Ran script with different image configurations and flags. Change-Id: I5d448c5425754496d256258281694cd7ec2554d2 Reviewed-on: https://gerrit.chromium.org/gerrit/15982 Commit-Ready: Gilad Arnold <garnold@chromium.org> Reviewed-by: Gilad Arnold <garnold@chromium.org> Tested-by: Gilad Arnold <garnold@chromium.org>
This commit is contained in:
parent
fe8601bb51
commit
a829f3392f
@ -255,29 +255,48 @@ else
|
||||
if [ -z "${FLAGS_image_name}" ]; then
|
||||
echo "No image name specified, autodetecting..."
|
||||
|
||||
# Obtain list of available images that can be used.
|
||||
image_candidate_list=( "${CHROMEOS_IMAGE_NAME}"
|
||||
# Resolve the default image full path (see though symlinks), make sure
|
||||
# it's present.
|
||||
default_image_path=$(readlink -f "${FLAGS_from}/${CHROMEOS_IMAGE_NAME}")
|
||||
if [ ! -f "${default_image_path}" ]; then
|
||||
default_image_path="MISSING"
|
||||
fi
|
||||
|
||||
# The list of candidate image names.
|
||||
image_candidate_list=( "${CHROMEOS_DEVELOPER_IMAGE_NAME}"
|
||||
"${CHROMEOS_RECOVERY_IMAGE_NAME}"
|
||||
"${CHROMEOS_TEST_IMAGE_NAME}"
|
||||
"${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"
|
||||
"${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}" )
|
||||
|
||||
# Obtain list of available images that can be used.
|
||||
unset image_list
|
||||
is_got_default=0
|
||||
for image_candidate in "${image_candidate_list[@]}"; do
|
||||
if [ -f "${FLAGS_from}/${image_candidate}" ]; then
|
||||
image_list=( "${image_list[@]}" "${image_candidate}" )
|
||||
image_candidate_path="${FLAGS_from}/${image_candidate}"
|
||||
if [ -f "${image_candidate_path}" ]; then
|
||||
if [ "${image_candidate_path}" == "${default_image_path}" ]; then
|
||||
# This is the default image, list it first.
|
||||
image_list=( "${image_candidate}" "${image_list[@]}" )
|
||||
is_got_default=1
|
||||
else
|
||||
image_list=( "${image_list[@]}" "${image_candidate}" )
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
num_images=${#image_list[*]}
|
||||
if (( ${num_images} == 0 )); then
|
||||
# Figure out what to do with the resulting list of images.
|
||||
declare -i num_images=${#image_list[*]}
|
||||
if (( num_images == 0 )); then
|
||||
die "No candidate images could be detected"
|
||||
elif (( ${num_images} == 1)); then
|
||||
image="${image_list}"
|
||||
echo "Found image ${image}"
|
||||
elif (( num_images == 1 )) && [ ${is_got_default} == 1 ]; then
|
||||
# Found a single image that is the default image, just select it.
|
||||
image="${image_list[0]}"
|
||||
echo "Found default image ${image}"
|
||||
else
|
||||
# Select one from a list of available images; default to the first.
|
||||
PS3="Select an image [1]: "
|
||||
choose image "${image_list}" "ERROR" "${image_list[@]}"
|
||||
choose image "${image_list[0]}" "ERROR" "${image_list[@]}"
|
||||
if [ "${image}" == "ERROR" ]; then
|
||||
die "Invalid selection"
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user