#!/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" < 1632. cats=( '<=sys-devel' "${BOARD_CHOSTS[@]/#/<=cross-}" ) sudo -E emerge --quiet --unmerge "${cats[@]/%//binutils-2.29.0}" "${cats[@]/%//gcc-7.2.0}" 2>/dev/null || : 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