mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-09 05:56:58 +02:00
Fix numerous style nits and inconsistencies in mod_image_for_test.sh
BUG=none TEST=build and boot a factory test image Review URL: http://codereview.chromium.org/6713049 Change-Id: Ia0c4c9780fccc91c4464acf84ca4c0327b8ea7bd
This commit is contained in:
parent
4f71dfcc84
commit
68fc75f034
@ -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.
|
||||||
|
|
||||||
@ -48,49 +48,49 @@ DEFINE_string qualdb "" "Location of qualified component file" d
|
|||||||
DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" y
|
DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" y
|
||||||
DEFINE_string build_root "/build" \
|
DEFINE_string build_root "/build" \
|
||||||
"The root location for board sysroots."
|
"The root location for board sysroots."
|
||||||
DEFINE_boolean fast ${DEFAULT_FAST} "Call many emerges in parallel"
|
DEFINE_boolean fast $DEFAULT_FAST "Call many emerges in parallel"
|
||||||
DEFINE_boolean inplace $FLAGS_TRUE \
|
DEFINE_boolean inplace $FLAGS_TRUE \
|
||||||
"Modify/overwrite the image ${CHROMEOS_IMAGE_NAME} in place. \
|
"Modify/overwrite the image $CHROMEOS_IMAGE_NAME in place. \
|
||||||
Otherwise the image will be copied to ${CHROMEOS_TEST_IMAGE_NAME} \
|
Otherwise the image will be copied to $CHROMEOS_TEST_IMAGE_NAME \
|
||||||
(or ${CHROMEOS_FACTORY_TEST_IMAGE_NAME} for --factory) if needed, and \
|
(or $CHROMEOS_FACTORY_TEST_IMAGE_NAME for --factory) if needed, and \
|
||||||
modified there"
|
modified there"
|
||||||
DEFINE_boolean force_copy ${FLAGS_FALSE} \
|
DEFINE_boolean force_copy $FLAGS_FALSE \
|
||||||
"Always rebuild test image if --noinplace"
|
"Always rebuild test image if --noinplace"
|
||||||
|
|
||||||
# Parse command line
|
# Parse command line
|
||||||
FLAGS "$@" || exit 1
|
FLAGS "$@" || exit 1
|
||||||
eval set -- "${FLAGS_ARGV}"
|
eval set -- "$FLAGS_ARGV"
|
||||||
|
|
||||||
EMERGE_CMD="emerge"
|
EMERGE_CMD="emerge"
|
||||||
EMERGE_BOARD_CMD="emerge-${FLAGS_board}"
|
EMERGE_BOARD_CMD="emerge-$FLAGS_board"
|
||||||
if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then
|
if [ $FLAGS_fast -eq $FLAGS_TRUE ]; then
|
||||||
echo "Using alternate emerge"
|
echo "Using alternate emerge"
|
||||||
EMERGE_CMD="${GCLIENT_ROOT}/chromite/bin/parallel_emerge"
|
EMERGE_CMD="$GCLIENT_ROOT/chromite/bin/parallel_emerge"
|
||||||
EMERGE_BOARD_CMD="${EMERGE_CMD} --board=${FLAGS_board}"
|
EMERGE_BOARD_CMD="$EMERGE_CMD --board=$FLAGS_board"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# No board, no default and no image set then we can't find the image
|
# No board, no default and no image set then we can't find the image
|
||||||
if [ -z $FLAGS_image ] && [ -z $FLAGS_board ] ; then
|
if [ -z "$FLAGS_image" -a -z "$FLAGS_board" ] ; then
|
||||||
setup_board_warning
|
setup_board_warning
|
||||||
die "mod_image_for_test failed. No board set and no image set"
|
die "mod_image_for_test failed. No board set and no image set"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# We have a board name but no image set. Use image at default location
|
# We have a board name but no image set. Use image at default location
|
||||||
if [ -z $FLAGS_image ] ; then
|
if [ -z "$FLAGS_image" ] ; then
|
||||||
IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}"
|
IMAGES_DIR="$DEFAULT_BUILD_ROOT/images/$FLAGS_board"
|
||||||
FILENAME="${CHROMEOS_IMAGE_NAME}"
|
FILENAME="$CHROMEOS_IMAGE_NAME"
|
||||||
FLAGS_image="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)/${FILENAME}"
|
FLAGS_image="$IMAGES_DIR/$(ls -t $IMAGES_DIR 2>&-| head -1)/$FILENAME"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Turn path into an absolute path.
|
# Turn path into an absolute path.
|
||||||
FLAGS_image=`eval readlink -f ${FLAGS_image}`
|
FLAGS_image=$(eval readlink -f $FLAGS_image)
|
||||||
|
|
||||||
# What cross-build are we targeting?
|
# What cross-build are we targeting?
|
||||||
. "${FLAGS_build_root}/${FLAGS_board}/etc/make.conf.board_setup"
|
. "$FLAGS_build_root/$FLAGS_board/etc/make.conf.board_setup"
|
||||||
# Figure out ARCH from the given toolchain.
|
# Figure out ARCH from the given toolchain.
|
||||||
# TODO: Move to common.sh as a function after scripts are switched over.
|
# TODO: Move to common.sh as a function after scripts are switched over.
|
||||||
TC_ARCH=$(echo "${CHOST}" | awk -F'-' '{ print $1 }')
|
TC_ARCH=$(echo "$CHOST" | awk -F'-' '{ print $1 }')
|
||||||
case "${TC_ARCH}" in
|
case "$TC_ARCH" in
|
||||||
arm*)
|
arm*)
|
||||||
ARCH="arm"
|
ARCH="arm"
|
||||||
;;
|
;;
|
||||||
@ -98,7 +98,7 @@ case "${TC_ARCH}" in
|
|||||||
ARCH="x86"
|
ARCH="x86"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
error "Unable to determine ARCH from toolchain: ${CHOST}"
|
error "Unable to determine ARCH from toolchain: $CHOST"
|
||||||
exit 1
|
exit 1
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@ -107,11 +107,11 @@ cleanup_mounts() {
|
|||||||
# Occasionally there are some daemons left hanging around that have our
|
# Occasionally there are some daemons left hanging around that have our
|
||||||
# root/stateful image file system open. We do a best effort attempt to kill
|
# root/stateful image file system open. We do a best effort attempt to kill
|
||||||
# them.
|
# them.
|
||||||
PIDS=`sudo lsof -t "$1" | sort | uniq`
|
PIDS=$(sudo lsof -t "$1" | sort | uniq)
|
||||||
for pid in ${PIDS}; do
|
for pid in $PIDS; do
|
||||||
local cmdline=`cat /proc/$pid/cmdline`
|
local cmdline=$(cat /proc/$pid/cmdline)
|
||||||
echo "Killing process that has open file on the mounted directory: $cmdline"
|
echo "Killing process that has open file on the mounted directory: $cmdline"
|
||||||
sudo kill $pid || /bin/true
|
sudo kill $pid || true
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ cleanup() {
|
|||||||
# Emerges chromeos-test onto the image.
|
# Emerges chromeos-test onto the image.
|
||||||
emerge_chromeos_test() {
|
emerge_chromeos_test() {
|
||||||
INSTALL_MASK=""
|
INSTALL_MASK=""
|
||||||
if [[ $FLAGS_installmask -eq ${FLAGS_TRUE} ]]; then
|
if [[ $FLAGS_installmask -eq $FLAGS_TRUE ]]; then
|
||||||
INSTALL_MASK="$DEFAULT_INSTALL_MASK"
|
INSTALL_MASK="$DEFAULT_INSTALL_MASK"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -136,20 +136,18 @@ emerge_chromeos_test() {
|
|||||||
|
|
||||||
|
|
||||||
install_autotest() {
|
install_autotest() {
|
||||||
SYSROOT="${FLAGS_build_root}/${FLAGS_board}"
|
local autotest_src="$FLAGS_build_root/$FLAGS_board/usr/local/autotest"
|
||||||
AUTOTEST_SRC="${SYSROOT}/usr/local/autotest"
|
local stateful_root="$ROOT_FS_DIR/usr/local"
|
||||||
stateful_root="${ROOT_FS_DIR}/usr/local"
|
local autotest_client="$stateful_root/autotest"
|
||||||
autotest_client="/autotest"
|
|
||||||
|
|
||||||
echo "Install autotest into stateful partition from $AUTOTEST_SRC"
|
echo "Install autotest into stateful partition from $AUTOTEST_SRC"
|
||||||
|
|
||||||
sudo mkdir -p "${stateful_root}${autotest_client}"
|
sudo mkdir -p "$autotest_client"
|
||||||
|
|
||||||
# Remove excess files from stateful partition.
|
# Remove excess files from stateful partition.
|
||||||
# If these aren't there, that's fine.
|
sudo rm -rf "$autotest_client/"*
|
||||||
sudo rm -rf "${stateful_root}${autotest_client}/*" || true
|
sudo rm -rf "$stateful_root/autotest-pkgs"
|
||||||
sudo rm -rf "${stateful_root}/autotest-pkgs" || true
|
sudo rm -rf "$stateful_root/lib/icedtea6"
|
||||||
sudo rm -rf "${stateful_root}/lib/icedtea6" || true
|
|
||||||
|
|
||||||
sudo rsync --delete --delete-excluded -auv \
|
sudo rsync --delete --delete-excluded -auv \
|
||||||
--exclude=deps/realtimecomm_playground \
|
--exclude=deps/realtimecomm_playground \
|
||||||
@ -162,33 +160,32 @@ install_autotest() {
|
|||||||
--exclude=site_tests/desktopui_PageCyclerTests \
|
--exclude=site_tests/desktopui_PageCyclerTests \
|
||||||
--exclude=site_tests/desktopui_UITest \
|
--exclude=site_tests/desktopui_UITest \
|
||||||
--exclude=.svn \
|
--exclude=.svn \
|
||||||
${AUTOTEST_SRC}/client/* "${stateful_root}/${autotest_client}"
|
"$autotest_src/client/"* "$autotest_client"
|
||||||
|
|
||||||
sudo chmod 755 "${stateful_root}/${autotest_client}"
|
sudo chmod 755 "$autotest_client"
|
||||||
sudo chown -R 1000:1000 "${stateful_root}/${autotest_client}"
|
sudo chown -R 1000:1000 "$autotest_client"
|
||||||
}
|
}
|
||||||
|
|
||||||
# main process begins here.
|
# main process begins here.
|
||||||
|
|
||||||
IMAGE_DIR="$(dirname "${FLAGS_image}")"
|
IMAGE_DIR=$(dirname "$FLAGS_image")
|
||||||
|
|
||||||
# Copy the image to a test location if required
|
# Copy the image to a test location if required
|
||||||
if [ ${FLAGS_inplace} -eq ${FLAGS_FALSE} ]; then
|
if [ $FLAGS_inplace -eq $FLAGS_FALSE ]; then
|
||||||
if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ]; then
|
if [ $FLAGS_factory -eq $FLAGS_TRUE ]; then
|
||||||
TEST_PATHNAME="${IMAGE_DIR}/${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"
|
TEST_PATHNAME="$IMAGE_DIR/$CHROMEOS_FACTORY_TEST_IMAGE_NAME"
|
||||||
typename="factory"
|
typename="factory"
|
||||||
else
|
else
|
||||||
TEST_PATHNAME="${IMAGE_DIR}/${CHROMEOS_TEST_IMAGE_NAME}"
|
TEST_PATHNAME="$IMAGE_DIR/$CHROMEOS_TEST_IMAGE_NAME"
|
||||||
typename="test"
|
typename="test"
|
||||||
fi
|
fi
|
||||||
if [ ! -f "${TEST_PATHNAME}" ] || \
|
if [ ! -f "$TEST_PATHNAME" -o $FLAGS_force_copy -eq $FLAGS_TRUE ] ; then
|
||||||
[ ${FLAGS_force_copy} -eq ${FLAGS_TRUE} ] ; then
|
|
||||||
echo "Creating test image from original..."
|
echo "Creating test image from original..."
|
||||||
${COMMON_PV_CAT} "${FLAGS_image}" >"${TEST_PATHNAME}" \
|
$COMMON_PV_CAT "$FLAGS_image" >"$TEST_PATHNAME" ||
|
||||||
|| die "Cannot copy ${FLAGS_image} to test image"
|
die "Cannot copy $FLAGS_image to test image"
|
||||||
FLAGS_image="${TEST_PATHNAME}"
|
FLAGS_image="$TEST_PATHNAME"
|
||||||
else
|
else
|
||||||
echo "Using cached ${typename} image"
|
echo "Using cached $typename image"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -198,25 +195,25 @@ fi
|
|||||||
|
|
||||||
# Make sure this is really what the user wants, before nuking the device
|
# 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
|
||||||
read -p "Modifying image ${FLAGS_image} for test; are you sure (y/N)? " SURE
|
read -p "Modifying image $FLAGS_image for test; are you sure (y/N)? " SURE
|
||||||
SURE="${SURE:0:1}" # Get just the first character
|
SURE="${SURE:0:1}" # Get just the first character
|
||||||
if [ "$SURE" != "y" ]; then
|
if [ "$SURE" != "y" ]; then
|
||||||
echo "Ok, better safe than sorry."
|
echo "Ok, better safe than sorry."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "Modifying image ${FLAGS_image} for test..."
|
echo "Modifying image $FLAGS_image for test..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Abort early if we can't find the image
|
# Abort early if we can't find the image
|
||||||
if [ ! -f $FLAGS_image ] && [ ${FLAGS_inplace} -eq ${FLAGS_TRUE} ; then
|
if [ ! -f $FLAGS_image -a $FLAGS_inplace -eq $FLAGS_TRUE ] ; then
|
||||||
die "No image found at $FLAGS_image to modify"
|
die "No image found at $FLAGS_image to modify"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
IMAGE_DIR=$(dirname "$FLAGS_image")
|
IMAGE_DIR=$(dirname "$FLAGS_image")
|
||||||
IMAGE_NAME="$(basename "$FLAGS_image")"
|
IMAGE_NAME=$(basename "$FLAGS_image")
|
||||||
ROOT_FS_DIR="$IMAGE_DIR/rootfs"
|
ROOT_FS_DIR="$IMAGE_DIR/rootfs"
|
||||||
STATEFUL_DIR="$IMAGE_DIR/stateful_partition"
|
STATEFUL_DIR="$IMAGE_DIR/stateful_partition"
|
||||||
|
|
||||||
@ -228,27 +225,26 @@ trap cleanup EXIT
|
|||||||
|
|
||||||
emerge_chromeos_test
|
emerge_chromeos_test
|
||||||
|
|
||||||
MOD_TEST_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts"
|
MOD_TEST_SCRIPT="$SCRIPTS_DIR/mod_for_test_scripts/test_setup.sh"
|
||||||
# Run test setup script to modify the image
|
# Run test setup script to modify the image
|
||||||
sudo GCLIENT_ROOT="${GCLIENT_ROOT}" ROOT_FS_DIR="${ROOT_FS_DIR}" \
|
sudo GCLIENT_ROOT="$GCLIENT_ROOT" ROOT_FS_DIR="$ROOT_FS_DIR" \
|
||||||
STATEFUL_DIR="${STATEFUL_DIR}" ARCH="${ARCH}" "${MOD_TEST_ROOT}/test_setup.sh"
|
STATEFUL_DIR="$STATEFUL_DIR" ARCH="$ARCH" "$MOD_TEST_SCRIPT"
|
||||||
|
|
||||||
if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ]; then
|
if [ $FLAGS_factory -eq $FLAGS_TRUE ]; then
|
||||||
install_autotest
|
install_autotest
|
||||||
|
|
||||||
MOD_FACTORY_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_factory_scripts"
|
MOD_FACTORY_SCRIPT="$SCRIPTS_DIR/mod_for_factory_scripts/factory_setup.sh"
|
||||||
# Run factory setup script to modify the image
|
# Run factory setup script to modify the image
|
||||||
sudo GCLIENT_ROOT="${GCLIENT_ROOT}" ROOT_FS_DIR="${ROOT_FS_DIR}" \
|
sudo GCLIENT_ROOT="$GCLIENT_ROOT" ROOT_FS_DIR="$ROOT_FS_DIR" \
|
||||||
QUALDB="${FLAGS_qualdb}" BOARD=${FLAGS_board} \
|
QUALDB="$FLAGS_qualdb" BOARD=$FLAGS_board "$MOD_FACTORY_SCRIPT"
|
||||||
"${MOD_FACTORY_ROOT}/factory_setup.sh"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Re-run ldconfig to fix /etc/ldconfig.so.cache.
|
# Re-run ldconfig to fix /etc/ldconfig.so.cache.
|
||||||
sudo /sbin/ldconfig -r "${ROOT_FS_DIR}"
|
sudo ldconfig -r "$ROOT_FS_DIR"
|
||||||
|
|
||||||
# Let's have a look at the image just in case..
|
# Let's have a look at the image just in case..
|
||||||
if [ "${VERIFY}" = "true" ]; then
|
if [ "$VERIFY" = "true" ]; then
|
||||||
pushd "${ROOT_FS_DIR}"
|
pushd "$ROOT_FS_DIR"
|
||||||
bash
|
bash
|
||||||
popd
|
popd
|
||||||
fi
|
fi
|
||||||
@ -256,10 +252,9 @@ fi
|
|||||||
cleanup
|
cleanup
|
||||||
|
|
||||||
# Now make it bootable with the flags from build_image
|
# 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}")
|
"$(basename "$FLAGS_image")"
|
||||||
|
|
||||||
print_time_elapsed
|
print_time_elapsed
|
||||||
|
|
||||||
trap - EXIT
|
trap - EXIT
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user