flatcar-scripts/update_chroot
J. Richard Barnette e80f6de440 Include the Chrome OS private overlay in the chroot, if present.
To build recovery images, the initramfs package needs fonts for
various languages.  The Japanese fonts to use depend on whether
it's an internal (Chrome OS) or external (Chromium OS) build.

Including the internal Japanese fonts requires additional settings
in /etc/make.conf in the chroot.  This change updates make_chroot
and update_chroot to ensure that the necessary settings are present
when appropriate.

BUG=chromium-os:26757
TEST=confirm proper packages after chroot creation with private manifest
TEST=confirm proper packages after chroot creation with public manifest
TEST=confirm proper packages after chroot upgrade with private manifest
TEST=confirm proper packages after chroot upgrade with public manifest
CQ-DEPEND=I32c4561c47752d96d2769c5429c5e44fe630f8f9

Change-Id: I2b29b32bf4e6b891a2228dc7f93ae0bb3f85e37f
Reviewed-on: https://gerrit.chromium.org/gerrit/17372
Tested-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: David James <davidjames@chromium.org>
Commit-Ready: Richard Barnette <jrbarnette@chromium.org>
2012-03-08 12:17:44 -08:00

109 lines
3.9 KiB
Bash
Executable File

#!/bin/bash
# Copyright (c) 2010 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.
# Performs an update of the chroot.
# 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.
. "$(dirname $0)/common.sh" || { echo "Unable to load common.sh"; exit 1; }
# Script must run inside the chroot
assert_inside_chroot "$@"
# Do not run as root
assert_not_root_user
# Flags
DEFINE_boolean usepkg $FLAGS_TRUE \
"Use binary packages to bootstrap."
DEFINE_boolean fast ${DEFAULT_FAST} "Call many emerges in parallel"
DEFINE_integer retries -1 \
"On build failure, the number of times to retry."
DEFINE_integer jobs -1 \
"How many packages to build in parallel at maximum."
# Parse command line flags
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 'set -e' is specified before now.
set -e
. ${SCRIPTS_DIR}/sdk_lib/make_conf_util.sh
# Run version hooks as pre-update
${SCRIPTS_DIR}/run_chroot_version_hooks
# Create /etc/make.conf.host_setup. The file content is regenerated
# from scratch every update. There are various reasons to do this:
# + It's cheap, so this is an easy way to guarantee correct content
# after an upgrade.
# + Inside make_chroot.sh, we use a temporary version of the file
# which must be updated before the script completes; that final
# update happens here.
# + If the repositories change to add or remove the private
# overlay, the file may need to be regenerated.
create_host_setup
info "Updating chroot"
EMERGE_FLAGS="-uNv --with-bdeps=y --select"
if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then
EMERGE_FLAGS="${EMERGE_FLAGS} --getbinpkg"
# Only update toolchain when binpkgs are available. Toolchain rollout
# process only takes place when the chromiumos sdk builder finishes
# a successful build.
EMERGE_FLAGS+=" --useoldpkg-atoms=sys-devel/binutils"
EMERGE_FLAGS+=" --useoldpkg-atoms=sys-devel/gcc"
EMERGE_FLAGS+=" --useoldpkg-atoms=sys-libs/glibc"
fi
if [[ "${FLAGS_jobs}" -ne -1 ]]; then
EMERGE_FLAGS+=" --jobs=${FLAGS_jobs}"
fi
# Perform an update of hard-host-depends and world in the chroot.
EMERGE_CMD="emerge"
if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then
EMERGE_CMD="${GCLIENT_ROOT}/chromite/bin/parallel_emerge"
fi
# In first pass, update portage and toolchains. Lagged updates of both
# can cause serious issues later.
CHOST="$(portageq envvar CHOST)"
LATEST="$(gcc-config -l | grep "${CHOST}" | awk '{ print $2 }' | \
sort -V | tail -n 1 )"
CURRENT="$(gcc-config -c)" || true # This fails if current profile is invalid.
eretry sudo -E ${EMERGE_CMD} ${EMERGE_FLAGS} \
sys-devel/gcc sys-devel/binutils sys-libs/glibc sys-apps/portage
# If the latest toolchain wasn't already selected before we updated, do nothing,
# otherwise autoselect the latest. Also fix if the current profile is invalid.
if [ "${LATEST}" = "${CURRENT}" ] || ! gcc-config -c &> /dev/null; then
LATEST="$(gcc-config -l | grep "${CHOST}" | awk '{ print $2 }' | \
sort -V | tail -n 1 )"
sudo gcc-config "${LATEST}"
fi
# Second pass, update everything else.
EMERGE_FLAGS+=" --deep"
eretry sudo -E ${EMERGE_CMD} ${EMERGE_FLAGS} \
chromeos-base/hard-host-depends world
# Automatically discard all CONFIG_PROTECT'ed files. Those that are
# protected should not be overwritten until the variable is changed.
# Autodiscard is option "-9" followed by the "YES" confirmation.
printf '%s\nYES\n' -9 | sudo etc-update
# If the user still has old perl modules installed, update them.
PERL_VERSIONS=$(find /usr/lib*/perl5/vendor_perl/ -maxdepth 1 -mindepth 1 \
-type d -printf '%P\n' | sort -u | wc -w)
if [ "$PERL_VERSIONS" -gt 1 ] ; then
sudo perl-cleaner --all -- --quiet
fi