mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-22 22:21:10 +02:00
Every consumer that I can find of get_latest_image.sh expects this script to output something useful. Many don't check the result and end up spitting out unhelpful messages when it doesn't. So make a missing images dir fatal for this script so everyone on top of us gets this checking for free. If, in the future, someone actually wants this to output nothing when there's nothing found, we can add a dedicated flag. That mode of operation is a lot less common than having it die by default. BUG=None TEST=delete image tree, run ./get_latest_image.sh --board=${BOARD}, see it fail nicely TEST=delete image tree, run ./image_to_vm.sh --board=${BOARD}, see it fail nicely Change-Id: I0a2ffd0b9084297b6d2346f02dbdb7bd0ef667bf Reviewed-on: https://gerrit.chromium.org/gerrit/15589 Reviewed-by: David James <davidjames@chromium.org> Reviewed-by: Chris Sosa <sosa@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org> Commit-Ready: Mike Frysinger <vapier@chromium.org>
63 lines
1.7 KiB
Bash
Executable File
63 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
# Prints the path to the most recently built image to stdout.
|
|
|
|
# --- BEGIN COMMON.SH BOILERPLATE ---
|
|
# Load common CrOS utilities. Inside the chroot this file is installed in
|
|
# /usr/lib/crosutils. Outside the chroot we find it relative to the script's
|
|
# location.
|
|
find_common_sh() {
|
|
local common_paths=(/usr/lib/crosutils $(dirname "$(readlink -f "$0")"))
|
|
local path
|
|
|
|
SCRIPT_ROOT=
|
|
for path in "${common_paths[@]}"; do
|
|
if [ -r "${path}/common.sh" ]; then
|
|
SCRIPT_ROOT=${path}
|
|
break
|
|
fi
|
|
done
|
|
}
|
|
|
|
find_common_sh
|
|
. "${SCRIPT_ROOT}/common.sh" || { echo "Unable to load common.sh"; exit 1; }
|
|
# --- END COMMON.SH BOILERPLATE ---
|
|
|
|
get_default_board
|
|
|
|
DEFINE_string board "$DEFAULT_BOARD" \
|
|
"The name of the board to check for images."
|
|
|
|
# Parse command line flags
|
|
FLAGS "$@" || exit 1
|
|
eval set -- "${FLAGS_ARGV}"
|
|
|
|
# Check on the board that they are trying to set up.
|
|
if [ -z "$FLAGS_board" ] ; then
|
|
die "Error: --board required."
|
|
fi
|
|
|
|
IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}"
|
|
|
|
# If there are no images, error out since presumably the
|
|
# caller isn't doing this for fun.
|
|
if [[ ! -d ${IMAGES_DIR} ]] ; then
|
|
die "${IMAGES_DIR} does not exist; have you run ./build_image?"
|
|
fi
|
|
|
|
# Use latest link if it exists, otherwise most recently changed dir
|
|
if [ -L ${IMAGES_DIR}/latest ] ; then
|
|
if ! dst=$(readlink "${IMAGES_DIR}"/latest) ; then
|
|
die "Could not read ${IMAGES_DIR}/latest; have you run ./build_image?"
|
|
fi
|
|
DEFAULT_FROM="${IMAGES_DIR}/${dst}"
|
|
else
|
|
DEFAULT_FROM=$(ls -dt "$IMAGES_DIR"/*/ | head -1)
|
|
fi
|
|
|
|
echo $DEFAULT_FROM
|