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 <keescook@chromium.org>
Reviewed-on: http://gerrit.chromium.org/gerrit/10241
Reviewed-by: David James <davidjames@chromium.org>
This commit is contained in:
Kees Cook 2011-10-18 13:21:41 -07:00 committed by Gerrit
parent fa5b8ff89f
commit 84a4c7a620
2 changed files with 6 additions and 40 deletions

View File

@ -7,26 +7,9 @@
# Script to convert the output of build_image.sh to a VMware image and write a # Script to convert the output of build_image.sh to a VMware image and write a
# corresponding VMware config file. # corresponding VMware config file.
# --- BEGIN COMMON.SH BOILERPLATE --- # Helper scripts should be run from the same location as this script.
# Load common CrOS utilities. Inside the chroot this file is installed in SCRIPT_ROOT=$(dirname "$(readlink -f "$0")")
# /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; } . "${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 # Need to be inside the chroot to load chromeos-common.sh
assert_inside_chroot assert_inside_chroot
@ -103,7 +86,7 @@ fi
IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}"
# Default to the most recent image # Default to the most recent image
if [ -z "${FLAGS_from}" ] ; then 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 else
pushd "${FLAGS_from}" && FLAGS_from=`pwd` && popd pushd "${FLAGS_from}" && FLAGS_from=`pwd` && popd
fi fi

View File

@ -7,26 +7,9 @@
# Helper script that mounts chromium os image from a device or directory # 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). # and creates mount points for /var and /usr/local (if in dev_mode).
# --- BEGIN COMMON.SH BOILERPLATE --- # Helper scripts should be run from the same location as this script.
# Load common CrOS utilities. Inside the chroot this file is installed in SCRIPT_ROOT=$(dirname "$(readlink -f "$0")")
# /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; } . "${SCRIPT_ROOT}/common.sh" || { echo "Unable to load common.sh"; exit 1; }
# --- END COMMON.SH BOILERPLATE ---
if [ $INSIDE_CHROOT -ne 1 ]; then if [ $INSIDE_CHROOT -ne 1 ]; then
INSTALL_ROOT="$SRC_ROOT/platform/installer/" INSTALL_ROOT="$SRC_ROOT/platform/installer/"
@ -194,7 +177,7 @@ function mount_image() {
# Find the last image built on the board. # Find the last image built on the board.
if [ ${FLAGS_most_recent} -eq ${FLAGS_TRUE} ] ; then 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 fi
# Turn paths into absolute paths. # Turn paths into absolute paths.