diff --git a/autotest_lib.sh b/autotest_lib.sh index fe76cb7663..f60382c5c8 100644 --- a/autotest_lib.sh +++ b/autotest_lib.sh @@ -4,7 +4,12 @@ # # Provides common commands for dealing running/building autotest -DEFINE_string board "" "The board for which you are building autotest" +. "$(dirname "$0")/common.sh" + +get_default_board + +DEFINE_string board "$DEFAULT_BOARD" \ + "The board for which you are building autotest" function check_board() { local board_names="" diff --git a/build_autotest.sh b/build_autotest.sh index 24c8eca15d..b5b8ad20fc 100755 --- a/build_autotest.sh +++ b/build_autotest.sh @@ -11,7 +11,7 @@ # The user can later run autotest against an ssh enabled test client system, or # install the compiled client tests directly onto the rootfs image. -. "$(dirname "$0")/common.sh" +# Includes common already . "$(dirname $0)/autotest_lib.sh" # Script must be run inside the chroot diff --git a/common.sh b/common.sh index 419ff48f04..6c97adc2d2 100644 --- a/common.sh +++ b/common.sh @@ -141,6 +141,28 @@ esac # ----------------------------------------------------------------------------- # Functions +function setup_board_warning { + echo + echo "$V_REVERSE================= WARNING ======================$V_VIDOFF" + echo + echo "*** No default board detected in " \ + "$GCLIENT_ROOT/src/scripts/.default_board" + echo "*** Either run setup_board with default flag set" + echo "*** or echo |board_name| > $GCLIENT_ROOT/src/scripts/.default_board" + echo +} + + +# Sets the default board variable for calling script +function get_default_board { + DEFAULT_BOARD= + + if [ -f "$GCLIENT_ROOT/src/scripts/.default_board" ] ; then + DEFAULT_BOARD=`cat "$GCLIENT_ROOT/src/scripts/.default_board"` + fi +} + + # Make a package function make_pkg_common { # Positional parameters from calling script. :? means "fail if unset". diff --git a/image_to_usb.sh b/image_to_usb.sh index c674e2f8fd..b1e533ee49 100755 --- a/image_to_usb.sh +++ b/image_to_usb.sh @@ -10,9 +10,10 @@ # The path to common.sh should be relative to your script's location. . "$(dirname "$0")/common.sh" +get_default_board # Flags -DEFINE_string board "" "Board for which the image was built" +DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built" DEFINE_string from "" \ "Directory containing rootfs.image and mbr.image" DEFINE_string to "" "$DEFAULT_TO_HELP" @@ -38,12 +39,23 @@ fi # Die on any errors. set -e -# If from isn't explicitly set +# No board, no default and no image set then we can't find the image +if [ -z $FLAGS_from ] && [ -z $FLAGS_board ] ; then + setup_board_warning + exit 1 +fi + +# We have a board name but no image set. Use image at default location if [ -z "$FLAGS_from" ]; then IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" FLAGS_from="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)" fi +if [ ! -d "$FLAGS_from" ] ; then + echo "Cannot find image directory $FLAGS_from" + exit 1 +fi + # If to isn't explicitly set if [ -z "$FLAGS_to" ]; then # Script can be run either inside or outside the chroot. diff --git a/mod_image_for_test.sh b/mod_image_for_test.sh index c544732462..e6982a1fc1 100755 --- a/mod_image_for_test.sh +++ b/mod_image_for_test.sh @@ -10,21 +10,34 @@ # The path to common.sh should be relative to your script's location. . "$(dirname "$0")/common.sh" -DEFAULT_BOARD=x86-generic -IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${DEFAULT_BOARD}" -DEFAULT_IMAGE="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)/rootfs.image" +get_default_board DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built" -DEFINE_string image "$DEFAULT_IMAGE" \ - "Location of the rootfs raw image file" +DEFINE_string image "" "Location of the rootfs raw image file" DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" "y" # Parse command line FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" -IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${DEFAULT_BOARD}" -DEFAULT_IMAGE="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)/rootfs.image" +# No board, no default and no image set then we can't find the image +if [ -z $FLAGS_IMAGE ] && [ -z $FLAGS_board ] ; then + setup_board_warning + echo "*** mod_image_for_test failed. No board set and no image set" + exit 1 +fi + +# We have a board name but no image set. Use image at default location +if [ -z $FLAGS_image ] ; then + IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" + FLAGS_image="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)/rootfs.image" +fi + +# Abort early if we can't find the image +if [ ! -f $FLAGS_image ] ; then + echo "No image found at $FLAGS_image" + exit 1 +fi # Make sure anything mounted in the rootfs is cleaned up ok on exit. cleanup_rootfs_mounts() {