blob: 8df2ffb65b71fbd3a7bb8ade7f632c9b47ecd22a [file] [log] [blame]
Brian Harringf539bc32012-02-06 00:18:37 -08001#!/bin/bash
2
Matt Tennant0a9d32d2012-07-30 16:51:37 -07003# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Brian Harringf539bc32012-02-06 00:18:37 -08004# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# This script sets up a Gentoo chroot environment. The script is passed the
8# path to an empty folder, which will be populated with a Gentoo stage3 and
9# setup for development. Once created, the password is set to PASSWORD (below).
10# One can enter the chrooted environment for work by running enter_chroot.sh.
11
12SCRIPT_ROOT=$(readlink -f $(dirname "$0")/..)
13. "${SCRIPT_ROOT}/common.sh" || exit 1
14
Brian Harring35767822012-02-01 23:50:45 -080015ENTER_CHROOT=$(readlink -f $(dirname "$0")/enter_chroot.sh)
16
Zdenek Behan4d21a292012-08-17 04:02:29 +020017if [ -n "${USE}" ]; then
18 echo "$SCRIPT_NAME: Building with a non-empty USE: ${USE}"
19 echo "This modifies the expected behaviour and can fail."
20fi
21
Brian Harringf539bc32012-02-06 00:18:37 -080022# Check if the host machine architecture is supported.
23ARCHITECTURE="$(uname -m)"
24if [[ "$ARCHITECTURE" != "x86_64" ]]; then
25 echo "$SCRIPT_NAME: $ARCHITECTURE is not supported as a host machine architecture."
26 exit 1
27fi
28
David James76764882012-10-24 19:46:29 -070029# Script must be run outside the chroot and as root.
Brian Harringf539bc32012-02-06 00:18:37 -080030assert_outside_chroot
David James76764882012-10-24 19:46:29 -070031assert_root_user
Brian Harringf539bc32012-02-06 00:18:37 -080032
Brian Harring35767822012-02-01 23:50:45 -080033# Define command line flags.
Brian Harringf539bc32012-02-06 00:18:37 -080034# See http://code.google.com/p/shflags/wiki/Documentation10x
35
36DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \
37 "Destination dir for the chroot environment."
38DEFINE_boolean usepkg $FLAGS_TRUE "Use binary packages to bootstrap."
39DEFINE_boolean delete $FLAGS_FALSE "Delete an existing chroot."
40DEFINE_boolean replace $FLAGS_FALSE "Overwrite existing chroot, if any."
41DEFINE_integer jobs -1 "How many packages to build in parallel at maximum."
Brian Harringf539bc32012-02-06 00:18:37 -080042DEFINE_string stage3_path "" \
43 "Use the stage3 located on this path."
Brian Harring7b6f3772012-09-23 14:01:13 -070044DEFINE_string cache_dir "" "Directory to store caches within."
Benjamin Gordon1d5afed2017-06-14 16:35:32 -060045DEFINE_boolean useimage $FLAGS_FALSE "Mount the chroot on a loopback image."
Brian Harringf539bc32012-02-06 00:18:37 -080046
Brian Harring35767822012-02-01 23:50:45 -080047# Parse command line flags.
Brian Harringf539bc32012-02-06 00:18:37 -080048FLAGS_HELP="usage: $SCRIPT_NAME [flags]"
49FLAGS "$@" || exit 1
50eval set -- "${FLAGS_ARGV}"
51check_flags_only_and_allow_null_arg "$@" && set --
52
Peter Mayo4411efe2012-09-21 04:41:27 -040053CROS_LOG_PREFIX=cros_sdk:make_chroot
David Purselld35d7af2015-05-04 16:37:08 -070054SUDO_HOME=$(eval echo ~"${SUDO_USER}")
Brian Harringf539bc32012-02-06 00:18:37 -080055
Brian Harringf539bc32012-02-06 00:18:37 -080056# Set the right umask for chroot creation.
57umask 022
58
59# Only now can we die on error. shflags functions leak non-zero error codes,
Brian Harring7f175a52012-03-02 05:37:00 -080060# so will die prematurely if 'switch_to_strict_mode' is specified before now.
Brian Harringf539bc32012-02-06 00:18:37 -080061# TODO: replace shflags with something less error-prone, or contribute a fix.
Brian Harring7f175a52012-03-02 05:37:00 -080062switch_to_strict_mode
Brian Harringf539bc32012-02-06 00:18:37 -080063
Brian Harring7b6f3772012-09-23 14:01:13 -070064[[ "${FLAGS_delete}" == "${FLAGS_FALSE}" ]] && \
65 [[ -z "${FLAGS_cache_dir}" ]] && \
66 die "--cache_dir is required"
67
J. Richard Barnettee80f6de2012-02-24 14:08:34 -080068. "${SCRIPT_ROOT}"/sdk_lib/make_conf_util.sh
69
David Purselld35d7af2015-05-04 16:37:08 -070070PRIMARY_GROUP=$(id -g -n "${SUDO_USER}")
71PRIMARY_GROUP_ID=$(id -g "${SUDO_USER}")
72
Brian Harringf539bc32012-02-06 00:18:37 -080073FULLNAME="ChromeOS Developer"
David Purselld35d7af2015-05-04 16:37:08 -070074DEFGROUPS="${PRIMARY_GROUP},adm,cdrom,floppy,audio,video,portage"
75
Brian Harringf539bc32012-02-06 00:18:37 -080076USEPKG=""
77if [[ $FLAGS_usepkg -eq $FLAGS_TRUE ]]; then
78 # Use binary packages. Include all build-time dependencies,
79 # so as to avoid unnecessary differences between source
80 # and binary builds.
81 USEPKG="--getbinpkg --usepkg --with-bdeps y"
82fi
83
Bertrand SIMONNET4dda4f52015-03-19 13:40:58 -070084EMERGE_CMD="${CHROOT_TRUNK_DIR}/chromite/bin/parallel_emerge"
Brian Harringf539bc32012-02-06 00:18:37 -080085
Brian Harring35767822012-02-01 23:50:45 -080086ENTER_CHROOT_ARGS=(
87 CROS_WORKON_SRCROOT="$CHROOT_TRUNK"
David James76764882012-10-24 19:46:29 -070088 PORTAGE_USERNAME="${SUDO_USER}"
Brian Harring35767822012-02-01 23:50:45 -080089 IGNORE_PREFLIGHT_BINHOST="$IGNORE_PREFLIGHT_BINHOST"
90)
91
92# Invoke enter_chroot. This can only be used after sudo has been installed.
Mike Frysinger6b1abb22012-05-11 13:44:06 -040093enter_chroot() {
Mike Frysinger7d88be92018-12-20 17:50:07 -050094 echo "[enter_chroot] $*"
Brian Harring7b6f3772012-09-23 14:01:13 -070095 "$ENTER_CHROOT" --cache_dir "${FLAGS_cache_dir}" --chroot "$FLAGS_chroot" \
96 -- "${ENTER_CHROOT_ARGS[@]}" "$@"
Brian Harringf539bc32012-02-06 00:18:37 -080097}
98
Brian Harring35767822012-02-01 23:50:45 -080099# Invoke enter_chroot running the command as root, and w/out sudo.
100# This should be used prior to sudo being merged.
Mike Frysingerba758452012-04-02 13:28:31 -0400101early_env=()
Mike Frysinger6b1abb22012-05-11 13:44:06 -0400102early_enter_chroot() {
Mike Frysinger7d88be92018-12-20 17:50:07 -0500103 echo "[early_enter_chroot] $*"
Brian Harring35767822012-02-01 23:50:45 -0800104 "$ENTER_CHROOT" --chroot "$FLAGS_chroot" --early_make_chroot \
Brian Harring7b6f3772012-09-23 14:01:13 -0700105 --cache_dir "${FLAGS_cache_dir}" \
Mike Frysingerba758452012-04-02 13:28:31 -0400106 -- "${ENTER_CHROOT_ARGS[@]}" "${early_env[@]}" "$@"
Brian Harringf539bc32012-02-06 00:18:37 -0800107}
108
Mike Frysinger4bb86452013-08-02 13:44:18 -0400109# Run a command within the chroot. The main usage of this is to avoid the
110# overhead of enter_chroot. It's when we do not need access to the source
111# tree, don't need the actual chroot profile env, and can run the command as
112# root. We do have to make sure PATH includes all the right programs as
113# found inside of the chroot since the environment outside of the chroot
114# might be insufficient (like distros with merged /bin /sbin and /usr).
David James76764882012-10-24 19:46:29 -0700115bare_chroot() {
David Purselld35d7af2015-05-04 16:37:08 -0700116 PATH="/bin:/sbin:/usr/bin:/usr/sbin:${PATH}" \
Mike Frysinger4bb86452013-08-02 13:44:18 -0400117 chroot "${FLAGS_chroot}" "$@"
Brian Harringf539bc32012-02-06 00:18:37 -0800118}
119
Mike Frysinger6b1abb22012-05-11 13:44:06 -0400120cleanup() {
Brian Harringf539bc32012-02-06 00:18:37 -0800121 # Clean up mounts
122 safe_umount_tree "${FLAGS_chroot}"
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600123
124 # Destroy LVM loopback setup if we can find a VG associated with our path.
125 local chroot_img="${FLAGS_chroot}.img"
126 [[ -f "$chroot_img" ]] || return 0
127
128 local chroot_dev=$(losetup -j "$chroot_img" | cut -f1 -d:)
129 local chroot_vg=$(find_vg_name "$FLAGS_chroot" "$chroot_dev")
130 if [ -n "$chroot_vg" ] && vgs "$chroot_vg" >&/dev/null; then
131 info "Removing VG $chroot_vg."
132 vgremove -f "$chroot_vg" --noudevsync
133 fi
134 if [ -n "$chroot_dev" ]; then
135 info "Detaching $chroot_dev."
136 losetup -d "$chroot_dev"
137 fi
Brian Harringf539bc32012-02-06 00:18:37 -0800138}
139
Mike Frysinger6b1abb22012-05-11 13:44:06 -0400140delete_existing() {
Brian Harring35767822012-02-01 23:50:45 -0800141 # Delete old chroot dir.
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600142 local chroot_img="${FLAGS_chroot}.img"
143 if [[ ! -e "$FLAGS_chroot" && ! -f "$chroot_img" ]]; then
Brian Harring35767822012-02-01 23:50:45 -0800144 return
Brian Harringf539bc32012-02-06 00:18:37 -0800145 fi
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600146 info "Cleaning up old mount points and loopback device..."
Brian Harring35767822012-02-01 23:50:45 -0800147 cleanup
148 info "Deleting $FLAGS_chroot..."
David James76764882012-10-24 19:46:29 -0700149 rm -rf "$FLAGS_chroot"
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600150 if [[ -f "$chroot_img" ]]; then
151 info "Deleting $chroot_img..."
152 rm -f "$chroot_img"
153 fi
Brian Harring35767822012-02-01 23:50:45 -0800154 info "Done."
Brian Harringf539bc32012-02-06 00:18:37 -0800155}
156
Mike Frysinger6b1abb22012-05-11 13:44:06 -0400157init_users () {
Brian Harring35767822012-02-01 23:50:45 -0800158 info "Set timezone..."
159 # date +%Z has trouble with daylight time, so use host's info.
David James76764882012-10-24 19:46:29 -0700160 rm -f "${FLAGS_chroot}/etc/localtime"
Brian Harringf539bc32012-02-06 00:18:37 -0800161 if [ -f /etc/localtime ] ; then
David James76764882012-10-24 19:46:29 -0700162 cp /etc/localtime "${FLAGS_chroot}/etc"
Brian Harringf539bc32012-02-06 00:18:37 -0800163 else
David James76764882012-10-24 19:46:29 -0700164 ln -sf /usr/share/zoneinfo/PST8PDT "${FLAGS_chroot}/etc/localtime"
Brian Harringf539bc32012-02-06 00:18:37 -0800165 fi
Brian Harring35767822012-02-01 23:50:45 -0800166 info "Adding user/group..."
David Purselld35d7af2015-05-04 16:37:08 -0700167 # Add the necessary groups to the chroot.
168 # Duplicate GIDs are allowed here in order to ensure that the required
169 # groups are the same inside and outside the chroot.
170 # TODO(dpursell): Handle when PRIMARY_GROUP exists in the chroot already
171 # with a different GID; groupadd will not create the new GID in that case.
172 bare_chroot groupadd -f -o -g "${PRIMARY_GROUP_ID}" "${PRIMARY_GROUP}"
Brian Harringf539bc32012-02-06 00:18:37 -0800173 # Add ourselves as a user inside the chroot.
Brian Harringf539bc32012-02-06 00:18:37 -0800174 # We need the UID to match the host user's. This can conflict with
175 # a particular chroot UID. At the same time, the added user has to
176 # be a primary user for the given UID for sudo to work, which is
177 # determined by the order in /etc/passwd. Let's put ourselves on top
178 # of the file.
David Purselld35d7af2015-05-04 16:37:08 -0700179 bare_chroot useradd -o -G "${DEFGROUPS}" -g "${PRIMARY_GROUP}" \
180 -u "${SUDO_UID}" -s /bin/bash -m -c "${FULLNAME}" "${SUDO_USER}"
Brian Harringf539bc32012-02-06 00:18:37 -0800181 # Because passwd generally isn't sorted and the entry ended up at the
182 # bottom, it is safe to just take it and move it to top instead.
David James76764882012-10-24 19:46:29 -0700183 sed -e '1{h;d};$!{H;d};$G' -i "${FLAGS_chroot}/etc/passwd"
Brian Harringf539bc32012-02-06 00:18:37 -0800184}
185
Mike Frysinger6b1abb22012-05-11 13:44:06 -0400186init_setup () {
Brian Harring35767822012-02-01 23:50:45 -0800187 info "Running init_setup()..."
David James76764882012-10-24 19:46:29 -0700188 mkdir -p -m 755 "${FLAGS_chroot}/usr" \
Mike Frysingerb45dbb52013-12-13 21:14:09 -0500189 "${FLAGS_chroot}${OVERLAYS_ROOT}" \
Mike Frysinger36beaaa2014-09-25 15:52:27 -0400190 "${FLAGS_chroot}"/"${CROSSDEV_OVERLAY}/metadata"
191 # Newer portage complains about bare overlays. Create the file that crossdev
192 # will also create later on.
193 cat <<EOF > "${FLAGS_chroot}/${CROSSDEV_OVERLAY}/metadata/layout.conf"
194# Autogenerated and managed by crossdev
195# Delete the above line if you want to manage this file yourself
196masters = portage-stable chromiumos
197repo-name = crossdev
198use-manifests = true
199thin-manifests = true
200EOF
Mike Frysingerb45dbb52013-12-13 21:14:09 -0500201 ln -sf "${CHROOT_TRUNK_DIR}/src/third_party/eclass-overlay" \
202 "${FLAGS_chroot}"/"${ECLASS_OVERLAY}"
Brian Harring2499bfb2012-12-18 16:23:31 -0800203 ln -sf "${CHROOT_TRUNK_DIR}/src/third_party/chromiumos-overlay" \
Brian Harringf539bc32012-02-06 00:18:37 -0800204 "${FLAGS_chroot}"/"${CHROOT_OVERLAY}"
Brian Harring2499bfb2012-12-18 16:23:31 -0800205 ln -sf "${CHROOT_TRUNK_DIR}/src/third_party/portage-stable" \
Brian Harringf539bc32012-02-06 00:18:37 -0800206 "${FLAGS_chroot}"/"${PORTAGE_STABLE_OVERLAY}"
Brian Harringf539bc32012-02-06 00:18:37 -0800207
Brian Harring35767822012-02-01 23:50:45 -0800208 # Some operations need an mtab.
Mike Frysingerb47a4ff2013-02-20 17:29:05 -0500209 ln -sfT /proc/mounts "${FLAGS_chroot}/etc/mtab"
Brian Harringf539bc32012-02-06 00:18:37 -0800210
211 # Set up sudoers. Inside the chroot, the user can sudo without a password.
212 # (Safe enough, since the only way into the chroot is to 'sudo chroot', so
213 # the user's already typed in one sudo password...)
214 # Make sure the sudoers.d subdir exists as older stage3 base images lack it.
David James76764882012-10-24 19:46:29 -0700215 mkdir -p "${FLAGS_chroot}/etc/sudoers.d"
Brian Harring06d3c2e2012-08-23 07:35:43 -0700216
217 # Use the standardized upgrade script to setup proxied vars.
David James76764882012-10-24 19:46:29 -0700218 load_environment_whitelist
Mike Frysinger6b05da92018-08-05 01:22:12 -0400219 bash "${SCRIPT_ROOT}/chroot_version_hooks.d/153_rewrite_sudoers.d" \
David James76764882012-10-24 19:46:29 -0700220 "${FLAGS_chroot}" "${SUDO_USER}" "${ENVIRONMENT_WHITELIST[@]}"
Brian Harring06d3c2e2012-08-23 07:35:43 -0700221
David James76764882012-10-24 19:46:29 -0700222 find "${FLAGS_chroot}/etc/"sudoers* -type f -exec chmod 0440 {} +
Brian Harring35767822012-02-01 23:50:45 -0800223 # Fix bad group for some.
David James76764882012-10-24 19:46:29 -0700224 chown -R root:root "${FLAGS_chroot}/etc/"sudoers*
Brian Harringf539bc32012-02-06 00:18:37 -0800225
Brian Harring35767822012-02-01 23:50:45 -0800226 info "Setting up hosts/resolv..."
227 # Copy config from outside chroot into chroot.
David James76764882012-10-24 19:46:29 -0700228 cp /etc/{hosts,resolv.conf} "$FLAGS_chroot/etc/"
229 chmod 0644 "$FLAGS_chroot"/etc/{hosts,resolv.conf}
Brian Harringf539bc32012-02-06 00:18:37 -0800230
231 # Setup host make.conf. This includes any overlay that we may be using
232 # and a pointer to pre-built packages.
Brian Harring35767822012-02-01 23:50:45 -0800233 # TODO: This should really be part of a profile in the portage.
234 info "Setting up /etc/make.*..."
Mike Frysinger53f79bb2014-04-05 22:27:52 -0400235 rm -f "${FLAGS_chroot}"/etc/{,portage/}make.{conf,profile}{,.catalyst}
Mike Frysingerc6e1ace2013-03-22 00:49:30 -0400236 mkdir -p "${FLAGS_chroot}/etc/portage"
David James76764882012-10-24 19:46:29 -0700237 ln -sf "${CHROOT_CONFIG}/make.conf.amd64-host" \
Brian Harringf539bc32012-02-06 00:18:37 -0800238 "${FLAGS_chroot}/etc/make.conf"
Mike Frysinger411b2422014-06-04 11:49:17 -0400239 ln -sf "${CHROOT_OVERLAY}/profiles/default/linux/amd64/10.0/sdk" \
Mike Frysingere9b40072015-05-19 05:07:04 -0400240 "${FLAGS_chroot}/etc/portage/make.profile"
Brian Harringf539bc32012-02-06 00:18:37 -0800241
Brian Harring35767822012-02-01 23:50:45 -0800242 # Create make.conf.user .
Alex Kleina28439c2019-01-14 14:48:30 -0700243 cat <<EOF > "${FLAGS_chroot}"/etc/make.conf.user
244# This file is useful for doing global (chroot and all board) changes.
245# Tweak emerge settings, ebuild env, etc...
246#
247# Make sure to append variables unless you really want to clobber all
248# existing settings. e.g. You most likely want:
249# FEATURES="${FEATURES} ..."
250# USE="${USE} foo"
251# and *not*:
252# USE="foo"
253#
254# This also is a good place to setup ACCEPT_LICENSE.
255EOF
David James76764882012-10-24 19:46:29 -0700256 chmod 0644 "${FLAGS_chroot}"/etc/make.conf.user
Brian Harringf539bc32012-02-06 00:18:37 -0800257
258 # Create directories referred to by our conf files.
David James76764882012-10-24 19:46:29 -0700259 mkdir -p -m 775 "${FLAGS_chroot}/var/lib/portage/pkgs" \
Brian Harring7b6f3772012-09-23 14:01:13 -0700260 "${FLAGS_chroot}/var/cache/"chromeos-{cache,chrome} \
261 "${FLAGS_chroot}/etc/profile.d"
262
David James76764882012-10-24 19:46:29 -0700263 echo "export CHROMEOS_CACHEDIR=/var/cache/chromeos-cache" > \
264 "${FLAGS_chroot}/etc/profile.d/chromeos-cachedir.sh"
265 chmod 0644 "${FLAGS_chroot}/etc/profile.d/chromeos-cachedir.sh"
266 rm -rf "${FLAGS_chroot}/var/cache/distfiles"
267 ln -s chromeos-cache/distfiles "${FLAGS_chroot}/var/cache/distfiles"
Brian Harring36b102b2012-02-06 23:34:25 -0800268
269 # Run this from w/in the chroot so we use whatever uid/gid
270 # these are defined as w/in the chroot.
David James76764882012-10-24 19:46:29 -0700271 bare_chroot chown "${SUDO_USER}:portage" /var/cache/chromeos-chrome
Brian Harring7ee892d2012-02-02 09:33:10 -0800272
273 # These are created for compatibility while transitioning
274 # make.conf and friends over to the new location.
Brian Harring7b6f3772012-09-23 14:01:13 -0700275 # TODO(ferringb): remove this 01/13 or so.
David James76764882012-10-24 19:46:29 -0700276 ln -s ../../cache/chromeos-cache/distfiles/host \
Brian Harring7ee892d2012-02-02 09:33:10 -0800277 "${FLAGS_chroot}/var/lib/portage/distfiles"
David James76764882012-10-24 19:46:29 -0700278 ln -s ../../cache/chromeos-cache/distfiles/target \
Brian Harring7ee892d2012-02-02 09:33:10 -0800279 "${FLAGS_chroot}/var/lib/portage/distfiles-target"
Brian Harringf539bc32012-02-06 00:18:37 -0800280
Brian Harringf539bc32012-02-06 00:18:37 -0800281 # Add chromite/bin and depot_tools into the path globally; note that the
282 # chromite wrapper itself might also be found in depot_tools.
283 # We rely on 'env-update' getting called below.
284 target="${FLAGS_chroot}/etc/env.d/99chromiumos"
David James76764882012-10-24 19:46:29 -0700285 cat <<EOF > "${target}"
David Purselld35d7af2015-05-04 16:37:08 -0700286PATH="${CHROOT_TRUNK_DIR}/chromite/bin:${DEPOT_TOOLS_DIR}"
Brian Harring2499bfb2012-12-18 16:23:31 -0800287CROS_WORKON_SRCROOT="${CHROOT_TRUNK_DIR}"
David Purselld35d7af2015-05-04 16:37:08 -0700288PORTAGE_USERNAME="${SUDO_USER}"
Brian Harringf539bc32012-02-06 00:18:37 -0800289EOF
290
291 # TODO(zbehan): Configure stuff that is usually configured in postinst's,
Mike Frysingereb1a9b42012-03-28 16:21:04 -0400292 # but wasn't. Fix the postinst's.
Brian Harring35767822012-02-01 23:50:45 -0800293 info "Running post-inst configuration hacks"
294 early_enter_chroot env-update
Brian Harringf539bc32012-02-06 00:18:37 -0800295
Brian Harring35767822012-02-01 23:50:45 -0800296 # This is basically a sanity check of our chroot. If any of these
297 # don't exist, then either bind mounts have failed, an invocation
298 # from above is broke, or some assumption about the stage3 is no longer
299 # true.
Mike Frysingere9b40072015-05-19 05:07:04 -0400300 early_enter_chroot ls -l /etc/make.conf /etc/portage/make.profile \
Brian Harring35767822012-02-01 23:50:45 -0800301 /usr/local/portage/chromiumos/profiles/default/linux/amd64/10.0
Brian Harringf539bc32012-02-06 00:18:37 -0800302
303 target="${FLAGS_chroot}/etc/profile.d"
David James76764882012-10-24 19:46:29 -0700304 mkdir -p "${target}"
305 cat << EOF > "${target}/chromiumos-niceties.sh"
Brian Harringf539bc32012-02-06 00:18:37 -0800306# Niceties for interactive logins. (cr) denotes this is a chroot, the
307# __git_branch_ps1 prints current git branch in ./ . The $r behavior is to
308# make sure we don't reset the previous $? value which later formats in
309# $PS1 might rely on.
310PS1='\$(r=\$?; __git_branch_ps1 "(%s) "; exit \$r)'"\${PS1}"
311PS1="(cr) \${PS1}"
312EOF
313
314 # Select a small set of locales for the user if they haven't done so
315 # already. This makes glibc upgrades cheap by only generating a small
316 # set of locales. The ones listed here are basically for the buildbots
317 # which always assume these are available. This works in conjunction
318 # with `cros_sdk --enter`.
319 # http://crosbug.com/20378
320 local localegen="$FLAGS_chroot/etc/locale.gen"
321 if ! grep -q -v -e '^#' -e '^$' "${localegen}" ; then
David James76764882012-10-24 19:46:29 -0700322 cat <<EOF >> "${localegen}"
Brian Harringf539bc32012-02-06 00:18:37 -0800323en_US ISO-8859-1
324en_US.UTF-8 UTF-8
325EOF
326 fi
327
Brian Harring35767822012-02-01 23:50:45 -0800328 # Automatically change to scripts directory.
Brian Harringf539bc32012-02-06 00:18:37 -0800329 echo 'cd ${CHROOT_CWD:-~/trunk/src/scripts}' \
David Purselld35d7af2015-05-04 16:37:08 -0700330 | user_append "${FLAGS_chroot}/home/${SUDO_USER}/.bash_profile"
Brian Harringf539bc32012-02-06 00:18:37 -0800331
Brian Harring35767822012-02-01 23:50:45 -0800332 # Enable bash completion for build scripts.
Brian Harringf539bc32012-02-06 00:18:37 -0800333 echo ". ~/trunk/src/scripts/bash_completion" \
David Purselld35d7af2015-05-04 16:37:08 -0700334 | user_append "${FLAGS_chroot}/home/${SUDO_USER}/.bashrc"
Brian Harringf539bc32012-02-06 00:18:37 -0800335
Peter Mayoe18c7d42013-06-06 13:41:03 -0400336 if [[ "${SUDO_USER}" = "chrome-bot" && -d "${SUDO_HOME}/.ssh" ]]; then
Brian Harringf539bc32012-02-06 00:18:37 -0800337 # Copy ssh keys, so chroot'd chrome-bot can scp files from chrome-web.
Peter Mayo31056952013-06-06 16:22:55 -0400338 user_cp -rp "${SUDO_HOME}/.ssh" "$FLAGS_chroot/home/${SUDO_USER}/"
Brian Harringf539bc32012-02-06 00:18:37 -0800339 fi
340
David Purselld35d7af2015-05-04 16:37:08 -0700341 if [[ -f "${SUDO_HOME}/.cros_chroot_init" ]]; then
342 sudo -u "${SUDO_USER}" -- /bin/bash "${SUDO_HOME}/.cros_chroot_init" \
David James76764882012-10-24 19:46:29 -0700343 "${FLAGS_chroot}"
Luigi Semenzato2443fdd2012-05-29 10:34:04 -0700344 fi
Yunlian Jiangf219bb32018-04-30 16:24:22 -0700345
346 # Update nsswitch.conf to make glibc-2.26 and after builds. See
347 # https://wiki.gentoo.org/wiki/Project:Toolchain/nsswitch.conf_in_glibc-2.26
348 if ! grep compat "${FLAGS_chroot}/etc/nsswitch.conf" | grep -q files; then
349 sed -i 's/\<compat\>/compat files/g' "${FLAGS_chroot}/etc/nsswitch.conf"
350 fi
Brian Harringf539bc32012-02-06 00:18:37 -0800351}
352
Gilad Arnold01d458b2015-05-28 06:41:08 -0700353unpack_tarball() {
354 local tarball_path="$1"
355 local dest_dir="$2"
356 local decompress
357 case "${tarball_path}" in
358 *.tbz2|*.tar.bz2) decompress=$(type -p pbzip2 || echo bzip2) ;;
Mike Frysinger978efbf2018-12-20 16:43:26 -0500359 *.tar.xz) decompress=$(type -p pixz || echo xz) ;;
Gilad Arnold01d458b2015-05-28 06:41:08 -0700360 *) die "Unknown tarball compression: ${tarball_path}" ;;
361 esac
Mike Frysinger978efbf2018-12-20 16:43:26 -0500362 ${decompress} -dc <"${tarball_path}" | tar -xp -C "${dest_dir}"
Gilad Arnold01d458b2015-05-28 06:41:08 -0700363}
364
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600365# Find a usable VG name for a given path and device. If there is an existing
366# VG associated with the device, it will be returned. If not, find an unused
367# name in the format cros_<safe_path>_NNN, where safe_path is an escaped version
368# of the last 90 characters of the path and NNN is a counter. Example:
369# /home/user/chromiumos/chroot/ -> cros_home+user+chromiumos+chroot_000.
370# If no unused name with this pattern can be found, return an empty string.
371find_vg_name() {
372 local chroot_path="$1"
373 local chroot_dev="$2"
374 chroot_path=${chroot_path##/}
375 chroot_path=${chroot_path%%/}
376 chroot_path=${chroot_path//[^A-Za-z0-9_+.-]/+}
377 chroot_path=${chroot_path: -$((${#chroot_path} < 90 ? ${#chroot_path} : 90))}
378 local vg_name=""
379 if [ -n "$chroot_dev" ]; then
380 vg_name=$(pvs -q --noheadings -o vg_name "$chroot_dev" 2>/dev/null | \
381 sed -e 's/^ *//')
382 fi
383 if [ -z "$vg_name" ]; then
384 local counter=0
385 vg_name=$(printf "cros_%s_%03d" "$chroot_path" "$counter")
386 while [ "$counter" -lt 1000 ] && vgs "$vg_name" >&/dev/null; do
387 counter=$((counter + 1))
388 vg_name=$(printf "cros_%s_%03d" "$chroot_path" "$counter")
389 done
390 if [ "$counter" -gt 999 ]; then
391 vg_name=""
392 fi
393 fi
394 echo "$vg_name"
395}
396
397# Create a loopback image and mount it on the chroot path so that we can take
398# snapshots before building. If an image already exists, try to mount it. The
399# chroot is initially mounted inside a temporary shared chroot.build subtree
400# that should have already been set up by the parent process, and then bind
401# mounted into the correct final location. The purpose of this indirection is
402# so that processes outside our mount namespace can see the top-level chroot
403# after we finish.
404mount_chroot_image() {
405 local chroot_image="$1"
406 local mount_path="$2"
407
408 # Make sure there's an image.
409 local existing_chroot=0
410 local chroot_dev=""
411 if [ -f "$chroot_image" ]; then
412 info "Attempting to reuse existing image file ${chroot_image}"
413 chroot_dev=$(losetup -j "$chroot_image" | cut -f1 -d:)
414 existing_chroot=1
415 else
416 dd if=/dev/null of="$chroot_image" bs=1G seek=500 >&/dev/null
417 fi
418
419 # Get/scan a loopback device attached to our image.
420 if [ -n "$chroot_dev" ]; then
421 pvscan -q "$chroot_dev" >&/dev/null
422 else
423 chroot_dev=$(losetup -f "$chroot_image" --show)
424 fi
425
426 # Find/create a VG on the loopback device.
427 chroot_vg=$(find_vg_name "$mount_path" "$chroot_dev")
428 if [ -z "$chroot_vg" ]; then
429 die_notrace "Unable to find usable VG name for ${mount_path}."
430 fi
431 if vgs "$chroot_vg" >&/dev/null; then
Benjamin Gordonf68aa942017-07-21 17:00:20 -0600432 vgchange -q -a y --noudevsync "$chroot_vg" >/dev/null || :
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600433 else
434 vgcreate -q "$chroot_vg" "$chroot_dev" >/dev/null
435 fi
436
437 # Find/create an LV inside our VG. If the LV is new, also create the FS.
438 # We need to pass --noudevsync to lvcreate because we're running inside
439 # a separate IPC namespace from the udev process.
440 if lvs "$chroot_vg/chroot" >&/dev/null; then
Benjamin Gordonf68aa942017-07-21 17:00:20 -0600441 lvchange -q -ay "$chroot_vg/chroot" --noudevsync >/dev/null || :
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600442 else
443 lvcreate -q -L 499G -T "${chroot_vg}/thinpool" -V500G -n chroot \
444 --noudevsync >/dev/null
445 mke2fs -q -m 0 -t ext4 "/dev/${chroot_vg}/chroot"
446 fi
447
448 # Mount the FS into a directory that should have been set up as a shared
449 # subtree by our parent process, then bind mount it into the place where
450 # it belongs. The parent will take care of moving the mount to the correct
451 # final place on the outside of our mount namespace after we exit.
452 local temp_chroot="${FLAGS_chroot}.build/chroot"
453 if ! mount -text4 -onoatime "/dev/${chroot_vg}/chroot" "$temp_chroot"; then
454 local chroot_example_opt=""
455 if [[ "$mount_path" != "$DEFAULT_CHROOT_DIR" ]]; then
456 chroot_example_opt="--chroot=$FLAGS_chroot"
457 fi
458
459 die_notrace <<EOF
460
461Unable to mount ${chroot_vg}/chroot on ${temp_chroot}. Check for corrupted
462image ${chroot_image}, or run
463
464cros_sdk --delete $chroot_example_opt
465
466to clean up an old chroot first.
467
468EOF
469 fi
470 mount --make-private "$temp_chroot"
471 mount --bind "$temp_chroot" "$mount_path"
472 mount --make-private "$mount_path"
473 if [ "$existing_chroot" = "1" ]; then
474 info "Mounted existing chroot image."
475 fi
476}
477
Brian Harring35767822012-02-01 23:50:45 -0800478# Handle deleting an existing environment.
Brian Harringf539bc32012-02-06 00:18:37 -0800479if [[ $FLAGS_delete -eq $FLAGS_TRUE || \
Brian Harring35767822012-02-01 23:50:45 -0800480 $FLAGS_replace -eq $FLAGS_TRUE ]]; then
Brian Harringf539bc32012-02-06 00:18:37 -0800481 delete_existing
482 [[ $FLAGS_delete -eq $FLAGS_TRUE ]] && exit 0
483fi
484
485CHROOT_TRUNK="${CHROOT_TRUNK_DIR}"
486PORTAGE="${SRC_ROOT}/third_party/portage"
487OVERLAY="${SRC_ROOT}/third_party/chromiumos-overlay"
488CONFIG_DIR="${OVERLAY}/chromeos/config"
Brian Harring2499bfb2012-12-18 16:23:31 -0800489CHROOT_CONFIG="${CHROOT_TRUNK_DIR}/src/third_party/chromiumos-overlay/chromeos/config"
Mike Frysingerb45dbb52013-12-13 21:14:09 -0500490OVERLAYS_ROOT="/usr/local/portage"
491ECLASS_OVERLAY="${OVERLAYS_ROOT}/eclass-overlay"
492PORTAGE_STABLE_OVERLAY="${OVERLAYS_ROOT}/stable"
493CROSSDEV_OVERLAY="${OVERLAYS_ROOT}/crossdev"
494CHROOT_OVERLAY="${OVERLAYS_ROOT}/chromiumos"
Brian Harringf539bc32012-02-06 00:18:37 -0800495CHROOT_STATE="${FLAGS_chroot}/etc/debian_chroot"
Vincent Palatin5ce24062014-02-26 12:08:23 -0800496CHROOT_VERSION="${FLAGS_chroot}/etc/cros_chroot_version"
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600497CHROOT_IMAGE="${FLAGS_chroot}.img"
Brian Harringf539bc32012-02-06 00:18:37 -0800498
499# Pass proxy variables into the environment.
500for type in http ftp all; do
David Purselld35d7af2015-05-04 16:37:08 -0700501 value=$(env | grep "${type}_proxy" || true)
Brian Harringf539bc32012-02-06 00:18:37 -0800502 if [ -n "${value}" ]; then
503 CHROOT_PASSTHRU+=("$value")
504 fi
505done
506
Brian Harring35767822012-02-01 23:50:45 -0800507# Create the destination directory.
Brian Harringf539bc32012-02-06 00:18:37 -0800508mkdir -p "$FLAGS_chroot"
509
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600510[[ $FLAGS_useimage -eq $FLAGS_TRUE ]] && \
511 mount_chroot_image "$CHROOT_IMAGE" "$FLAGS_chroot"
512
513# If the version contains something non-zero, we were already created and this
514# is just a re-mount.
515[[ -f "$CHROOT_VERSION" && "$(<$CHROOT_VERSION)" != "0" ]] && exit 0
516
Brian Harringf539bc32012-02-06 00:18:37 -0800517echo
David Purselld35d7af2015-05-04 16:37:08 -0700518if [[ -f "${CHROOT_STATE}" ]]; then
Mike Frysinger51930072014-04-05 13:01:45 -0400519 info "stage3 already set up. Skipping..."
David Purselld35d7af2015-05-04 16:37:08 -0700520elif [[ -z "${FLAGS_stage3_path}" ]]; then
Mike Frysinger51930072014-04-05 13:01:45 -0400521 die_notrace "Please use --stage3_path when bootstrapping"
Brian Harringf539bc32012-02-06 00:18:37 -0800522else
Mike Frysinger51930072014-04-05 13:01:45 -0400523 info "Unpacking stage3..."
Gilad Arnold01d458b2015-05-28 06:41:08 -0700524 unpack_tarball "${FLAGS_stage3_path}" "${FLAGS_chroot}"
David James76764882012-10-24 19:46:29 -0700525 rm -f "$FLAGS_chroot/etc/"make.{globals,conf.user}
Brian Harringf539bc32012-02-06 00:18:37 -0800526fi
527
Vincent Palatin5ce24062014-02-26 12:08:23 -0800528# Ensure that we properly detect when we are inside the chroot.
529# We'll force this to the latest version at the end as needed.
David Purselld35d7af2015-05-04 16:37:08 -0700530if [[ ! -e "${CHROOT_VERSION}" ]]; then
Vincent Palatin5ce24062014-02-26 12:08:23 -0800531 echo "0" > "${CHROOT_VERSION}"
532fi
533
Brian Harring35767822012-02-01 23:50:45 -0800534# Set up users, if needed, before mkdir/mounts below.
Brian Harringf539bc32012-02-06 00:18:37 -0800535[ -f $CHROOT_STATE ] || init_users
536
Brian Harring2499bfb2012-12-18 16:23:31 -0800537# Reset internal vars to force them to the 'inside the chroot' value;
538# since user directories now exist, this can do the upgrade in place.
539set_chroot_trunk_dir "${FLAGS_chroot}" poppycock
540
Brian Harringf539bc32012-02-06 00:18:37 -0800541echo
Brian Harring35767822012-02-01 23:50:45 -0800542info "Setting up mounts..."
543# Set up necessary mounts and make sure we clean them up on exit.
Brian Harring2499bfb2012-12-18 16:23:31 -0800544mkdir -p "${FLAGS_chroot}/${CHROOT_TRUNK_DIR}" \
545 "${FLAGS_chroot}/${DEPOT_TOOLS_DIR}" "${FLAGS_chroot}/run"
Brian Harring35767822012-02-01 23:50:45 -0800546
J. Richard Barnettee80f6de2012-02-24 14:08:34 -0800547# Create a special /etc/make.conf.host_setup that we use to bootstrap
548# the chroot. The regular content for the file will be generated the
549# first time we invoke update_chroot (further down in this script).
550create_bootstrap_host_setup "${FLAGS_chroot}"
Brian Harringf539bc32012-02-06 00:18:37 -0800551
552if ! [ -f "$CHROOT_STATE" ];then
553 INITIALIZE_CHROOT=1
554fi
555
Mike Frysingerba758452012-04-02 13:28:31 -0400556if ! early_enter_chroot bash -c 'type -P pbzip2' >/dev/null ; then
557 # This chroot lacks pbzip2 early on, so we need to disable it.
558 early_env+=(
559 PORTAGE_BZIP2_COMMAND="bzip2"
560 PORTAGE_BUNZIP2_COMMAND="bunzip2"
561 )
562fi
563
Brian Harringf539bc32012-02-06 00:18:37 -0800564if [ -z "${INITIALIZE_CHROOT}" ];then
Brian Harring35767822012-02-01 23:50:45 -0800565 info "chroot already initialized. Skipping..."
Brian Harringf539bc32012-02-06 00:18:37 -0800566else
Brian Harring35767822012-02-01 23:50:45 -0800567 # Run all the init stuff to setup the env.
Brian Harringf539bc32012-02-06 00:18:37 -0800568 init_setup
569fi
570
Brian Harring35767822012-02-01 23:50:45 -0800571# Add file to indicate that it is a chroot.
Mike Frysinger51930072014-04-05 13:01:45 -0400572# Add version of stage3 for update checks.
573echo "STAGE3=${FLAGS_stage3_path}" > "${CHROOT_STATE}"
Brian Harringf539bc32012-02-06 00:18:37 -0800574
Daniel Kurtz51244842017-07-25 01:32:04 +0800575# TODO(crbug.com/747810): Remove this once stage3 is updated past 2015-Q1.
576# The 2014.09.18 stage3 uses app-admin/eselect-python, but in 2015-Q1 it moved
577# to app-eselect/eselect-python. Since portage depends on python-exec, and
578# python-exec depends on eselect-python, update python and related packages
579# before portage.
580info "Updating python"
Jason D. Clinton78d28d92018-01-19 17:43:39 -0700581early_enter_chroot emerge -uNv --quiet python:2.7 python
Daniel Kurtz51244842017-07-25 01:32:04 +0800582
583# New versions of the stage3 have Python 3 set as the default. Make sure we
584# default to 2.x as our scripts are only compatible with Python 2. We leave
585# Python 3 installed though as we've started including it in our SDK.
586# We can't just "set 1" because the option order changes for different stage3
587# tarballs.
588early_enter_chroot eselect python update --ignore "3*"
589
Brian Harring35767822012-02-01 23:50:45 -0800590info "Updating portage"
Mike Frysinger66fd81f2012-02-28 13:13:20 -0500591early_enter_chroot emerge -uNv --quiet portage
Brian Harringf539bc32012-02-06 00:18:37 -0800592
Mike Frysinger9a2978c2013-08-04 11:38:43 -0400593# Clear out openrc if it's installed as we don't want it.
David Purselld35d7af2015-05-04 16:37:08 -0700594if [[ -e "${FLAGS_chroot}/usr/share/openrc" ]]; then
Mike Frysinger9a2978c2013-08-04 11:38:43 -0400595 info "Uninstalling openrc"
596 early_enter_chroot env CLEAN_DELAY=0 emerge -qC sys-apps/openrc
Mike Frysinger47e599e2013-10-28 13:30:12 -0400597 # Now update baselayout to get our functions.sh. The unmerge
598 # above removed our copy in the process.
599 early_enter_chroot emerge -uNvq sys-apps/baselayout
Mike Frysinger9a2978c2013-08-04 11:38:43 -0400600fi
601
Bertrand SIMONNET85c96c72014-08-20 12:10:48 -0700602# Add chromite into python path.
Bertrand SIMONNET85c96c72014-08-20 12:10:48 -0700603for python_path in "${FLAGS_chroot}/usr/lib/"python2.*; do
604 python_path+="/site-packages"
605 sudo mkdir -p "${python_path}"
606 sudo ln -s -fT "${CHROOT_TRUNK_DIR}"/chromite "${python_path}"/chromite
607done
608
Chirantan Ekboteaf1b9502016-07-14 11:29:16 -0700609# The stage3 contains an old version of ncurses, which causes a slot conflict
610# later when we try to setup the toolchains. Update it here to the latest
611# version, which gracefully handles the slot issues.
612info "Updating ncurses"
613early_enter_chroot emerge -uNvq sys-libs/ncurses
614
Manoj Gupta63ee9f52018-05-11 18:09:37 -0700615# Update these packages early because they cause build failures when they're
616# concurrently emerged during the main update below.
617# Specific packages:
618# sys-apps/sandbox upgrade breaks dev-libs/nss, also needed by newer libtool.
619# sys-devel/patch 2.6 misapplies git patches in dev-embedded/coreboot-sdk.
620# older sys-devel/automake makes media-libs/freetype build flaky.
621# glibc 2.26+ needs a newer bison.
622info "Updating preinstalled build tools"
623early_enter_chroot ${EMERGE_CMD} -uNv ${USEPKG} --select ${EMERGE_JOBS} \
624 sys-apps/sandbox '>=sys-devel/patch-2.7' sys-devel/automake sys-devel/bison
625
Mike Frysingeraf95b612018-12-20 17:08:19 -0500626# Now that many of the fundamental packages should be in a good state, update
627# the host toolchain. We have to do this step by step ourselves to avoid races
628# when building tools that are actively used (e.g. updating the assembler while
629# also compiling other packages that use the assembler).
630# https://crbug.com/715788
Zdenek Behan2fbd5af2012-03-12 19:38:50 +0100631info "Updating host toolchain"
David Purselld35d7af2015-05-04 16:37:08 -0700632if [[ ! -e "${FLAGS_chroot}/usr/bin/crossdev" ]]; then
Mike Frysinger5e07dc72014-11-05 14:40:04 -0500633 early_enter_chroot $EMERGE_CMD -uNv crossdev
634fi
Zdenek Behan2fbd5af2012-03-12 19:38:50 +0100635TOOLCHAIN_ARGS=( --deleteold )
David Purselld35d7af2015-05-04 16:37:08 -0700636if [[ "${FLAGS_usepkg}" == "${FLAGS_FALSE}" ]]; then
Zdenek Behan2fbd5af2012-03-12 19:38:50 +0100637 TOOLCHAIN_ARGS+=( --nousepkg )
638fi
Mike Frysingeraf95b612018-12-20 17:08:19 -0500639# First the low level compiler tools. These should be fairly independent of
640# the C library, so we can do it first.
641early_enter_chroot ${EMERGE_CMD} -uNv ${EMERGE_JOBS} \
642 sys-devel/binutils
643# Next the C library. The compilers often use newer features, but the C library
644# is often designed to work with older compilers.
645early_enter_chroot ${EMERGE_CMD} -uNv ${EMERGE_JOBS} \
646 sys-kernel/linux-headers sys-libs/glibc
647# Now we can let the rest of the compiler packages build in parallel as they
648# don't generally rely on each other.
Zdenek Behan2fbd5af2012-03-12 19:38:50 +0100649# Note: early_enter_chroot executes as root.
Brian Harring2499bfb2012-12-18 16:23:31 -0800650early_enter_chroot "${CHROOT_TRUNK_DIR}/chromite/bin/cros_setup_toolchains" \
Zdenek Behan2fbd5af2012-03-12 19:38:50 +0100651 --hostonly "${TOOLCHAIN_ARGS[@]}"
Brian Harringf539bc32012-02-06 00:18:37 -0800652
Ben Chan0c9da662017-05-15 17:29:51 -0700653info "Running emerge curl sudo gentoolkit ..."
Mike Frysinger650bf872012-02-27 11:05:26 -0500654early_enter_chroot $EMERGE_CMD -uNv $USEPKG --select $EMERGE_JOBS \
Ben Chan0c9da662017-05-15 17:29:51 -0700655 pbzip2 dev-libs/openssl net-misc/curl sudo app-portage/gentoolkit
656
657info "Updating Perl modules"
658early_enter_chroot \
659 "${CHROOT_TRUNK_DIR}/src/scripts/build_library/perl_rebuild.sh"
Paul Drews8bae3b52012-10-10 11:18:13 -0700660
Brian Harringf539bc32012-02-06 00:18:37 -0800661if [ -n "${INITIALIZE_CHROOT}" ]; then
662 # If we're creating a new chroot, we also want to set it to the latest
663 # version.
Alex Kleine5e0ea92018-09-13 17:18:15 -0600664 enter_chroot run_chroot_version_hooks --init-latest
Brian Harringf539bc32012-02-06 00:18:37 -0800665fi
666
Brian Harring35767822012-02-01 23:50:45 -0800667# Update chroot.
Zdenek Behan2fbd5af2012-03-12 19:38:50 +0100668# Skip toolchain update because it already happened above, and the chroot is
669# not ready to emerge all cross toolchains.
670UPDATE_ARGS=( --skip_toolchain_update )
David Purselld35d7af2015-05-04 16:37:08 -0700671if [[ "${FLAGS_usepkg}" == "${FLAGS_TRUE}" ]]; then
Brian Harring35767822012-02-01 23:50:45 -0800672 UPDATE_ARGS+=( --usepkg )
Brian Harringf539bc32012-02-06 00:18:37 -0800673else
Brian Harring35767822012-02-01 23:50:45 -0800674 UPDATE_ARGS+=( --nousepkg )
Brian Harringf539bc32012-02-06 00:18:37 -0800675fi
David James184e3902012-02-23 20:19:28 -0800676if [[ "${FLAGS_jobs}" -ne -1 ]]; then
David Purselld35d7af2015-05-04 16:37:08 -0700677 UPDATE_ARGS+=( --jobs="${FLAGS_jobs}" )
David James184e3902012-02-23 20:19:28 -0800678fi
Brian Harring2499bfb2012-12-18 16:23:31 -0800679enter_chroot "${CHROOT_TRUNK_DIR}/src/scripts/update_chroot" "${UPDATE_ARGS[@]}"
Brian Harringf539bc32012-02-06 00:18:37 -0800680
Stefan Zager48c776b2013-10-09 13:01:25 -0700681# The java-config package atm does not support $ROOT. Select a default
682# VM ourselves until that gets fixed upstream.
683enter_chroot sudo java-config --set-system-vm 1
684
Brian Harring35767822012-02-01 23:50:45 -0800685CHROOT_EXAMPLE_OPT=""
686if [[ "$FLAGS_chroot" != "$DEFAULT_CHROOT_DIR" ]]; then
Brian Harringf539bc32012-02-06 00:18:37 -0800687 CHROOT_EXAMPLE_OPT="--chroot=$FLAGS_chroot"
688fi
689
Matt Tennant0a9d32d2012-07-30 16:51:37 -0700690command_completed
Brian Harringf539bc32012-02-06 00:18:37 -0800691
Brian Harring35767822012-02-01 23:50:45 -0800692cat <<EOF
Mike Frysingerbdc4fb12012-02-10 11:20:03 -0500693
694${CROS_LOG_PREFIX:-cros_sdk}: All set up. To enter the chroot, run:
695$ cros_sdk --enter $CHROOT_EXAMPLE_OPT
Brian Harring35767822012-02-01 23:50:45 -0800696
697CAUTION: Do *NOT* rm -rf the chroot directory; if there are stale bind
698mounts you may end up deleting your source tree too. To unmount and
699delete the chroot cleanly, use:
700$ cros_sdk --delete $CHROOT_EXAMPLE_OPT
Mike Frysingerbdc4fb12012-02-10 11:20:03 -0500701
Brian Harring35767822012-02-01 23:50:45 -0800702EOF
David James22dc2ba2012-11-29 15:46:58 -0800703
704warn_if_nfs "${SUDO_HOME}"