mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-24 07:01:13 +02:00
Simplify standard boilerplate for selected scripts
This shortens the standard boilerplate for finding and sourcing shell function libraries for build_image, mod_image_for_test.sh and mod_image_for_recovery.sh. As a side effect of the change, both mod_image_for_test.sh and mod_image_for_recovery.sh will now restart inside the chroot if invoked from outside; this is consistent with the pre-existing behavior of build_image. BUG=None TEST=run the three scripts, from both inside and outside the chroot Change-Id: Idd91cbee323346a871b49deea31a76875f5ee3c4 Reviewed-on: http://gerrit.chromium.org/gerrit/4675 Tested-by: Richard Barnette <jrbarnette@chromium.org> Reviewed-by: Vince Laviano <vlaviano@chromium.org>
This commit is contained in:
parent
1fe3c57d18
commit
8447777820
37
build_image
37
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" \
|
||||
|
21
build_library/build_common.sh
Normal file
21
build_library/build_common.sh
Normal file
@ -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
|
@ -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 \
|
||||
|
@ -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 \
|
||||
|
Loading…
x
Reference in New Issue
Block a user