mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-07 04:56:58 +02:00
Another fix for 10d98e7
. Empty values must be quoted, otherwise the
tokenizer gets confused and everything falls apart. :(
223 lines
7.2 KiB
Bash
Executable File
223 lines
7.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Copyright (c) 2012 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.
|
|
|
|
# Script to build a bootable keyfob-based chromeos system image from within
|
|
# a coreos setup. This assumes that all needed packages have been built into
|
|
# the given target's root with binary packages turned on. This script will
|
|
# build the Chrome OS image using only pre-built binary packages.
|
|
|
|
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
|
|
. "${SCRIPT_ROOT}/common.sh" || exit 1
|
|
|
|
# Script must run inside the chroot
|
|
restart_in_chroot_if_needed "$@"
|
|
|
|
assert_not_root_user
|
|
|
|
DEFAULT_GROUP=developer
|
|
if [[ ${COREOS_OFFICIAL:-0} -eq 1 ]]; then
|
|
DEFAULT_GROUP=alpha
|
|
fi
|
|
|
|
# Developer-visible flags.
|
|
DEFINE_string board "${DEFAULT_BOARD}" \
|
|
"The board to build an image for."
|
|
DEFINE_string boot_args "" \
|
|
"Additional boot arguments to pass to the commandline"
|
|
DEFINE_boolean enable_rootfs_verification ${FLAGS_TRUE} \
|
|
"Default all bootloaders to use kernel-based root fs integrity checking."
|
|
DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/images" \
|
|
"Directory in which to place image result directories (named by version)"
|
|
DEFINE_string disk_layout "base" \
|
|
"The disk layout type to use for this image."
|
|
DEFINE_string group "${DEFAULT_GROUP}" \
|
|
"The update group."
|
|
DEFINE_boolean generate_update "${FLAGS_FALSE}" \
|
|
"Generate update payload. (prod only)"
|
|
|
|
# include upload options
|
|
. "${BUILD_LIBRARY_DIR}/release_util.sh" || exit 1
|
|
|
|
FLAGS_HELP="USAGE: build_image [flags] [list of images to build].
|
|
This script is used to build a CoreOS image. CoreOS comes in many
|
|
different forms. This scripts can be used to build the following:
|
|
|
|
base - Pristine CoreOS image for generating update payloads or a dev/prod image.
|
|
prod - Production image for CoreOS. This image is for booting.
|
|
dev - Developer image. Like base but with additional developer packages.
|
|
|
|
Examples:
|
|
|
|
build_image --board=<board> dev prod - builds developer and production images.
|
|
...
|
|
"
|
|
show_help_if_requested "$@"
|
|
|
|
# The following options are advanced options, only available to those willing
|
|
# to read the source code. They are not shown in help output, since they are
|
|
# not needed for the typical developer workflow.
|
|
DEFINE_integer build_attempt 1 \
|
|
"The build attempt for this image build."
|
|
DEFINE_boolean fast ${FLAGS_TRUE} \
|
|
"Use the parallel_emerge wrapper script."
|
|
DEFINE_integer jobs "${NUM_JOBS}" \
|
|
"How many packages to build in parallel at maximum."
|
|
DEFINE_boolean replace ${FLAGS_FALSE} \
|
|
"Overwrite existing output, if any."
|
|
DEFINE_string symlink "latest" \
|
|
"Symlink name to use for this image."
|
|
DEFINE_string version "" \
|
|
"Overrides version number in name to this version."
|
|
|
|
# Parse command line.
|
|
FLAGS "$@" || exit 1
|
|
|
|
eval set -- "${FLAGS_ARGV}"
|
|
|
|
# Only now can we die on error. shflags functions leak non-zero error codes,
|
|
# so will die prematurely if 'switch_to_strict_mode' is specified before now.
|
|
switch_to_strict_mode
|
|
|
|
check_gsutil_opts
|
|
|
|
# N.B. Ordering matters for some of the libraries below, because
|
|
# some of the files contain initialization used by later files.
|
|
. "${BUILD_LIBRARY_DIR}/toolchain_util.sh" || exit 1
|
|
. "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1
|
|
. "${BUILD_LIBRARY_DIR}/build_image_util.sh" || exit 1
|
|
. "${BUILD_LIBRARY_DIR}/base_image_util.sh" || exit 1
|
|
. "${BUILD_LIBRARY_DIR}/prod_image_util.sh" || exit 1
|
|
. "${BUILD_LIBRARY_DIR}/dev_image_util.sh" || exit 1
|
|
. "${BUILD_LIBRARY_DIR}/test_image_content.sh" || exit 1
|
|
|
|
parse_build_image_args
|
|
|
|
BASE_PACKAGE="coreos-base/coreos"
|
|
|
|
PRISTINE_IMAGE_NAME=${CHROMEOS_BASE_IMAGE_NAME}
|
|
|
|
DEVKEYSDIR="/usr/share/vboot/devkeys"
|
|
|
|
eclean-$BOARD -d packages
|
|
|
|
if [[ ${skip_blacklist_check} -ne 1 ]]; then
|
|
check_blacklist
|
|
fi
|
|
|
|
# Check that the build root is sane.
|
|
if [[ ${skip_test_build_root} -ne 1 ]]; then
|
|
info "Checking build root"
|
|
test_image_content "${BOARD_ROOT}"
|
|
fi
|
|
|
|
# Hack to fix bug where x86_64 CHOST line gets incorrectly added.
|
|
# ToDo(msb): remove this hack.
|
|
PACKAGES_FILE="${BOARD_ROOT}/packages/Packages"
|
|
sudo sed -e "s/CHOST: x86_64-pc-linux-gnu//" -i "${PACKAGES_FILE}"
|
|
|
|
# Handle existing directory.
|
|
if [[ -e "${BUILD_DIR}" ]]; then
|
|
if [[ ${FLAGS_replace} -eq ${FLAGS_TRUE} ]]; then
|
|
sudo rm -rf "${BUILD_DIR}"
|
|
else
|
|
error "Directory ${BUILD_DIR} already exists."
|
|
error "Use --build_attempt option to specify an unused attempt."
|
|
error "Or use --replace if you want to overwrite this directory."
|
|
die "Unwilling to overwrite ${BUILD_DIR}."
|
|
fi
|
|
fi
|
|
|
|
# Create the output directory and temporary mount points.
|
|
mkdir -p "${BUILD_DIR}"
|
|
|
|
DISK_LAYOUT="${FLAGS_disk_layout:-base}"
|
|
|
|
# Create the base image.
|
|
create_base_image "${PRISTINE_IMAGE_NAME}" "${DISK_LAYOUT}" "${FLAGS_group}"
|
|
if should_build_image ${PRISTINE_IMAGE_NAME}; then
|
|
upload_image "${BUILD_DIR}/${PRISTINE_IMAGE_NAME}"
|
|
fi
|
|
|
|
# Running board-specific setup if any exists.
|
|
if type board_setup &>/dev/null; then
|
|
board_setup "${BUILD_DIR}/${PRISTINE_IMAGE_NAME}"
|
|
fi
|
|
|
|
# Create a developer image if an image that is based on it is requested.
|
|
if should_build_image ${CHROMEOS_DEVELOPER_IMAGE_NAME}; then
|
|
if should_build_image ${COREOS_PRODUCTION_IMAGE_NAME}; then
|
|
cp "${BUILD_DIR}/${PRISTINE_IMAGE_NAME}" \
|
|
"${BUILD_DIR}/${CHROMEOS_DEVELOPER_IMAGE_NAME}"
|
|
else
|
|
copy_image ${PRISTINE_IMAGE_NAME} ${CHROMEOS_DEVELOPER_IMAGE_NAME}
|
|
fi
|
|
install_dev_packages ${CHROMEOS_DEVELOPER_IMAGE_NAME} ${DISK_LAYOUT}
|
|
upload_image "${BUILD_DIR}/${CHROMEOS_DEVELOPER_IMAGE_NAME}"
|
|
fi
|
|
|
|
if should_build_image ${COREOS_PRODUCTION_IMAGE_NAME}; then
|
|
copy_image ${CHROMEOS_BASE_IMAGE_NAME} ${COREOS_PRODUCTION_IMAGE_NAME}
|
|
setup_prod_image ${COREOS_PRODUCTION_IMAGE_NAME} ${DISK_LAYOUT}
|
|
upload_image "${BUILD_DIR}/${COREOS_PRODUCTION_IMAGE_NAME}"
|
|
if [[ ${FLAGS_generate_update} -eq ${FLAGS_TRUE} ]]; then
|
|
generate_update "${COREOS_PRODUCTION_IMAGE_NAME}" ${DISK_LAYOUT}
|
|
fi
|
|
fi
|
|
|
|
if ! should_build_image ${PRISTINE_IMAGE_NAME}; then
|
|
rm -f "${BUILD_DIR}/${PRISTINE_IMAGE_NAME}"
|
|
fi
|
|
|
|
# Write out a version.txt file, this will be used by image_to_vm.sh
|
|
tee "${BUILD_DIR}/version.txt" <<EOF
|
|
COREOS_BUILD=${COREOS_BUILD}
|
|
COREOS_BRANCH=${COREOS_BRANCH}
|
|
COREOS_PATCH=${COREOS_PATCH}
|
|
COREOS_VERSION=${COREOS_VERSION_STRING}
|
|
COREOS_VERSION_ID=${COREOS_VERSION_ID}
|
|
COREOS_BUILD_ID="${COREOS_BUILD_ID}"
|
|
COREOS_SDK_VERSION=${COREOS_SDK_VERSION}
|
|
EOF
|
|
|
|
upload_image "${BUILD_DIR}/version.txt"
|
|
|
|
# Create a named symlink.
|
|
LINK_NAME="${FLAGS_output_root}/${BOARD}/${FLAGS_symlink}"
|
|
ln -sfT $(basename ${BUILD_DIR}) ${LINK_NAME}
|
|
|
|
echo "Done. Image(s) created in ${BUILD_DIR}"
|
|
|
|
print_image_to_vm() {
|
|
flags=
|
|
if [ $# = 1 ]; then
|
|
flags="--${1}_image"
|
|
fi
|
|
|
|
cat << EOF
|
|
To convert it to a virtual machine image, use:
|
|
./image_to_vm.sh --from=${OUTSIDE_OUTPUT_DIR} --board=${BOARD} ${flags}
|
|
|
|
The default type is qemu, see ./image_to_vm.sh --help for other options.
|
|
EOF
|
|
}
|
|
|
|
# Print out the images we generated.
|
|
if should_build_image ${COREOS_PRODUCTION_IMAGE_NAME}; then
|
|
echo "CoreOS Production image created as ${COREOS_PRODUCTION_IMAGE_NAME}"
|
|
print_image_to_vm "prod"
|
|
fi
|
|
if should_build_image ${CHROMEOS_BASE_IMAGE_NAME}; then
|
|
echo "Non-developer CoreOS image created as ${PRISTINE_IMAGE_NAME}"
|
|
fi
|
|
if should_build_image ${CHROMEOS_DEVELOPER_IMAGE_NAME}; then
|
|
echo "Developer image created as ${CHROMEOS_DEVELOPER_IMAGE_NAME}"
|
|
print_image_to_vm
|
|
fi
|
|
|
|
command_completed
|
|
|
|
|