crosutils: allow factory scripts to be executed in a limited bundle environment

This CL allows factory related scripts to be executed in a prepared and limited
environment which can be made by extracting a factory bundle:
 - always load scripts from $SCRIPT_ROOT
 - allow running bundled binary programs from $SCRIPT_ROOT/../bin
 - override GCLIENT_ROOT for the layout of a bundle

BUG=chrome-os-partner:5979
TEST=(outside cros environment)
     ./make_factory_package --config mp_factory.conf  # test omaha
     ./make_factory_package --config rma.conf  # test --usbimg
     ./make_factory_package --config mp_ssd.conf  # test --diskimg

Change-Id: Ibf85fa267f6fe53ae88e41fd7f62ef7110b2b0bf
Reviewed-on: http://gerrit.chromium.org/gerrit/7905
Tested-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Nick Sanders <nsanders@chromium.org>
This commit is contained in:
Hung-Te Lin 2011-09-17 15:44:49 +08:00 committed by chrome-bot
parent cfc4720c28
commit 545dc57e97
4 changed files with 42 additions and 71 deletions

View File

@ -45,6 +45,16 @@ image_has_part_tools() {
image_has_command cgpt || image_has_command parted image_has_command cgpt || image_has_command parted
} }
# Finds if specified tool can be found by current path; updates system path if
# the tool is available in given folder.
image_find_tool() {
local tool="$1"
local alternative_folder="$(readlink -f "$2")"
if ! image_has_command "$tool" && [ -x "$alternative_folder/$tool" ]; then
PATH="$alternative_folder:$PATH"; export PATH
fi
}
# Finds the best partition tool and print partition offset # Finds the best partition tool and print partition offset
image_part_offset() { image_part_offset() {
local file="$1" local file="$1"

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# Copyright (c) 2009 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 # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
@ -11,40 +11,23 @@
# miniomaha lives in src/platform/dev/ and miniomaha partition sets live # miniomaha lives in src/platform/dev/ and miniomaha partition sets live
# in src/platform/dev/static. # in src/platform/dev/static.
# --- BEGIN COMMON.SH BOILERPLATE --- # This script may be executed in a full CrOS source tree or an extracted factory
# Load common CrOS utilities. Inside the chroot this file is installed in # bundle with limited tools, so we must always load scripts from $SCRIPT_ROOT
# /usr/lib/crosutils. Outside the chroot we find it relative to the script's # and search for binary programs in $SCRIPT_ROOT/../bin
# location.
find_common_sh() {
local common_paths=(/usr/lib/crosutils $(dirname "$(readlink -f "$0")"))
local path
SCRIPT_ROOT= SCRIPT="$(readlink -f "$0")"
for path in "${common_paths[@]}"; do SCRIPT_ROOT="$(dirname "$SCRIPT")"
if [ -r "${path}/common.sh" ]; then . "$SCRIPT_ROOT/lib/cros_image_common.sh" || exit 1
SCRIPT_ROOT=${path} image_find_tool "cgpt" "$SCRIPT_ROOT/../bin"
break
if [ -f "$SCRIPT_ROOT/../dev/devserver.py" ]; then
# Running within an extracted factory bundle
GCLIENT_ROOT="$(readlink -f "$SCRIPT_ROOT/..")"
fi fi
done . "$SCRIPT_ROOT/common.sh" || exit 1
} . "$SCRIPT_ROOT/chromeos-common.sh" || exit 1
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
# NOTE: This script needs to be called from outside the chroot.
. "/usr/lib/installer/chromeos-common.sh" &> /dev/null || \
. "${SRC_ROOT}/platform/installer/chromeos-common.sh" || \
die "Unable to load /usr/lib/installer/chromeos-common.sh"
# Load functions designed for image processing
. "${SCRIPT_ROOT}/lib/cros_image_common.sh" ||
die "Cannot load required library: lib/cros_image_common.sh; Abort."
SCRIPT="$0"
get_default_board get_default_board
FLAGS_NONE='none' FLAGS_NONE='none'
# Flags # Flags

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
#
# Copyright (c) 2011 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 # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
@ -9,11 +9,14 @@
# CAUTION: Recovery shim images are not supported yet because they require the # CAUTION: Recovery shim images are not supported yet because they require the
# kernel partitions to be laid out in a special way # kernel partitions to be laid out in a special way
SCRIPT="$0" # This script may be executed in a full CrOS source tree or an extracted factory
SCRIPT_ROOT=$(dirname "$SCRIPT") # bundle with limited tools, so we must always load scripts from $SCRIPT_ROOT
# and search for binary programs in $SCRIPT_ROOT/../bin
# Load functions designed for image processing SCRIPT="$(readlink -f "$0")"
. "${SCRIPT_ROOT}/lib/cros_image_common.sh" || exit 1 SCRIPT_ROOT="$(dirname "$SCRIPT")"
. "$SCRIPT_ROOT/lib/cros_image_common.sh" || exit 1
image_find_tool "cgpt" "$SCRIPT_ROOT/../bin"
# CGPT Header: PMBR, header, table; sec_table, sec_header # CGPT Header: PMBR, header, table; sec_table, sec_header
CGPT_START_SIZE=$((1 + 1 + 32)) CGPT_START_SIZE=$((1 + 1 + 32))

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# Copyright (c) 2009 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 # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
@ -8,35 +8,16 @@
# build_image.sh and generates an image that can be used for auto # build_image.sh and generates an image that can be used for auto
# update. # update.
# This script may be executed in a full CrOS source tree or an extracted factory
# bundle with limited tools, so we must always load scripts from $SCRIPT_ROOT
# and search for binary programs in $SCRIPT_ROOT/../bin
SCRIPT="$(readlink -f "$0")"
SCRIPT_ROOT="$(dirname "$SCRIPT")"
. "$SCRIPT_ROOT/lib/cros_image_common.sh" || exit 1
image_find_tool "cgpt" "$SCRIPT_ROOT/../bin"
set -e 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 ---
# Load functions designed for image processing
if ! . "${SCRIPT_ROOT}/lib/cros_image_common.sh"; then
echo "ERROR: Cannot load required library: lib/cros_image_common.sh; Abort."
exit 1
fi
# We need 2-3 non-zero parameters. # We need 2-3 non-zero parameters.
if [ "$#" -lt 2 ] || [ "$#" -gt 3 ] || [ -z "$1" ] || [ -z "$2" ]; then if [ "$#" -lt 2 ] || [ "$#" -gt 3 ] || [ -z "$1" ] || [ -z "$2" ]; then
echo " echo "
@ -56,12 +37,6 @@ Examples:
exit 1 exit 1
fi fi
if [ "$CROS_GENERATE_UPDATE_PAYLOAD_CALLED" != "1" ]; then
echo "WARNING:"
echo " This script should only be called from cros_generate_update_payload"
echo " Please run that script with --help to see how to use it."
fi
if ! image_has_command pigz; then if ! image_has_command pigz; then
(echo "WARNING:" (echo "WARNING:"
echo " Your system does not have pigz (parallel gzip) installed." echo " Your system does not have pigz (parallel gzip) installed."