From 84a4c7a620a070c9f72e09bd3185cf766913a182 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Tue, 18 Oct 2011 13:21:41 -0700 Subject: [PATCH] Use fully qualified path for helpers. Change helper invocation to use discovered script path so image_to_vm.sh and mount_gpt_image.sh can be run outside of ~/trunk/src/scripts. Additionally, minimize SCRIPT_ROOT boilerplate to not potentially mix execution locations, as suggested by David James. BUG=None TEST=Built images from outside of ~/trunk/src/scripts Change-Id: I4851cc74e7da8e08b4e7be79651fb41ce8868aed Signed-off-by: Kees Cook Reviewed-on: http://gerrit.chromium.org/gerrit/10241 Reviewed-by: David James --- image_to_vm.sh | 23 +++-------------------- mount_gpt_image.sh | 23 +++-------------------- 2 files changed, 6 insertions(+), 40 deletions(-) diff --git a/image_to_vm.sh b/image_to_vm.sh index ed360a15f0..cf9804152f 100755 --- a/image_to_vm.sh +++ b/image_to_vm.sh @@ -7,26 +7,9 @@ # Script to convert the output of build_image.sh to a VMware image and write a # corresponding VMware config file. -# --- 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 +# Helper scripts should be run from the same location as this script. +SCRIPT_ROOT=$(dirname "$(readlink -f "$0")") . "${SCRIPT_ROOT}/common.sh" || { echo "Unable to load common.sh"; exit 1; } -# --- END COMMON.SH BOILERPLATE --- # Need to be inside the chroot to load chromeos-common.sh assert_inside_chroot @@ -103,7 +86,7 @@ fi IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" # Default to the most recent image if [ -z "${FLAGS_from}" ] ; then - FLAGS_from="$(./get_latest_image.sh --board=${FLAGS_board})" + FLAGS_from="$(${SCRIPT_ROOT}/get_latest_image.sh --board=${FLAGS_board})" else pushd "${FLAGS_from}" && FLAGS_from=`pwd` && popd fi diff --git a/mount_gpt_image.sh b/mount_gpt_image.sh index fd9eda7a88..368af5c7e1 100755 --- a/mount_gpt_image.sh +++ b/mount_gpt_image.sh @@ -7,26 +7,9 @@ # Helper script that mounts chromium os image from a device or directory # and creates mount points for /var and /usr/local (if in dev_mode). -# --- 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 +# Helper scripts should be run from the same location as this script. +SCRIPT_ROOT=$(dirname "$(readlink -f "$0")") . "${SCRIPT_ROOT}/common.sh" || { echo "Unable to load common.sh"; exit 1; } -# --- END COMMON.SH BOILERPLATE --- if [ $INSIDE_CHROOT -ne 1 ]; then INSTALL_ROOT="$SRC_ROOT/platform/installer/" @@ -194,7 +177,7 @@ function mount_image() { # Find the last image built on the board. if [ ${FLAGS_most_recent} -eq ${FLAGS_TRUE} ] ; then - FLAGS_from="$(./get_latest_image.sh --board="${FLAGS_board}")" + FLAGS_from="$(${SCRIPT_ROOT}/get_latest_image.sh --board="${FLAGS_board}")" fi # Turn paths into absolute paths.