diff --git a/archive_build.sh b/archive_build.sh index 233540a627..ff2be62ce7 100755 --- a/archive_build.sh +++ b/archive_build.sh @@ -6,9 +6,26 @@ # Script to archive build results. Used by the buildbots. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" +# --- 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 --- # Script must be run outside the chroot assert_outside_chroot @@ -43,7 +60,8 @@ DEFINE_string acl "private" \ DEFINE_string gsutil_archive "" \ "Optional datastore archive location" DEFINE_integer keep_max 0 "Maximum builds to keep in archive (0=all)" -DEFINE_boolean official_build $FLAGS_FALSE "Set CHROMEOS_OFFICIAL=1 for release builds." +DEFINE_boolean official_build $FLAGS_FALSE \ + "Set CHROMEOS_OFFICIAL=1 for release builds." DEFINE_boolean test_mod $FLAGS_TRUE "Modify image for testing purposes" DEFINE_boolean prebuilt_upload $FLAGS_FALSE "Upload prebuilt binary packages." DEFINE_string to "$DEFAULT_TO" "Directory of build archive" @@ -57,8 +75,7 @@ eval set -- "${FLAGS_ARGV}" DEFAULT_USED= # Reset "default" FLAGS_from based on passed-in board if not set on cmd-line -if [ "$FLAGS_from" = "$DEFAULT_FROM" ] -then +if [ "$FLAGS_from" = "$DEFAULT_FROM" ]; then # Keep the directory name of the current image set (*.bin). IMG_DIR="$(readlink ${IMAGES_DIR}/${FLAGS_board}/latest)" FLAGS_from="${IMAGES_DIR}/${FLAGS_board}/${IMG_DIR}" @@ -68,8 +85,7 @@ fi # Die on any errors. set -e -if [ -z "$DEFAULT_USED" ] -then +if [ -z "$DEFAULT_USED" ]; then if [ $FLAGS_test_mod -eq $FLAGS_TRUE ] || \ [ $FLAGS_factory_install_mod -eq $FLAGS_TRUE ] || \ [ $FLAGS_factory_test_mod -eq $FLAGS_TRUE ] @@ -81,14 +97,12 @@ then fi fi -if [ ! -d "$FLAGS_from" ] -then +if [ ! -d "$FLAGS_from" ]; then echo "$FLAGS_from does not exist. Exiting..." exit 1 fi -if [ $FLAGS_official_build -eq $FLAGS_TRUE ] -then +if [ $FLAGS_official_build -eq $FLAGS_TRUE ]; then CHROMEOS_OFFICIAL=1 fi @@ -103,8 +117,7 @@ REVISION=${REVISION:0:8} # Use the version number plus revision as the last change. (Need both, since # trunk builds multiple times with the same version string.) LAST_CHANGE="${CHROMEOS_VERSION_STRING}-r${REVISION}" -if [ -n "$FLAGS_build_number" ] -then +if [ -n "$FLAGS_build_number" ]; then LAST_CHANGE="$LAST_CHANGE-b${FLAGS_build_number}" fi @@ -141,8 +154,7 @@ function do_chroot_mod() { } # Modify image for test if flag set. -if [ $FLAGS_test_mod -eq $FLAGS_TRUE ] -then +if [ $FLAGS_test_mod -eq $FLAGS_TRUE ]; then echo "Modifying image for test" do_chroot_mod "${FLAGS_from}/chromiumos_test_image.bin" "" @@ -152,16 +164,14 @@ then popd fi -if [ $FLAGS_factory_test_mod -eq $FLAGS_TRUE ] -then +if [ $FLAGS_factory_test_mod -eq $FLAGS_TRUE ]; then echo "Modifying image for factory test" do_chroot_mod "${FLAGS_from}/chromiumos_factory_image.bin" \ "--factory" fi # Modify for recovery -if [ $FLAGS_official_build -eq $FLAGS_TRUE ] -then +if [ $FLAGS_official_build -eq $FLAGS_TRUE ]; then BUILDVER="$(readlink ${IMAGES_DIR}/${FLAGS_board}/latest)" CHROOT_IMAGE_DIR=/home/$USER/trunk/src/build/images/$FLAGS_board/$BUILDVER ./enter_chroot.sh -- ./mod_image_for_recovery.sh --board $FLAGS_board \ @@ -175,8 +185,7 @@ fi # Build differently sized shims. Currently only factory install shim is # supported, TODO(tgao): Add developer shim. -if [ $FLAGS_factory_install_mod -eq $FLAGS_TRUE ] -then +if [ $FLAGS_factory_install_mod -eq $FLAGS_TRUE ]; then echo "Building factory install shim." # HACK: The build system can't currently handle more than one image size # at a time. Therefor eit's necessary to do another round of build after @@ -205,8 +214,7 @@ MANIFEST=`ls | grep -v factory` zip -r "${ZIPFILE}" ${MANIFEST} if [ $FLAGS_factory_test_mod -eq $FLAGS_TRUE ] || \ - [ $FLAGS_factory_install_mod -eq $FLAGS_TRUE ] -then + [ $FLAGS_factory_install_mod -eq $FLAGS_TRUE ]; then # We need to have directory structure for factory package, as # signing and packaging utilities need unpack_partitions.sh. echo "Compressing factory software" @@ -268,8 +276,7 @@ then fi -if [ $FLAGS_prebuilt_upload -eq $FLAGS_TRUE ] -then +if [ $FLAGS_prebuilt_upload -eq $FLAGS_TRUE ]; then # Construct prebuilt upload command. # This will upload prebuilt packages to Google Storage. prebuilt_cmd="${SCRIPTS_DIR}/prebuilt.py" @@ -287,8 +294,7 @@ fi gsutil_archive "${ZIPFILE}" "${LAST_CHANGE}/${FLAGS_zipname}" -if [ $FLAGS_archive_debug -eq $FLAGS_TRUE ] -then +if [ $FLAGS_archive_debug -eq $FLAGS_TRUE ]; then echo "Generating Breakpad symbols" ! ${SCRIPTS_DIR}/cros_generate_breakpad_symbols --board=${FLAGS_board} echo "Creating debug archive" @@ -302,16 +308,14 @@ then fi if [ $FLAGS_factory_test_mod -eq $FLAGS_TRUE ] || \ - [ $FLAGS_factory_install_mod -eq $FLAGS_TRUE ] -then + [ $FLAGS_factory_install_mod -eq $FLAGS_TRUE ]; then gsutil_archive "${FACTORY_ZIPFILE}" \ "${LAST_CHANGE}/factory_${FLAGS_zipname}" fi gsutil_archive "${FLAGS_to}/LATEST" "LATEST" # Purge old builds if necessary -if [ $FLAGS_keep_max -gt 0 ] -then +if [ $FLAGS_keep_max -gt 0 ]; then echo "Deleting old builds (all but the newest ${FLAGS_keep_max})..." cd "$FLAGS_to" # +2 because line numbers start at 1 and need to skip LATEST file diff --git a/archive_hwqual b/archive_hwqual index 6ce823726b..1bc91a8395 100755 --- a/archive_hwqual +++ b/archive_hwqual @@ -6,9 +6,26 @@ # Script to take an archived build result and prepare a hwqual release. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" +# --- 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 --- # Flags DEFINE_string from "" "Directory with build archive (zipname)" @@ -42,7 +59,7 @@ function main() { FLAGS_to="${FLAGS_from}" fi - local script_dir=$(dirname "$0") + local script_dir=${SCRIPTS_DIR} script_dir=$(readlink -f "${script_dir}") docgen_dir="autotest/utils/docgen" diff --git a/bin/cros_get_chrome_version b/bin/cros_get_chrome_version index a29cb3275f..938b57a681 100755 --- a/bin/cros_get_chrome_version +++ b/bin/cros_get_chrome_version @@ -6,8 +6,28 @@ # Returns the version of Chrome running on a remote machine. -. "$(dirname $0)/../common.sh" -. "$(dirname $0)/../remote_access.sh" +# --- 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 --- + +. "${SCRIPT_ROOT}/remote_access.sh" || die "Unable to load remote_access.sh" FLAGS "$@" || exit 1 diff --git a/bin/cros_make_image_bootable b/bin/cros_make_image_bootable index d5644916b8..c1a2d0e2b5 100755 --- a/bin/cros_make_image_bootable +++ b/bin/cros_make_image_bootable @@ -7,21 +7,35 @@ # Script which ensures that a given image has an up-to-date # kernel partition, rootfs integrity hashes, and legacy bootloader configs. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -COMMON_PATH="$(dirname "$0")/../common.sh" -if [ ! -r "${COMMON_PATH}" ]; then - echo "ERROR! Cannot find common.sh: ${COMMON_PATH}" 1>&2 - exit 1 -fi +# --- 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 -. "$(dirname "$0")/../common.sh" + SCRIPT_ROOT= + for path in "${common_paths[@]}"; do + if [ -r "${path}/common.sh" ]; then + SCRIPT_ROOT=${path} + break + fi + done +} -# Script must be run inside the chroot. +find_common_sh +. "${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 +# Load functions and constants for chromeos-install +. "/usr/lib/installer/chromeos-common.sh" || \ + die "Unable to load /usr/lib/installer/chromeos-common.sh" + set -e -. "$(dirname "$0")/../chromeos-common.sh" # for partoffset and partsize if [ $# -lt 2 ]; then echo "Usage: ${0} /PATH/TO/IMAGE IMAGE.BIN [shflags overrides]" @@ -41,7 +55,7 @@ if [ ! -r "${BOOT_DESC_FILE}" ]; then BOOT_DESC="${@}" else BOOT_DESC="$(cat ${BOOT_DESC_FILE} | tr -s '\n' ' ')" - info "Boot-time configuration for $(dirname ${IMAGE}): " + info "Boot-time configuration for $(dirname "${IMAGE}"): " cat ${BOOT_DESC_FILE} | while read line; do info " ${line}" done @@ -138,7 +152,7 @@ make_image_bootable() { fi trap "mount_gpt_cleanup" EXIT - ${SCRIPTS_DIR}/mount_gpt_image.sh --from "$(dirname ${image})" \ + "${SCRIPTS_DIR}/mount_gpt_image.sh" --from "$(dirname "${image}")" \ --image "$(basename ${image})" -r "${FLAGS_rootfs_mountpoint}" \ -s "${FLAGS_statefulfs_mountpoint}" diff --git a/bin/cros_overlay_list b/bin/cros_overlay_list index 7031068261..238f0974ea 100755 --- a/bin/cros_overlay_list +++ b/bin/cros_overlay_list @@ -6,24 +6,26 @@ # This script generates the list of board overlays and variants. +# --- 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 scripts +# /usr/lib/crosutils. Outside the chroot we find it relative to the script's # location. -common_paths="/usr/lib/crosutils $(dirname "$0")/.." +find_common_sh() { + local common_paths=(/usr/lib/crosutils "$(dirname "$(readlink -f "$0")")/..") + local path -for path in ${common_paths} ; do - if [ -f "${path}/common.sh" ] ; then - COMMON_SH="${path}/common.sh" - break - fi -done + SCRIPT_ROOT= + for path in "${common_paths[@]}"; do + if [ -r "${path}/common.sh" ]; then + SCRIPT_ROOT=${path} + break + fi + done +} -if [ -z "${COMMON_SH}" ] ; then - error "common.sh not found in search path (${common_paths})" - exit 1 -fi - -. "${COMMON_SH}" +find_common_sh +. "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1) +# --- END COMMON.SH BOILERPLATE --- get_default_board diff --git a/bin/cros_package_to_live b/bin/cros_package_to_live index 699bf237c4..2430333c36 100755 --- a/bin/cros_package_to_live +++ b/bin/cros_package_to_live @@ -7,16 +7,28 @@ # Script to update a running device with an optionally built package out # of your build directory -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. +# --- 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=$(dirname $0) -if [ -f ${script_root}/../common.sh ] ; then - script_root=${script_root}/.. -fi + SCRIPT_ROOT= + for path in "${common_paths[@]}"; do + if [ -r "${path}/common.sh" ]; then + SCRIPT_ROOT=${path} + break + fi + done +} -. "${script_root}/common.sh" -. "${script_root}/remote_access.sh" +find_common_sh +. "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1) +# --- END COMMON.SH BOILERPLATE --- + +. "${SCRIPT_ROOT}/remote_access.sh" || die "Unable to load remote_access.sh" get_default_board @@ -89,8 +101,8 @@ for pkg in $@; do echo "Could not find latest built version of ${pkg}" exit 1 fi - pkg_dir=$(basename $(dirname $latest_pkg)) - pkg_name=$(basename $latest_pkg) + pkg_dir=$(basename "$(dirname "$latest_pkg")") + pkg_name=$(basename "$latest_pkg") echo "Installing ${latest_pkg}..." remote_sh "mktemp -d /tmp/cros_package_to_live.XXXX" diff --git a/bin/cros_resign_image.sh b/bin/cros_resign_image.sh index d6709ef20e..3d5e6a85eb 100755 --- a/bin/cros_resign_image.sh +++ b/bin/cros_resign_image.sh @@ -7,11 +7,33 @@ # Script to resign the kernel partition generated in the output of build_image # with keys of our choosing. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/../common.sh" +# --- 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 -. "$(dirname "$0")/../chromeos-common.sh" # for partoffset and partsize + 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 --- + +# Need to be inside the chroot to load chromeos-common.sh +assert_inside_chroot + +# Load functions and constants for chromeos-install +. "/usr/lib/installer/chromeos-common.sh" || \ + die "Unable to load /usr/lib/installer/chromeos-common.sh" locate_gpt diff --git a/bin/cros_revert_image.sh b/bin/cros_revert_image.sh index 5810af836c..c47f38bf22 100755 --- a/bin/cros_revert_image.sh +++ b/bin/cros_revert_image.sh @@ -1,4 +1,7 @@ #!/bin/bash +# Copyright (c) 2011 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. # Usage: # revert_image.sh [image_to_revert] @@ -6,7 +9,7 @@ # This assumes the image has been updated by update_image.sh. usage() { -cat < + if [ $INSIDE_CHROOT -ne 1 ]; then + local abspath=$(readlink -f "$0") + # strip everything up to (and including) /scripts/ from abspath + local path_from_scripts="${abspath##*/scripts/}" exec $SCRIPTS_DIR/enter_chroot.sh -- \ - $CHROOT_TRUNK_DIR/src/scripts/$(basename $0) "$@" + "$CHROOT_TRUNK_DIR/src/scripts/$path_from_scripts" "$@" fi } # Fail unless we're inside the chroot. This guards against messing up your # workstation. function assert_inside_chroot { - if [ $INSIDE_CHROOT -ne 1 ] - then + if [ $INSIDE_CHROOT -ne 1 ]; then echo "This script must be run inside the chroot. Run this first:" echo " $SCRIPTS_DIR/enter_chroot.sh" exit 1 @@ -312,33 +312,19 @@ function assert_inside_chroot { # Fail if we're inside the chroot. This guards against creating or entering # nested chroots, among other potential problems. function assert_outside_chroot { - if [ $INSIDE_CHROOT -ne 0 ] - then + if [ $INSIDE_CHROOT -ne 0 ]; then echo "This script must be run outside the chroot." exit 1 fi } function assert_not_root_user { - if [ `id -u` = 0 ]; then + if [ $(id -u) = 0 ]; then echo "This script must be run as a non-root user." exit 1 fi } -# Install a package if it's not already installed -function install_if_missing { - # Positional parameters from calling script. :? means "fail if unset". - PKG_NAME=${1:?} - shift - - if [ -z `which $PKG_NAME` ] - then - echo "Can't find $PKG_NAME; attempting to install it." - sudo apt-get --yes --force-yes install $PKG_NAME - fi -} - # Returns true if the input file is whitelisted. # # $1 - The file to check @@ -402,12 +388,12 @@ function die { # Retry an emerge command according to $FLAGS_retries # The $EMERGE_JOBS flags will only be added the first time the command is run function eretry () { - local i= + local i for i in $(seq $FLAGS_retries); do - echo Retrying $* - $* $EMERGE_JOBS && return 0 + echo "Retrying $@" + "$@" $EMERGE_JOBS && return 0 done - $* && return 0 + "$@" && return 0 return 1 } @@ -455,6 +441,7 @@ function safe_umount { fix_broken_symlinks() { local build_root="${1}" local symlinks=$(find "${build_root}/usr/local" -lname "${build_root}/*") + local symlink for symlink in ${symlinks}; do echo "Fixing ${symlink}" local target=$(ls -l "${symlink}" | cut -f 2 -d '>') @@ -491,6 +478,7 @@ setup_symlinks_on_root() { fi # Set up symlinks that should point to ${dev_image_target}. + local path for path in usr local; do if [ -h "${dev_image_root}/${path}" ]; then sudo unlink "${dev_image_root}/${path}" @@ -556,10 +544,10 @@ start_time=$(date +%s) # Print time elsapsed since start_time. print_time_elapsed() { - end_time=$(date +%s) - elapsed_seconds="$(( $end_time - $start_time ))" - minutes="$(( $elapsed_seconds / 60 ))" - seconds="$(( $elapsed_seconds % 60 ))" + local end_time=$(date +%s) + local elapsed_seconds=$(($end_time - $start_time)) + local minutes=$(($elapsed_seconds / 60)) + local seconds=$(($elapsed_seconds % 60)) echo "Elapsed time: ${minutes}m${seconds}s" } @@ -574,7 +562,7 @@ print_time_elapsed() { # ${1} specifies the location of the chroot. chroot_hacks_from_outside() { # Give args better names. - local chroot_dir="${1}" + local chroot_dir=$1 # Add root as a sudoer if not already done. if ! sudo grep -q '^root ALL=(ALL) ALL$' "${chroot_dir}/etc/sudoers" ; then diff --git a/create_esp.sh b/create_esp.sh index 261b8de340..26f4b2ed91 100755 --- a/create_esp.sh +++ b/create_esp.sh @@ -6,7 +6,26 @@ # Creates an empty ESP image. -. "$(dirname "$0")/common.sh" +# --- 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 diff --git a/create_legacy_bootloader_templates.sh b/create_legacy_bootloader_templates.sh index 8bfa761617..314363775d 100755 --- a/create_legacy_bootloader_templates.sh +++ b/create_legacy_bootloader_templates.sh @@ -6,7 +6,26 @@ # Helper script that generates the signed kernel image -. "$(dirname "$0")/common.sh" +# --- 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 diff --git a/cros_download_latest_image b/cros_download_latest_image index b3abaf8004..1ef56caad2 100755 --- a/cros_download_latest_image +++ b/cros_download_latest_image @@ -7,9 +7,26 @@ # Downloads the latest buildbot image and prints the path to it. # This script only works if you have access to buildbot images. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" +# --- 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 diff --git a/cros_generate_breakpad_symbols b/cros_generate_breakpad_symbols index 8bfe8792c8..0e10cbc6e7 100755 --- a/cros_generate_breakpad_symbols +++ b/cros_generate_breakpad_symbols @@ -9,12 +9,29 @@ # NOTE: This script must be run from the chromeos build chroot environment. # -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" +# --- 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 --- # Script must be run inside the chroot -restart_in_chroot_if_needed $* +restart_in_chroot_if_needed "$@" get_default_board @@ -39,7 +56,7 @@ function cleanup() { # Given path to a debug file, return its text file function get_text_for_debug() { local debug_file=$1 - local text_dir=$(dirname ${debug_file#$DEBUG_ROOT}) + local text_dir=$(dirname "${debug_file#$DEBUG_ROOT}") local text_path=${SYSROOT}${text_dir}/$(basename "${debug_file}" .debug) echo ${text_path} } diff --git a/cros_generate_update_payload b/cros_generate_update_payload index 384e27714f..b55f438526 100755 --- a/cros_generate_update_payload +++ b/cros_generate_update_payload @@ -7,12 +7,33 @@ # Script to generate a Chromium OS update for use by the update engine. # If a source .bin is specified, the update is assumed to be a delta update. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" +# --- 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 --- + +# Need to be inside the chroot to load chromeos-common.sh +assert_inside_chroot # Load functions and constants for chromeos-install -. "$(dirname "$0")/chromeos-common.sh" +. "/usr/lib/installer/chromeos-common.sh" || \ + die "Unable to load /usr/lib/installer/chromeos-common.sh" SRC_MNT="" DST_MNT="" @@ -233,7 +254,7 @@ else fi DST_ROOT=$(extract_partition_to_temp_file "$FLAGS_image" 3) - GENERATOR="$(dirname "$0")/mk_memento_images.sh" + GENERATOR="${SCRIPTS_DIR}/mk_memento_images.sh" CROS_GENERATE_UPDATE_PAYLOAD_CALLED=1 "$GENERATOR" "$DST_KERNEL" "$DST_ROOT" mv "$(dirname "$DST_KERNEL")/update.gz" "$FLAGS_output" diff --git a/cros_mark_branch_as_stable b/cros_mark_branch_as_stable index a2dfd7a693..e538235419 100755 --- a/cros_mark_branch_as_stable +++ b/cros_mark_branch_as_stable @@ -27,9 +27,26 @@ # # Example usage: ./cros_mark_branch_as_stable -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" +# --- 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 --- function is_workon() { xargs grep -lE '^inherit.*cros-workon'; } function is_stable() { xargs grep -lE '^KEYWORDS=[^~]*$'; } @@ -38,8 +55,8 @@ function is_unstable() { xargs grep -lE '^KEYWORDS=.*~'; } function get_workon_commit() { # Get the latest workon commit associated with an ebuild. ebuild="$1" - dir=$(dirname $ebuild) - CATEGORY=$(basename $(dirname "$dir")) + dir=$(dirname "$ebuild") + CATEGORY=$(basename "$(dirname "$dir")") CROS_WORKON_LOCALNAME=$(basename "$dir") CROS_WORKON_SUBDIR= @@ -65,7 +82,7 @@ function get_workon_commit() { cd $SRCDIR && git rev-parse HEAD } -BLACKLIST_FILE=$(dirname "$0")/cros_mark_as_stable_blacklist +BLACKLIST_FILE="${SCRIPTS_DIR}/cros_mark_as_stable_blacklist" BLACKLIST=$(cat "$BLACKLIST_FILE") if [[ -n "$BLACKLIST" ]]; then die "$0 does not support cros_mark_as_stable_blacklist" diff --git a/cros_run_unit_tests b/cros_run_unit_tests index 3206f0c706..54a0297702 100755 --- a/cros_run_unit_tests +++ b/cros_run_unit_tests @@ -10,7 +10,26 @@ # This script requires that you run build_packages first. -. "$(dirname "$0")/common.sh" +# --- 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 @@ -76,7 +95,7 @@ if [ -z "${FLAGS_package_file}" -a -z "${FLAGS_packages}" ]; then egrep '^chromeos-base' ) fi -BLACK_LIST_FILE="$(dirname "$0")/unit_test_black_list.txt" +BLACK_LIST_FILE="${SCRIPTS_DIR}/unit_test_black_list.txt" if [ "${FLAGS_withdebug}" -eq "${FLAGS_FALSE}" ]; then export USE="${USE} -cros-debug" diff --git a/cros_show_stacks b/cros_show_stacks index fa6b769321..be2eb25e89 100755 --- a/cros_show_stacks +++ b/cros_show_stacks @@ -6,11 +6,28 @@ # Script to generate stackdumps from a machine or dmp files. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. +# --- 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 -. "$(dirname $0)/common.sh" -. "$(dirname $0)/remote_access.sh" + 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 --- + +. "${SCRIPT_ROOT}/remote_access.sh" || die "Unable to load remote_access.sh" assert_inside_chroot diff --git a/cros_workon b/cros_workon index 5d890bd488..0d9c9189d8 100755 --- a/cros_workon +++ b/cros_workon @@ -10,12 +10,29 @@ # is intended to support development. The current source tip is fetched, # source modified and built using the unstable 'live' (9999) ebuild. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" +# --- 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 --- # Script must be run inside the chroot -restart_in_chroot_if_needed $* +restart_in_chroot_if_needed "$@" get_default_board DEFINE_string board "${DEFAULT_BOARD}" \ @@ -42,7 +59,6 @@ eval set -- "${FLAGS_ARGV}" WORKON_CMD=$1 shift - # Board dir config # If both are specified, just use host, because board does not @@ -98,7 +114,8 @@ if [ ! -L "${UNMASK_FILE}" ]; then fi find_keyword_workon_ebuilds() { - keyword="${1}" + local keyword="${1}" + local overlay local cros_overlays=$("${PORTAGEQCMD}" envvar PORTDIR_OVERLAY) @@ -112,7 +129,7 @@ find_keyword_workon_ebuilds() { } show_workon_ebuilds() { - keyword=$1 + local keyword=$1 find_keyword_workon_ebuilds ${keyword} | \ sed -e 's/.*\/\([^/]*\)\/\([^/]*\)\/.*\.ebuild/\1\/\2/' | \ @@ -150,6 +167,7 @@ canonicalize_name () { canonicalize_names () { local atoms=$1 local names="" + local atom for atom in ${atoms}; do local name=$(canonicalize_name "${atom}") @@ -168,6 +186,7 @@ show_live_ebuilds () { # Display ebuilds currently part of the live branch and open for development # for any board that currently has live ebuilds. show_all_live_ebuilds () { + local workon_file for workon_file in ${WORKON_DIR}/*; do if [ -s "${workon_file}" ]; then echo -e "${V_BOLD_GREEN}$(basename ${workon_file}):${V_VIDOFF}" @@ -177,7 +196,10 @@ show_all_live_ebuilds () { done } -# This is called only for "cros-workon start". We dont handle the "stop" case since the local changes are ignored anyway since the 9999.ebuild is masked and we dont want to deal with what to do with the user's local changes. +# This is called only for "cros-workon start". We dont handle the +# "stop" case since the local changes are ignored anyway since the +# 9999.ebuild is masked and we dont want to deal with what to do with +# the user's local changes. regen_manifest_and_sync() { # Nothing to do unless you are working on the minilayout local manifest=${CHROOT_TRUNK_DIR}/.repo/manifest.xml @@ -185,6 +207,7 @@ regen_manifest_and_sync() { return fi + local pkgname for pkgname in $(show_live_ebuilds); do eval $(${EBUILDCMD} $(${EQUERYCMD} which ${pkgname}) info) local srcdir=$(readlink -m ${CROS_WORKON_SRCDIR}) @@ -201,6 +224,7 @@ regen_manifest_and_sync() { ebuild_to_live () { local atoms=$1 local atoms_success="" + local atom for atom in ${atoms}; do if ! grep -qx "=${atom}-9999" "${WORKON_FILE}" ; then @@ -219,6 +243,7 @@ ebuild_to_live () { ebuild_to_stable () { local atoms=$1 local atoms_success="" + local atom for atom in ${atoms}; do if grep -qx "=${atom}-9999" "${WORKON_FILE}" ; then @@ -236,6 +261,7 @@ ebuild_to_stable () { # Run a command on all or a set of repos. ebuild_iterate() { local atoms=$1 + local atom for atom in ${atoms}; do info "Running \"${FLAGS_command}\" on ${atom}" @@ -249,7 +275,7 @@ if [ ${FLAGS_all} = "${FLAGS_TRUE}" ]; then case ${WORKON_CMD} in start) ATOM_LIST=$(show_workon_ebuilds ${BOARD_KEYWORD});; stop|iterate) ATOM_LIST=$(show_live_ebuilds);; - list|list-all) ;; + list) ;; *) die "--all is invalid for the given command";; esac else # not selected --all @@ -266,10 +292,11 @@ else # not selected --all fi case ${WORKON_CMD} in - start) ebuild_to_live "${ATOM_LIST}" ;; - stop) ebuild_to_stable "${ATOM_LIST}" ;; - list) [ ${FLAGS_all} = "${FLAGS_FALSE}" ] && show_live_ebuilds || show_workon_ebuilds ${BOARD_KEYWORD} ;; + start) ebuild_to_live "${ATOM_LIST}" ;; + stop) ebuild_to_stable "${ATOM_LIST}" ;; + list) [ ${FLAGS_all} = "${FLAGS_FALSE}" ] && show_live_ebuilds || \ + show_workon_ebuilds ${BOARD_KEYWORD} ;; list-all) show_all_live_ebuilds ;; - iterate)ebuild_iterate "${ATOM_LIST}" ;; + iterate) ebuild_iterate "${ATOM_LIST}" ;; *) die "$(basename $0): command '${WORKON_CMD}' not recognized" ;; esac diff --git a/emit_gpt_scripts.sh b/emit_gpt_scripts.sh index 692e836ef8..f57899ce67 100755 --- a/emit_gpt_scripts.sh +++ b/emit_gpt_scripts.sh @@ -5,10 +5,33 @@ # # Emit scripts to pack and unpack the partitions from a GPT disk image. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" -. "$(dirname "$0")/chromeos-common.sh" +# --- 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 --- + +# Need to be inside the chroot to load chromeos-common.sh +assert_inside_chroot + +# Load functions and constants for chromeos-install +. "/usr/lib/installer/chromeos-common.sh" || \ + die "Unable to load /usr/lib/installer/chromeos-common.sh" set -e diff --git a/enable_localaccount.sh b/enable_localaccount.sh index 3590d7adec..2232551977 100755 --- a/enable_localaccount.sh +++ b/enable_localaccount.sh @@ -4,8 +4,7 @@ # found in the LICENSE file. set -e -if [ -z $1 ] -then +if [ -z $1 ]; then echo "Usage: $0 localaccount_username [chroot_path]" exit 1 fi diff --git a/enter_chroot.sh b/enter_chroot.sh index 7679d9c5ec..669cdacb78 100755 --- a/enter_chroot.sh +++ b/enter_chroot.sh @@ -6,9 +6,26 @@ # Script to enter the chroot environment -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" +# --- 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 --- # Script must be run outside the chroot and as a regular user. assert_outside_chroot @@ -87,8 +104,7 @@ eval set -- "${_FLAGS_FIXED}" FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" -if [ $FLAGS_official_build -eq $FLAGS_TRUE ] -then +if [ $FLAGS_official_build -eq $FLAGS_TRUE ]; then CHROMEOS_OFFICIAL=1 fi @@ -117,31 +133,26 @@ function setup_env { # Mount only if not already mounted MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" - if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] - then + if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then sudo mount none -t proc "$MOUNTED_PATH" || \ die "Could not mount $MOUNTED_PATH" fi MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/sys")" - if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] - then + if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then sudo mount none -t sysfs "$MOUNTED_PATH" || \ die "Could not mount $MOUNTED_PATH" fi MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev")" - if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] - then + if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then sudo mount --bind /dev "$MOUNTED_PATH" || \ die "Could not mount $MOUNTED_PATH" fi if [ $FLAGS_ssh_agent -eq $FLAGS_TRUE ]; then TARGET_DIR="$(readlink -f "${FLAGS_chroot}/home/${USER}/.ssh")" - if [ -n "${SSH_AUTH_SOCK}" \ - -a -d "${HOME}/.ssh" ] - then + if [ -n "${SSH_AUTH_SOCK}" -a -d "${HOME}/.ssh" ]; then mkdir -p "${TARGET_DIR}" cp -r "${HOME}/.ssh/known_hosts" "${TARGET_DIR}" cp -r "${HOME}/.ssh/config" "${TARGET_DIR}" @@ -153,22 +164,19 @@ function setup_env { fi MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev/pts")" - if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] - then + if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then sudo mount none -t devpts "$MOUNTED_PATH" || \ die "Could not mount $MOUNTED_PATH" fi MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}$CHROOT_TRUNK_DIR")" - if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] - then + if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then sudo mount --bind "$FLAGS_trunk" "$MOUNTED_PATH" || \ die "Could not mount $MOUNTED_PATH" fi MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")" - if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] - then + if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")" if [ -z "$CHROME_ROOT" ]; then ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \ @@ -188,11 +196,10 @@ function setup_env { fi MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")" - if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] - then + if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then if [ $(which gclient 2>/dev/null) ]; then info "Mounting depot_tools" - DEPOT_TOOLS=$(dirname $(which gclient) ) + DEPOT_TOOLS=$(dirname "$(which gclient)") mkdir -p "$MOUNTED_PATH" if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then warn "depot_tools failed to mount; perhaps it's on NFS?" @@ -202,7 +209,7 @@ function setup_env { fi # Install fuse module. - if [ -c "${FUSE_DEVICE}" ] ; then + if [ -c "${FUSE_DEVICE}" ]; then sudo modprobe fuse 2> /dev/null ||\ warn "-- Note: modprobe fuse failed. gmergefs will not work" fi @@ -271,8 +278,7 @@ function teardown_env { ) 200>>"$LOCKFILE" || die "teardown_env failed" } -if [ $FLAGS_mount -eq $FLAGS_TRUE ] -then +if [ $FLAGS_mount -eq $FLAGS_TRUE ]; then setup_env info "Make sure you run" info " $0 --unmount" @@ -281,8 +287,7 @@ then exit 0 fi -if [ $FLAGS_unmount -eq $FLAGS_TRUE ] -then +if [ $FLAGS_unmount -eq $FLAGS_TRUE ]; then teardown_env exit 0 fi diff --git a/get_latest_image.sh b/get_latest_image.sh index 1c5d90f20e..82e7569e4d 100755 --- a/get_latest_image.sh +++ b/get_latest_image.sh @@ -6,9 +6,26 @@ # Prints the path to the most recently built image to stdout. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" +# --- 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 diff --git a/get_package_list b/get_package_list index b45e2869ad..ea16e03759 100755 --- a/get_package_list +++ b/get_package_list @@ -7,7 +7,26 @@ # Lists all package dependencies of a particular package. Useful to find out # all packages depended on by chromeos and chromeos-dev. -. "$(dirname "$0")/common.sh" +# --- 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 --- # Script must be run inside the chroot. assert_inside_chroot diff --git a/gmergefs b/gmergefs index 6995a6fd08..2be45dad2d 100755 --- a/gmergefs +++ b/gmergefs @@ -6,10 +6,28 @@ # Run gmergefs from the scripts directory. -COMMON_SH="$(dirname "$0")/common.sh" -. "$COMMON_SH" +# --- 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 --- # Script must be run inside the chroot. assert_inside_chroot -cd ${GCLIENT_ROOT}/src/platform/dev && ./gmergefs $* +cd ${GCLIENT_ROOT}/src/platform/dev && ./gmergefs "$@" diff --git a/image_hacks.sh b/image_hacks.sh index 633962c571..cf275908ae 100755 --- a/image_hacks.sh +++ b/image_hacks.sh @@ -23,20 +23,41 @@ #------ These are the scripts we're trying to kill --------# +# --- 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 --- + function mod_image_for_test() { - $(dirname ${0})/mod_image_for_test.sh $* || return $? + "${SCRIPTS_DIR}/mod_image_for_test.sh" "$@" || return $? } function mod_image_for_recovery() { - $(dirname ${0})/mod_image_for_recovery.sh $* || return $? + "${SCRIPTS_DIR}/mod_image_for_recovery.sh" "$@" || return $? } function mod_image_for_dev_recovery() { - $(dirname ${0})/mod_image_for_dev_recovery.sh $* || return $? + "${SCRIPTS_DIR}/mod_image_for_dev_recovery.sh" "$@" || return $? } function customize_rootfs() { - $(dirname ${0})/customize_rootfs $* || return $? + "${SCRIPTS_DIR}/customize_rootfs" "$@" || return $? } #-------------------------- Tools -------------------------# @@ -73,7 +94,6 @@ function corrupt_for_test() { } function main() { - . "$(dirname "$0")/common.sh" get_default_board # Flag definitions: @@ -116,10 +136,10 @@ function main() { } case "$(basename $0)" in -# (mod_image_for_test.sh) mod_image_for_test $* || return $?;; -# (mod_image_for_recovery.sh) mod_image_for_recovery $* || return $?;; -# (mod_image_for_dev_recovery.sh) mod_image_for_dev_recovery $* || return $?;; -# (customize_rootfs) customize_rootfs $* || return $?;; - (image_hacks.sh) main $* || return $?;; # normal invocation +# (mod_image_for_test.sh) mod_image_for_test "$@" || return $?;; +# (mod_image_for_recovery.sh) mod_image_for_recovery "$@" || return $?;; +# (mod_image_for_dev_recovery.sh) mod_image_for_dev_recovery "$@" || return $?;; +# (customize_rootfs) customize_rootfs "$@" || return $?;; + (image_hacks.sh) main "$@" || return $?;; # normal invocation (*) echo "$0: Unknown invocation!"; exit 1 ;; esac diff --git a/image_to_live.sh b/image_to_live.sh index a8ce40c6b6..79e15b1f35 100755 --- a/image_to_live.sh +++ b/image_to_live.sh @@ -6,11 +6,28 @@ # Script to update an image onto a live running ChromiumOS instance. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. +# --- 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 -. "$(dirname $0)/common.sh" -. "$(dirname $0)/remote_access.sh" + 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 --- + +. "${SCRIPT_ROOT}/remote_access.sh" || die "Unable to load remote_access.sh" # Flags to control image_to_live. DEFINE_boolean ignore_hostname ${FLAGS_TRUE} \ @@ -130,7 +147,7 @@ function start_dev_server { # IMAGE_PATH should be the newest image and learn the board from # the target. learn_board - IMAGE_PATH="$($(dirname "$0")/get_latest_image.sh --board="${FLAGS_board}")" + IMAGE_PATH="$(${SCRIPTS_DIR}/get_latest_image.sh --board="${FLAGS_board}")" IMAGE_PATH="${IMAGE_PATH}/chromiumos_image.bin" devserver_flags="${devserver_flags} \ --image $(reinterpret_path_for_chroot ${IMAGE_PATH})" @@ -160,8 +177,7 @@ function start_dev_server { info "Waiting on devserver to start" info "note: be patient as the server generates the update before starting." - until netstat -anp 2>&1 | grep 0.0.0.0:${FLAGS_devserver_port} > /dev/null - do + until netstat -anp 2>&1 | grep 0.0.0.0:${FLAGS_devserver_port} > /dev/null; do sleep 5 echo -n "." if ! pgrep -f start_devserver > /dev/null; then @@ -314,7 +330,7 @@ function run_auto_update { function verify_image { info "Verifying image." - "${SCRIPTS_DIR}/mount_gpt_image.sh" --from "$(dirname ${IMAGE_PATH})" \ + "${SCRIPTS_DIR}/mount_gpt_image.sh" --from "$(dirname "${IMAGE_PATH}")" \ --image "$(basename ${IMAGE_PATH})" \ --read_only @@ -345,7 +361,7 @@ function find_root_dev { function main() { assert_outside_chroot - cd $(dirname "$0") + cd "${SCRIPTS_DIR}" FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" diff --git a/image_to_usb.sh b/image_to_usb.sh index 19eefb1f63..db5bd98787 100755 --- a/image_to_usb.sh +++ b/image_to_usb.sh @@ -6,12 +6,34 @@ # Script to convert the output of build_image.sh to a usb image. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" +# --- 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 --- # Load functions and constants for chromeos-install -. "$(dirname "$0")/chromeos-common.sh" +[ -f /usr/lib/installer/chromeos-common.sh ] && \ + INSTALLER_ROOT=/usr/lib/installer || \ + INSTALLER_ROOT=$(dirname "$(readlink -f "$0")") + +. "${INSTALLER_ROOT}/chromeos-common.sh" || \ + die "Unable to load chromeos-common.sh" get_default_board @@ -183,8 +205,7 @@ fi # Let's do it. -if [ -b "${FLAGS_to}" ] -then +if [ -b "${FLAGS_to}" ]; then # Output to a block device (i.e., a real USB key), so need sudo dd if [ ${FLAGS_install} -ne ${FLAGS_TRUE} ]; then echo "Copying USB image ${SRC_IMAGE} to device ${FLAGS_to}..." @@ -205,24 +226,21 @@ then fi # Make sure this is really what the user wants, before nuking the device - if [ ${FLAGS_yes} -ne ${FLAGS_TRUE} ] - then + if [ ${FLAGS_yes} -ne ${FLAGS_TRUE} ]; then sudo fdisk -l "${FLAGS_to}" 2>/dev/null | grep Disk | head -1 [ -n "$disk_manufacturer" ] && echo "Manufacturer: $disk_manufacturer" [ -n "$disk_product" ] && echo "Product: $disk_product" echo "This will erase all data on this device:" read -p "Are you sure (y/N)? " SURE SURE="${SURE:0:1}" # Get just the first character - if [ "${SURE}" != "y" ] - then + if [ "${SURE}" != "y" ]; then echo "Ok, better safe than sorry." exit 1 fi fi echo "Attempting to unmount any mounts on the USB device..." - for i in $(mount | grep ^"${FLAGS_to}" | awk '{print $1}') - do + for i in $(mount | grep ^"${FLAGS_to}" | awk '{print $1}'); do if sudo umount "$i" 2>&1 >/dev/null | grep "not found"; then echo echo "The device you have specified is already mounted at some point " diff --git a/image_to_virtualbox.sh b/image_to_virtualbox.sh index f194ae9349..094b0f52e6 100755 --- a/image_to_virtualbox.sh +++ b/image_to_virtualbox.sh @@ -5,9 +5,27 @@ # found in the LICENSE file. # Script to convert the output of build_image.sh to a VirtualBox image. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" + +# --- 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 --- IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" # Default to the most recent image @@ -28,7 +46,7 @@ eval set -- "${FLAGS_ARGV}" # Die on any errors. set -e -# Convert args to paths. Need eval to un-quote the string so that shell +# Convert args to paths. Need eval to un-quote the string so that shell # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. FLAGS_from=`eval readlink -f $FLAGS_from` FLAGS_to=`eval readlink -f $FLAGS_to` @@ -41,5 +59,5 @@ for EXTERNAL_tools in qemu-img VBoxManage; do fi done -$(dirname "$0")/image_to_vmware.sh --format=virtualbox --from=$FLAGS_from \ - --to=$(dirname "$FLAGS_to") --vbox_disk=$(basename "$FLAGS_to") +"${SCRIPTS_DIR}/image_to_vmware.sh" --format=virtualbox --from="$FLAGS_from" \ + --to="$(dirname "$FLAGS_to")" --vbox_disk="$(basename "$FLAGS_to")" diff --git a/image_to_vm.sh b/image_to_vm.sh index 2ff4984607..dff302303f 100755 --- a/image_to_vm.sh +++ b/image_to_vm.sh @@ -7,14 +7,38 @@ # Script to convert the output of build_image.sh to a VMware image and write a # corresponding VMware config file. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" -. "$(dirname "$0")/chromeos-common.sh" -. "$(dirname "$0")/lib/cros_vm_constants.sh" +# --- 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 --- + +# Need to be inside the chroot to load chromeos-common.sh +assert_inside_chroot + +# Load functions and constants for chromeos-install +. "/usr/lib/installer/chromeos-common.sh" || \ + die "Unable to load /usr/lib/installer/chromeos-common.sh" + +. "${SCRIPT_ROOT}/lib/cros_vm_constants.sh" || \ + die "Unable to load ${SCRIPT_ROOT}/lib/cros_vm_constants.sh" get_default_board -assert_inside_chroot # Flags DEFINE_string board "${DEFAULT_BOARD}" \ @@ -120,7 +144,7 @@ if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then fi # Memory units are in MBs -TEMP_IMG="$(dirname ${SRC_IMAGE})/vm_temp_image.bin" +TEMP_IMG="$(dirname "${SRC_IMAGE}")/vm_temp_image.bin" # If we're not building for VMWare, don't build the vmx if [ "${FLAGS_format}" != "vmware" ]; then @@ -189,11 +213,11 @@ mkdir -p "${TEMP_ESP_MNT}" sudo mount -o loop "${TEMP_ESP}" "${TEMP_ESP_MNT}" if [ "${FLAGS_format}" = "qemu" ]; then - sudo python "$(dirname $0)/fixup_image_for_qemu.py" \ + sudo python "${SCRIPTS_DIR}/fixup_image_for_qemu.py" \ --mounted_dir="${TEMP_MNT}" \ --enable_tablet=true else - sudo python "$(dirname $0)/fixup_image_for_qemu.py" \ + sudo python "${SCRIPTS_DIR}/fixup_image_for_qemu.py" \ --mounted_dir="${TEMP_MNT}" \ --enable_tablet=false fi diff --git a/kernel_fetcher.sh b/kernel_fetcher.sh index e85566a8b5..6a9f26a1b5 100755 --- a/kernel_fetcher.sh +++ b/kernel_fetcher.sh @@ -4,9 +4,26 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" +# --- 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 --- IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" @@ -22,8 +39,7 @@ eval set -- "${FLAGS_ARGV}" # Die on any errors. set -e -if [ -z "${FLAGS_from}" -o -z "${FLAGS_to}" -o -z "${FLAGS_offset}" ] -then +if [ -z "${FLAGS_from}" -o -z "${FLAGS_to}" -o -z "${FLAGS_offset}" ]; then echo "You must define all of from, to and offset." exit 1 fi diff --git a/lib/cros_vm_lib.sh b/lib/cros_vm_lib.sh index 8b70ad2c99..3a50a62705 100644 --- a/lib/cros_vm_lib.sh +++ b/lib/cros_vm_lib.sh @@ -69,7 +69,7 @@ function start_kvm() { fi local net_option="-net nic,model=virtio" - if [ -f "$(dirname $1)/.use_e1000" ]; then + if [ -f "$(dirname "$1")/.use_e1000" ]; then info "Detected older image, using e1000 instead of virtio." net_option="-net nic,model=e1000" fi @@ -91,7 +91,7 @@ function start_kvm() { # Checks to see if we can access the target virtual machine with ssh. function ssh_ping() { - "$(dirname $0)"/../ssh_test.sh \ + "${SCRIPT_ROOT}/ssh_test.sh" \ --ssh_port=${FLAGS_ssh_port} \ --remote=127.0.0.1 >&2 } diff --git a/make_developer_script_runner.sh b/make_developer_script_runner.sh index 32d3133c1a..134bf080e4 100755 --- a/make_developer_script_runner.sh +++ b/make_developer_script_runner.sh @@ -9,12 +9,33 @@ # It is very straight forward, top to bottom to show clearly what is # little is needed to create a developer shim to run a signed script. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" +# --- 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 --- + +# Need to be inside the chroot to load chromeos-common.sh +assert_inside_chroot # Load functions and constants for chromeos-install -. "$(dirname "$0")/chromeos-common.sh" +. "/usr/lib/installer/chromeos-common.sh" || \ + die "Unable to load /usr/lib/installer/chromeos-common.sh" DEFINE_integer statefulfs_size 2 \ "Number of mebibytes to use for the stateful filesystem" diff --git a/make_factory_package.sh b/make_factory_package.sh index 715f1fd9b3..bc68119e3c 100755 --- a/make_factory_package.sh +++ b/make_factory_package.sh @@ -11,15 +11,36 @@ # miniomaha lives in src/platform/dev/ and miniomaha partition sets live # in src/platform/dev/static. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" +# --- 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 --- + +# Need to be inside the chroot to load chromeos-common.sh +assert_inside_chroot # Load functions and constants for chromeos-install -. "$(dirname "$0")/chromeos-common.sh" +. "/usr/lib/installer/chromeos-common.sh" || \ + die "Unable to load /usr/lib/installer/chromeos-common.sh" # Load functions designed for image processing -. "$(dirname "$0")/lib/cros_image_common.sh" || +. "${SCRIPT_ROOT}/lib/cros_image_common.sh" || die "Cannot load required library: lib/cros_image_common.sh; Abort." get_default_board diff --git a/mk_memento_images.sh b/mk_memento_images.sh index 7a10745427..9e8b609e0a 100755 --- a/mk_memento_images.sh +++ b/mk_memento_images.sh @@ -10,8 +10,31 @@ set -e +# --- 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 --- + +. "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1) + # Load functions designed for image processing -if ! . "$(dirname "$0")/lib/cros_image_common.sh"; then +if ! . "${SCRIPT_ROOT}/lib/cros_image_common.sh"; then echo "ERROR: Cannot load required library: lib/cros_image_common.sh; Abort." exit 1 fi diff --git a/mod_image_for_recovery.sh b/mod_image_for_recovery.sh index 2d6e03151b..4119e59afe 100755 --- a/mod_image_for_recovery.sh +++ b/mod_image_for_recovery.sh @@ -9,19 +9,37 @@ # kernel. Alternatively, a signed recovery kernel can be used to # create a Chromium OS recovery image. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" +# --- 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 --- + +# Need to be inside the chroot to load chromeos-common.sh +assert_inside_chroot # Load functions and constants for chromeos-install -. "$(dirname "$0")/chromeos-common.sh" +. "/usr/lib/installer/chromeos-common.sh" || \ + die "Unable to load /usr/lib/installer/chromeos-common.sh" # For update_partition_table -. "$(dirname "$0")/resize_stateful_partition.sh" - - -# We need to be in the chroot to emerge test packages. -assert_inside_chroot +. "${SCRIPT_ROOT}/resize_stateful_partition.sh" || \ + die "Unable to load ${SCRIPT_ROOT}/resize_stateful_partition.sh" get_default_board @@ -371,7 +389,7 @@ RECOVERY_KERNEL_IMAGE=\ "${FLAGS_kernel_outfile:-${IMAGE_DIR}/recovery_vmlinuz.image}" RECOVERY_KERNEL_VBLOCK="${RECOVERY_KERNEL_IMAGE}.vblock" STATEFUL_DIR="$IMAGE_DIR/stateful_partition" -SCRIPTS_DIR=$(dirname "$0") +SCRIPTS_DIR=${SCRIPT_ROOT} # Mounts gpt image and sets up var, /usr/local and symlinks. # If there's a dev payload, mount stateful diff --git a/mod_image_for_test.sh b/mod_image_for_test.sh index 97aa5e0cc7..f9fec77c33 100755 --- a/mod_image_for_test.sh +++ b/mod_image_for_test.sh @@ -6,15 +6,33 @@ # Script to modify a keyfob-based chromeos system image for testability. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" +# --- 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 --- + +# Need to be inside the chroot to load chromeos-common.sh +assert_inside_chroot # Load functions and constants for chromeos-install -. "$(dirname "$0")/chromeos-common.sh" - -# We need to be in the chroot to emerge test packages. -assert_inside_chroot +. "/usr/lib/installer/chromeos-common.sh" || \ + die "Unable to load /usr/lib/installer/chromeos-common.sh" get_default_board @@ -92,8 +110,7 @@ cleanup_mounts() { # root/stateful image file system open. We do a best effort attempt to kill # them. PIDS=`sudo lsof -t "$1" | sort | uniq` - for pid in ${PIDS} - do + for pid in ${PIDS}; do local cmdline=`cat /proc/$pid/cmdline` echo "Killing process that has open file on the mounted directory: $cmdline" sudo kill $pid || /bin/true @@ -169,11 +186,11 @@ fi set -e -IMAGE_DIR="$(dirname "$FLAGS_image")" +IMAGE_DIR=$(dirname "$FLAGS_image") IMAGE_NAME="$(basename "$FLAGS_image")" ROOT_FS_DIR="$IMAGE_DIR/rootfs" STATEFUL_DIR="$IMAGE_DIR/stateful_partition" -SCRIPTS_DIR=$(dirname "$0") +SCRIPTS_DIR=${SCRIPT_ROOT} DEV_USER="chronos" trap cleanup EXIT @@ -229,7 +246,7 @@ fi cleanup # Now make it bootable with the flags from build_image -${SCRIPTS_DIR}/bin/cros_make_image_bootable $(dirname "${FLAGS_image}") \ +"${SCRIPTS_DIR}/bin/cros_make_image_bootable" "$(dirname "${FLAGS_image}")" \ $(basename "${FLAGS_image}") print_time_elapsed diff --git a/mount_gpt_image.sh b/mount_gpt_image.sh index 1c95a91eb1..1534105182 100755 --- a/mount_gpt_image.sh +++ b/mount_gpt_image.sh @@ -7,10 +7,34 @@ # 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). -. "$(dirname "$0")/common.sh" +# --- 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 --- + +# Need to be inside the chroot to load chromeos-common.sh +assert_inside_chroot + +# Load functions and constants for chromeos-install +. "/usr/lib/installer/chromeos-common.sh" || \ + die "Unable to load /usr/lib/installer/chromeos-common.sh" -# For functions related to gpt images. -. "$(dirname "$0")/chromeos-common.sh" locate_gpt get_default_board diff --git a/resize_stateful_partition.sh b/resize_stateful_partition.sh index 07ebd73cf1..455807491b 100755 --- a/resize_stateful_partition.sh +++ b/resize_stateful_partition.sh @@ -6,9 +6,33 @@ # Utility methods used to resize a stateful partition and update the GPT table -# Source constants and utility functions -. "$(dirname "$0")/common.sh" -. "$(dirname "$0")/chromeos-common.sh" +# --- 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 --- + +# Need to be inside the chroot to load chromeos-common.sh +assert_inside_chroot + +# Load functions and constants for chromeos-install +. "/usr/lib/installer/chromeos-common.sh" || \ + die "Unable to load /usr/lib/installer/chromeos-common.sh" locate_gpt diff --git a/run_remote_tests.sh b/run_remote_tests.sh index ab4923d756..cb007c060b 100755 --- a/run_remote_tests.sh +++ b/run_remote_tests.sh @@ -9,8 +9,28 @@ # Load common constants. This should be the first executable line. # The path to common.sh should be relative to your script's location. -. "$(dirname $0)/common.sh" -. "$(dirname $0)/remote_access.sh" +# --- 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 --- + +. "${SCRIPT_ROOT}/remote_access.sh" || die "Unable to load remote_access.sh" get_default_board @@ -33,8 +53,7 @@ function stop_ssh_agent() { # Call this function from the exit trap of the main script. # Iff we started ssh-agent, be nice and clean it up. # Note, only works if called from the main script - no subshells. - if [[ 1 -eq ${OWN_SSH_AGENT} ]] - then + if [[ 1 -eq ${OWN_SSH_AGENT} ]]; then kill ${SSH_AGENT_PID} 2>/dev/null unset OWN_SSH_AGENT SSH_AGENT_PID SSH_AUTH_SOCK fi @@ -129,7 +148,7 @@ autotest autotest-tests (or use --build)." fi if [ ${FLAGS_build} -eq ${FLAGS_FALSE} ] && - $(dirname $0)/cros_workon --board=${FLAGS_board} list | + "${SCRIPTS_DIR}/cros_workon" --board=${FLAGS_board} list | grep -q autotest; then AUTOTEST_DIR="${SRC_ROOT}/third_party/autotest/files" FLAGS_build=${FLAGS_TRUE} @@ -165,7 +184,7 @@ autotest-tests to continue." } function main() { - cd $(dirname "$0") + cd "${SCRIPTS_DIR}" FLAGS "$@" || exit 1 @@ -261,7 +280,7 @@ function main() { echo "" info "Running ${test_type} test ${control_file}" local control_file_name=$(basename "${control_file}") - local short_name=$(basename $(dirname "${control_file}")) + local short_name=$(basename "$(dirname "${control_file}")") # testName/control --> testName # testName/control.bvt --> testName.bvt diff --git a/set_shared_user_password.sh b/set_shared_user_password.sh index 25baca0e63..bdc7c44f1a 100755 --- a/set_shared_user_password.sh +++ b/set_shared_user_password.sh @@ -7,12 +7,29 @@ # Script to set the password for the shared user account. Stores the # MD5crypt'd password to a file, for use by customize_rootfs.sh. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" +# --- 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 --- # Script must be run inside the chroot -restart_in_chroot_if_needed $* +restart_in_chroot_if_needed "$@" FLAGS_HELP="USAGE: $0 [flags]" diff --git a/ssh_test.sh b/ssh_test.sh index 8048150edb..ef5eb57491 100755 --- a/ssh_test.sh +++ b/ssh_test.sh @@ -8,8 +8,28 @@ # a code of 0 if successful and non-zero otherwise. Used by test infrastructure # scripts. -. "$(dirname "$0")/common.sh" -. "$(dirname "$0")/remote_access.sh" +# --- 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 --- + +. "${SCRIPT_ROOT}/remote_access.sh" || die "Unable to load remote_access.sh" function cleanup { cleanup_remote_access @@ -17,7 +37,7 @@ function cleanup { } function main() { - cd $(dirname "$0") + cd "${SCRIPTS_DIR}" FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" diff --git a/start_devserver b/start_devserver index 38cbbdb32b..6d4cddbba4 100755 --- a/start_devserver +++ b/start_devserver @@ -6,12 +6,30 @@ # Start the Dev Server after making sure we are running under a chroot. -. "$(dirname "$0")/common.sh" +# --- 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 --- # Script must be run inside the chroot if not in 'always serve' mode. -if [[ "$1" != "--archive_dir" ]] -then - restart_in_chroot_if_needed $* +if [[ "$1" != "--archive_dir" ]]; then + restart_in_chroot_if_needed "$@" fi # Temporary workaround: to start devserver for update engine, pass in args @@ -23,4 +41,4 @@ if [ -z "${PKG_INSTALL_MASK+x}" ]; then fi echo PKG_INSTALL_MASK=$PKG_INSTALL_MASK -cd ${GCLIENT_ROOT}/src/platform/dev && python devserver.py $* +cd ${GCLIENT_ROOT}/src/platform/dev && python devserver.py "$@" diff --git a/sync_build_test.sh b/sync_build_test.sh index 72585087da..b7dad2747e 100755 --- a/sync_build_test.sh +++ b/sync_build_test.sh @@ -41,11 +41,28 @@ # CHRONOS_PASSWD - default value for --chronos_passwd # -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" -# Allow remote access (for learning board type) -. "$(dirname "$0")/remote_access.sh" +# --- 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 --- + +. "${SCRIPT_ROOT}/remote_access.sh" DEFINE_string board "" "Board setting" DEFINE_boolean build ${FLAGS_TRUE} \ @@ -122,7 +139,7 @@ function validate_and_set_param_defaults() { if [[ -z "${FLAGS_top}" ]]; then # Use the top directory based on where this script runs from - FLAGS_top=$(dirname $(dirname $(dirname $0))) + FLAGS_top=${GCLIENT_ROOT} fi # Canonicalize any symlinks @@ -487,7 +504,7 @@ function grab_buildbot() { export GSDCURL_USERNAME read -s -p "Password: " GSDCURL_PASSWORD export GSDCURL_PASSWORD - CURL="$(dirname $0)/bin/cros_gsdcurl.py" + CURL="${SCRIPTS_DIR}/bin/cros_gsdcurl.py" if [[ "${FLAGS_grab_buildbot}" == "LATEST" ]]; then local latest=$(${CURL} "${FLAGS_buildbot_uri}/LATEST") if [[ -z "${latest}" ]]; then @@ -507,7 +524,7 @@ function grab_buildbot() { cd "${dl_dir}" unzip image.zip - local image_basename=$(basename $(dirname "${FLAGS_grab_buildbot}")) + local image_basename=$(basename "$(dirname "${FLAGS_grab_buildbot}")") local image_base_dir="${FLAGS_top}/src/build/images/${FLAGS_board}" local image_dir="${image_base_dir}/${image_basename}" info "Copying in build image to ${image_dir}" diff --git a/test_image b/test_image index ec586f1523..f4b079a9d4 100755 --- a/test_image +++ b/test_image @@ -4,9 +4,26 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" +# --- 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 --- # Flags DEFINE_string target "x86" \ diff --git a/tracker.sh b/tracker.sh index 5e937ee2b8..4ce6e3431f 100755 --- a/tracker.sh +++ b/tracker.sh @@ -6,9 +6,26 @@ # Script to report issues from the command line -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" +# --- 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 --- # Script must be run outside the chroot assert_outside_chroot @@ -36,7 +53,7 @@ FLAGS_HELP=" Assigned = In someone's queue, but not started Started = Work in progress Upstream = Issue has been reported to another project - + Closed Statuses: Fixed = Work completed, needs verification Verified = Test or reporter verified that the fix works @@ -44,13 +61,13 @@ FLAGS_HELP=" WontFix = Cannot reproduce, works as intended, or obsolete FixUnreleased = Security bug fixed on all branches, not released Invalid = Not a valid issue report - + Types: Bug = Software not working correctly Feature = Request for new or improved feature Task = Project or work that doesn't change code Cleanup = Code maintenance unrelated to bugs - + Priority: 0 = Critical. Resolve now. Blocks other work or users need immediate update. 1 = High. Required for the specified milestone release. diff --git a/update_bootloaders.sh b/update_bootloaders.sh index 2dbc138bbb..0b34172dcc 100755 --- a/update_bootloaders.sh +++ b/update_bootloaders.sh @@ -7,8 +7,33 @@ # Helper script that generates the legacy/efi bootloader partitions. # It does not populate the templates, but can update a loop device. -. "$(dirname "$0")/common.sh" -. "$(dirname "$0")/chromeos-common.sh" # installer +# --- 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 --- + +# Need to be inside the chroot to load chromeos-common.sh +assert_inside_chroot + +# Load functions and constants for chromeos-install +. "/usr/lib/installer/chromeos-common.sh" || \ + die "Unable to load /usr/lib/installer/chromeos-common.sh" get_default_board diff --git a/update_kernel.sh b/update_kernel.sh index 2c9972379d..b5cb818b43 100755 --- a/update_kernel.sh +++ b/update_kernel.sh @@ -6,14 +6,31 @@ # Script to update the kernel on a live running ChromiumOS instance. -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. +# --- 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 -. "$(dirname $0)/common.sh" -. "$(dirname $0)/remote_access.sh" + 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 --- + +. "${SCRIPT_ROOT}/remote_access.sh" # Script must be run inside the chroot. -restart_in_chroot_if_needed $* +restart_in_chroot_if_needed "$@" DEFINE_string board "" "Override board reported by target" DEFINE_string device "" "Override boot device reported by target" diff --git a/upload_symbols b/upload_symbols index 96307b4247..d6f6c2561f 100755 --- a/upload_symbols +++ b/upload_symbols @@ -7,16 +7,30 @@ # purposes. This script need only be used to upload release builds # symbols or to debug crashes on non-release builds (in which case try # to only upload the symbols for those executables involved). -# -# NOTE: This script must be run from the chromeos build chroot environment. -# -# Load common constants. This should be the first executable line. -# The path to common.sh should be relative to your script's location. -. "$(dirname "$0")/common.sh" +# --- 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 --- # Script must be run inside the chroot -restart_in_chroot_if_needed $* +restart_in_chroot_if_needed "$@" get_default_board @@ -118,7 +132,7 @@ function main() { sudo rm -rf "${DEFAULT_BREAKPAD_ROOT}" info "Generating all breakpad symbol files." local verbosity="" - local generate_script="$(dirname $0)/cros_generate_breakpad_symbols" + local generate_script="${SCRIPTS_DIR}/cros_generate_breakpad_symbols" [ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ] && verbosity="--verbose" if ! "${generate_script}" --board=${FLAGS_board} ${verbosity}; then error "Some errors while generating symbols; uploading anyway" diff --git a/verify_rootfs_chksum.sh b/verify_rootfs_chksum.sh index 9a8012dfba..7ad196d897 100755 --- a/verify_rootfs_chksum.sh +++ b/verify_rootfs_chksum.sh @@ -6,15 +6,40 @@ # Script to verify integrity of root file system for a GPT-based image -# Load functions and constants -. "$(dirname "$0")/common.sh" || exit 1 -. "$(dirname "$0")/chromeos-common.sh" || exit 1 +# --- 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 --- + +# Load functions and constants for chromeos-install +[ -f /usr/lib/installer/chromeos-common.sh ] && \ + INSTALLER_ROOT=/usr/lib/installer || \ + INSTALLER_ROOT=$(dirname "$(readlink -f "$0")") + +. "${INSTALLER_ROOT}/chromeos-common.sh" || \ + die "Unable to load chromeos-common.sh" # Needed for partoffset and partsize calls locate_gpt # Script must be run inside the chroot. -restart_in_chroot_if_needed $* +restart_in_chroot_if_needed "$@" DEFINE_string image "" "Device or an image path. Default: (empty)." @@ -58,8 +83,7 @@ function get_partitions() { } function cleanup() { - for i in ${KERNEL_IMG} ${ROOTFS_IMG} - do + for i in ${KERNEL_IMG} ${ROOTFS_IMG}; do if [ ! -b ${i} ]; then rm -f ${i} fi