diff --git a/build_image b/build_image index 1d3d3c9195..409818dcce 100755 --- a/build_image +++ b/build_image @@ -1,3 +1,4 @@ +#!/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 @@ -8,42 +9,10 @@ # the given target's root with binary packages turned on. This script will # build the Chrome OS image using only pre-built binary packages. -# 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 "$0")) - local path +SCRIPT_ROOT=$(dirname "$0") +. "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1 - SCRIPT_ROOT= - for path in "${common_paths[@]}"; do - local common="${path}/common.sh" - if ([ -r "${common}" ] && . "${common}" && [ -d "${SCRIPTS_DIR}" ]); then - SCRIPT_ROOT=${path} - break - fi - done -} -find_common_sh -. "${SCRIPT_ROOT}/common.sh" || ! echo "Unable to load common.sh" || exit 1 - -# 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" - -locate_gpt - -# Script must be run inside the chroot. -restart_in_chroot_if_needed "$@" - -get_default_board - -# Flags. DEFINE_string board "${DEFAULT_BOARD}" \ "The board to build an image for." DEFINE_string build_root "/build" \ diff --git a/build_library/build_common.sh b/build_library/build_common.sh new file mode 100644 index 0000000000..a77f736b32 --- /dev/null +++ b/build_library/build_common.sh @@ -0,0 +1,21 @@ +# 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. + +# Common library file to be sourced by build_image, +# mod_image_for_test.sh, and mod_image_for_recovery.sh. This +# file ensures that library source files needed by all the scripts +# are included once, and also takes care of certain bookeeping tasks +# common to all the scripts. + +# SCRIPT_ROOT must be set prior to sourcing this file +. "${SCRIPT_ROOT}/common.sh" || exit 1 + +# All scripts using this file must be run inside the chroot. +restart_in_chroot_if_needed "$@" + +INSTALLER_ROOT=/usr/lib/installer +. "${INSTALLER_ROOT}/chromeos-common.sh" || exit 1 + +locate_gpt +get_default_board diff --git a/mod_image_for_recovery.sh b/mod_image_for_recovery.sh index 93c3239585..485fa11b38 100755 --- a/mod_image_for_recovery.sh +++ b/mod_image_for_recovery.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (c) 2010 The Chromium OS Authors. All rights reserved. +# 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. @@ -9,37 +9,9 @@ # kernel. Alternatively, a signed recovery kernel can be used to # create a Chromium OS recovery image. -# --- 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") +. "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1 - 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 - -get_default_board DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built" b DEFINE_integer statefulfs_sectors 4096 \ diff --git a/mod_image_for_test.sh b/mod_image_for_test.sh index 8ba2e3f1ee..48793c6f59 100755 --- a/mod_image_for_test.sh +++ b/mod_image_for_test.sh @@ -19,35 +19,9 @@ # TODO(vlaviano): delete this script. # ============================================================================= -# --- 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") +. "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1 - 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 DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built" b DEFINE_boolean factory $FLAGS_FALSE \