#!/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. . "$(dirname "$0")/common.sh" || exit 1 # Script must run inside the chroot assert_inside_chroot "$@" # Do not run as root assert_not_root_user DEFINE_boolean usepkg "${FLAGS_TRUE}" \ "Use binary packages when possible." DEFINE_boolean getbinpkg "${FLAGS_TRUE}" \ "Download binary packages from remote repository." DEFINE_boolean usepkgonly "${FLAGS_FALSE}" \ "Only use/download binary packages. Implies --noworkon" DEFINE_boolean workon "${FLAGS_TRUE}" \ "Automatically rebuild updated cros-workon packages." DEFINE_integer jobs "${NUM_JOBS}" \ "How many packages to build in parallel at maximum." DEFINE_boolean skip_toolchain_update "${FLAGS_FALSE}" \ "Don't update the toolchains." DEFINE_string toolchain_boards "" \ "Extra toolchains to setup for the specified boards." FLAGS_HELP="usage: $(basename $0) [flags] Performs an update of the chroot. This script is called as part of build_packages, so there is typically no need to call this script directly. " # 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 'switch_to_strict_mode' is specified before now. switch_to_strict_mode if [[ "${FLAGS_usepkgonly}" -eq "${FLAGS_TRUE}" ]]; then for flag in usepkg getbinpkg; do fvar="FLAGS_${flag}" if [[ "${!fvar}" -ne "${FLAGS_TRUE}" ]]; then die_notrace "--usepkgonly is incompatible with --no${flag}" fi done FLAGS_workon="${FLAGS_FALSE}" fi . "${BUILD_LIBRARY_DIR}/toolchain_util.sh" PORTAGE_STABLE_OVERLAY="${REPO_ROOT}/src/third_party/portage-stable" CROSSDEV_OVERLAY="/usr/local/portage/crossdev" COREOS_OVERLAY="${REPO_ROOT}/src/third_party/coreos-overlay" COREOS_CONFIG="${COREOS_OVERLAY}/coreos/config" # PORTAGE_USERNAME may already be in the env but set just to be safe. : ${PORTAGE_USERNAME:=${USER}} # Clean up old distfiles cache. It used to be split for 'host' and # 'target' but that just duplicates files. Also a ccache was in there. if [[ -d "${REPO_CACHE_DIR}/distfiles/host" ]]; then info "Cleaning up old distfiles cache..." sudo mv "${REPO_CACHE_DIR}"/{distfiles/host,distfiles.host} sudo rm -rf "${REPO_CACHE_DIR}/distfiles" sudo mv "${REPO_CACHE_DIR}"/{distfiles.host,distfiles} fi info "Setting up portage..." sudo mkdir -p "${REPO_CACHE_DIR}/distfiles" sudo chown "${PORTAGE_USERNAME}:portage" "${REPO_CACHE_DIR}/distfiles" sudo mkdir -p /etc/portage/repos.conf /var/lib/portage/pkgs sudo touch /etc/portage/make.conf.user sudo_clobber "/etc/portage/make.conf" <=dev-lang/perl-5.21'; then EMERGE_FLAGS+=( --reinstall-atoms='dev-perl/File-Slurp dev-perl/Locale-gettext perl-core/File-Temp' --usepkg-exclude='dev-perl/File-Slurp dev-perl/Locale-gettext perl-core/File-Temp' ) fi # Perform an update of coreos-devel/sdk-depends and world in the chroot. EMERGE_CMD="emerge" # In first pass, update portage and toolchains. Lagged updates of both # can cause serious issues later. info "Updating basic system packages" sudo -E ${EMERGE_CMD} --quiet "${EMERGE_FLAGS[@]}" \ dev-util/ccache \ sys-apps/portage \ sys-devel/crossdev \ sys-devel/sysroot-wrappers \ sys-libs/nss-usrfiles \ "${TOOLCHAIN_PKGS[@]}" gcc_set_latest_profile "$(portageq envvar CHOST)" if [[ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_FALSE}" && \ -n "${FLAGS_toolchain_boards}" ]]; then CROSS_CHOSTS=( $(get_board_chost ${FLAGS_toolchain_boards} | sort -u) ) # double check get_board_chost actually returned results, pipefail isn't set. [[ -n "${CROSS_CHOSTS[*]}" ]] || exit 1 for cross_chost in "${CROSS_CHOSTS[@]}"; do info "Updating cross ${cross_chost} toolchain" install_cross_toolchain "${cross_chost}" --quiet "${EMERGE_FLAGS[@]}" done fi # Build cros_workon packages when they are changed. CHROMITE_BIN="${GCLIENT_ROOT}/chromite/bin" if [ "${FLAGS_workon}" -eq "${FLAGS_TRUE}" ]; then for pkg in $("${CHROMITE_BIN}/cros_list_modified_packages" --host); do EMERGE_FLAGS+=( "--reinstall-atoms=${pkg}" "--usepkg-exclude=${pkg}" ) done fi # Second pass, update everything else. EMERGE_FLAGS+=( --deep ) info "Updating all SDK packages" sudo -E ${EMERGE_CMD} "${EMERGE_FLAGS[@]}" \ coreos-devel/sdk-depends world info "Removing obsolete packages" sudo -E ${EMERGE_CMD} --quiet --depclean @unavailable if portageq list_preserved_libs / >/dev/null; then info "Rebuilding packages linked against old libraries" sudo -E ${EMERGE_CMD} "${REBUILD_FLAGS[@]}" @preserved-rebuild fi # 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 # Old $PS1 customization that doesn't work any more if [[ -e /etc/profile.d/coreos-niceties.sh ]]; then sudo rm -f /etc/profile.d/coreos-niceties.sh fi command_completed