blob: 0fcf36741852f81fed4005e6a919a394798977d3 [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_date "2010.03.09" \
43 "Use the stage3 with the given date."
44DEFINE_string stage3_path "" \
45 "Use the stage3 located on this path."
Gilad Arnold8c8e0852015-06-03 16:19:16 -070046DEFINE_string toolchains_overlay_path "" \
47 "Use the toolchains overlay located on this path."
Brian Harring7b6f3772012-09-23 14:01:13 -070048DEFINE_string cache_dir "" "Directory to store caches within."
Benjamin Gordon1d5afed2017-06-14 16:35:32 -060049DEFINE_boolean useimage $FLAGS_FALSE "Mount the chroot on a loopback image."
Brian Harringf539bc32012-02-06 00:18:37 -080050
Brian Harring35767822012-02-01 23:50:45 -080051# Parse command line flags.
Brian Harringf539bc32012-02-06 00:18:37 -080052FLAGS_HELP="usage: $SCRIPT_NAME [flags]"
53FLAGS "$@" || exit 1
54eval set -- "${FLAGS_ARGV}"
55check_flags_only_and_allow_null_arg "$@" && set --
56
Peter Mayo4411efe2012-09-21 04:41:27 -040057CROS_LOG_PREFIX=cros_sdk:make_chroot
David Purselld35d7af2015-05-04 16:37:08 -070058SUDO_HOME=$(eval echo ~"${SUDO_USER}")
Brian Harringf539bc32012-02-06 00:18:37 -080059
Brian Harringf539bc32012-02-06 00:18:37 -080060# Set the right umask for chroot creation.
61umask 022
62
63# Only now can we die on error. shflags functions leak non-zero error codes,
Brian Harring7f175a52012-03-02 05:37:00 -080064# so will die prematurely if 'switch_to_strict_mode' is specified before now.
Brian Harringf539bc32012-02-06 00:18:37 -080065# TODO: replace shflags with something less error-prone, or contribute a fix.
Brian Harring7f175a52012-03-02 05:37:00 -080066switch_to_strict_mode
Brian Harringf539bc32012-02-06 00:18:37 -080067
Brian Harring7b6f3772012-09-23 14:01:13 -070068[[ "${FLAGS_delete}" == "${FLAGS_FALSE}" ]] && \
69 [[ -z "${FLAGS_cache_dir}" ]] && \
70 die "--cache_dir is required"
71
J. Richard Barnettee80f6de2012-02-24 14:08:34 -080072. "${SCRIPT_ROOT}"/sdk_lib/make_conf_util.sh
73
David Purselld35d7af2015-05-04 16:37:08 -070074PRIMARY_GROUP=$(id -g -n "${SUDO_USER}")
75PRIMARY_GROUP_ID=$(id -g "${SUDO_USER}")
76
Brian Harringf539bc32012-02-06 00:18:37 -080077FULLNAME="ChromeOS Developer"
David Purselld35d7af2015-05-04 16:37:08 -070078DEFGROUPS="${PRIMARY_GROUP},adm,cdrom,floppy,audio,video,portage"
79
Brian Harringf539bc32012-02-06 00:18:37 -080080USEPKG=""
81if [[ $FLAGS_usepkg -eq $FLAGS_TRUE ]]; then
82 # Use binary packages. Include all build-time dependencies,
83 # so as to avoid unnecessary differences between source
84 # and binary builds.
85 USEPKG="--getbinpkg --usepkg --with-bdeps y"
86fi
87
Bertrand SIMONNET4dda4f52015-03-19 13:40:58 -070088EMERGE_CMD="${CHROOT_TRUNK_DIR}/chromite/bin/parallel_emerge"
Brian Harringf539bc32012-02-06 00:18:37 -080089
Brian Harring35767822012-02-01 23:50:45 -080090ENTER_CHROOT_ARGS=(
91 CROS_WORKON_SRCROOT="$CHROOT_TRUNK"
David James76764882012-10-24 19:46:29 -070092 PORTAGE_USERNAME="${SUDO_USER}"
Brian Harring35767822012-02-01 23:50:45 -080093 IGNORE_PREFLIGHT_BINHOST="$IGNORE_PREFLIGHT_BINHOST"
94)
95
96# Invoke enter_chroot. This can only be used after sudo has been installed.
Mike Frysinger6b1abb22012-05-11 13:44:06 -040097enter_chroot() {
Brian Harring7b6f3772012-09-23 14:01:13 -070098 "$ENTER_CHROOT" --cache_dir "${FLAGS_cache_dir}" --chroot "$FLAGS_chroot" \
99 -- "${ENTER_CHROOT_ARGS[@]}" "$@"
Brian Harringf539bc32012-02-06 00:18:37 -0800100}
101
Brian Harring35767822012-02-01 23:50:45 -0800102# Invoke enter_chroot running the command as root, and w/out sudo.
103# This should be used prior to sudo being merged.
Mike Frysingerba758452012-04-02 13:28:31 -0400104early_env=()
Mike Frysinger6b1abb22012-05-11 13:44:06 -0400105early_enter_chroot() {
Brian Harring35767822012-02-01 23:50:45 -0800106 "$ENTER_CHROOT" --chroot "$FLAGS_chroot" --early_make_chroot \
Brian Harring7b6f3772012-09-23 14:01:13 -0700107 --cache_dir "${FLAGS_cache_dir}" \
Mike Frysingerba758452012-04-02 13:28:31 -0400108 -- "${ENTER_CHROOT_ARGS[@]}" "${early_env[@]}" "$@"
Brian Harringf539bc32012-02-06 00:18:37 -0800109}
110
Mike Frysinger4bb86452013-08-02 13:44:18 -0400111# Run a command within the chroot. The main usage of this is to avoid the
112# overhead of enter_chroot. It's when we do not need access to the source
113# tree, don't need the actual chroot profile env, and can run the command as
114# root. We do have to make sure PATH includes all the right programs as
115# found inside of the chroot since the environment outside of the chroot
116# might be insufficient (like distros with merged /bin /sbin and /usr).
David James76764882012-10-24 19:46:29 -0700117bare_chroot() {
David Purselld35d7af2015-05-04 16:37:08 -0700118 PATH="/bin:/sbin:/usr/bin:/usr/sbin:${PATH}" \
Mike Frysinger4bb86452013-08-02 13:44:18 -0400119 chroot "${FLAGS_chroot}" "$@"
Brian Harringf539bc32012-02-06 00:18:37 -0800120}
121
Mike Frysinger6b1abb22012-05-11 13:44:06 -0400122cleanup() {
Brian Harringf539bc32012-02-06 00:18:37 -0800123 # Clean up mounts
124 safe_umount_tree "${FLAGS_chroot}"
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600125
126 # Destroy LVM loopback setup if we can find a VG associated with our path.
127 local chroot_img="${FLAGS_chroot}.img"
128 [[ -f "$chroot_img" ]] || return 0
129
130 local chroot_dev=$(losetup -j "$chroot_img" | cut -f1 -d:)
131 local chroot_vg=$(find_vg_name "$FLAGS_chroot" "$chroot_dev")
132 if [ -n "$chroot_vg" ] && vgs "$chroot_vg" >&/dev/null; then
133 info "Removing VG $chroot_vg."
134 vgremove -f "$chroot_vg" --noudevsync
135 fi
136 if [ -n "$chroot_dev" ]; then
137 info "Detaching $chroot_dev."
138 losetup -d "$chroot_dev"
139 fi
Brian Harringf539bc32012-02-06 00:18:37 -0800140}
141
Mike Frysinger6b1abb22012-05-11 13:44:06 -0400142delete_existing() {
Brian Harring35767822012-02-01 23:50:45 -0800143 # Delete old chroot dir.
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600144 local chroot_img="${FLAGS_chroot}.img"
145 if [[ ! -e "$FLAGS_chroot" && ! -f "$chroot_img" ]]; then
Brian Harring35767822012-02-01 23:50:45 -0800146 return
Brian Harringf539bc32012-02-06 00:18:37 -0800147 fi
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600148 info "Cleaning up old mount points and loopback device..."
Brian Harring35767822012-02-01 23:50:45 -0800149 cleanup
150 info "Deleting $FLAGS_chroot..."
David James76764882012-10-24 19:46:29 -0700151 rm -rf "$FLAGS_chroot"
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600152 if [[ -f "$chroot_img" ]]; then
153 info "Deleting $chroot_img..."
154 rm -f "$chroot_img"
155 fi
Brian Harring35767822012-02-01 23:50:45 -0800156 info "Done."
Brian Harringf539bc32012-02-06 00:18:37 -0800157}
158
Mike Frysinger6b1abb22012-05-11 13:44:06 -0400159init_users () {
Brian Harring35767822012-02-01 23:50:45 -0800160 info "Set timezone..."
161 # date +%Z has trouble with daylight time, so use host's info.
David James76764882012-10-24 19:46:29 -0700162 rm -f "${FLAGS_chroot}/etc/localtime"
Brian Harringf539bc32012-02-06 00:18:37 -0800163 if [ -f /etc/localtime ] ; then
David James76764882012-10-24 19:46:29 -0700164 cp /etc/localtime "${FLAGS_chroot}/etc"
Brian Harringf539bc32012-02-06 00:18:37 -0800165 else
David James76764882012-10-24 19:46:29 -0700166 ln -sf /usr/share/zoneinfo/PST8PDT "${FLAGS_chroot}/etc/localtime"
Brian Harringf539bc32012-02-06 00:18:37 -0800167 fi
Brian Harring35767822012-02-01 23:50:45 -0800168 info "Adding user/group..."
David Purselld35d7af2015-05-04 16:37:08 -0700169 # Add the necessary groups to the chroot.
170 # Duplicate GIDs are allowed here in order to ensure that the required
171 # groups are the same inside and outside the chroot.
172 # TODO(dpursell): Handle when PRIMARY_GROUP exists in the chroot already
173 # with a different GID; groupadd will not create the new GID in that case.
174 bare_chroot groupadd -f -o -g "${PRIMARY_GROUP_ID}" "${PRIMARY_GROUP}"
Brian Harringf539bc32012-02-06 00:18:37 -0800175 # Add ourselves as a user inside the chroot.
Brian Harringf539bc32012-02-06 00:18:37 -0800176 # We need the UID to match the host user's. This can conflict with
177 # a particular chroot UID. At the same time, the added user has to
178 # be a primary user for the given UID for sudo to work, which is
179 # determined by the order in /etc/passwd. Let's put ourselves on top
180 # of the file.
David Purselld35d7af2015-05-04 16:37:08 -0700181 bare_chroot useradd -o -G "${DEFGROUPS}" -g "${PRIMARY_GROUP}" \
182 -u "${SUDO_UID}" -s /bin/bash -m -c "${FULLNAME}" "${SUDO_USER}"
Brian Harringf539bc32012-02-06 00:18:37 -0800183 # Because passwd generally isn't sorted and the entry ended up at the
184 # bottom, it is safe to just take it and move it to top instead.
David James76764882012-10-24 19:46:29 -0700185 sed -e '1{h;d};$!{H;d};$G' -i "${FLAGS_chroot}/etc/passwd"
Brian Harringf539bc32012-02-06 00:18:37 -0800186}
187
Mike Frysinger6b1abb22012-05-11 13:44:06 -0400188init_setup () {
Brian Harring35767822012-02-01 23:50:45 -0800189 info "Running init_setup()..."
David James76764882012-10-24 19:46:29 -0700190 mkdir -p -m 755 "${FLAGS_chroot}/usr" \
Mike Frysingerb45dbb52013-12-13 21:14:09 -0500191 "${FLAGS_chroot}${OVERLAYS_ROOT}" \
Mike Frysinger36beaaa2014-09-25 15:52:27 -0400192 "${FLAGS_chroot}"/"${CROSSDEV_OVERLAY}/metadata"
193 # Newer portage complains about bare overlays. Create the file that crossdev
194 # will also create later on.
195 cat <<EOF > "${FLAGS_chroot}/${CROSSDEV_OVERLAY}/metadata/layout.conf"
196# Autogenerated and managed by crossdev
197# Delete the above line if you want to manage this file yourself
198masters = portage-stable chromiumos
199repo-name = crossdev
200use-manifests = true
201thin-manifests = true
202EOF
Mike Frysingerb45dbb52013-12-13 21:14:09 -0500203 ln -sf "${CHROOT_TRUNK_DIR}/src/third_party/eclass-overlay" \
204 "${FLAGS_chroot}"/"${ECLASS_OVERLAY}"
Brian Harring2499bfb2012-12-18 16:23:31 -0800205 ln -sf "${CHROOT_TRUNK_DIR}/src/third_party/chromiumos-overlay" \
Brian Harringf539bc32012-02-06 00:18:37 -0800206 "${FLAGS_chroot}"/"${CHROOT_OVERLAY}"
Brian Harring2499bfb2012-12-18 16:23:31 -0800207 ln -sf "${CHROOT_TRUNK_DIR}/src/third_party/portage-stable" \
Brian Harringf539bc32012-02-06 00:18:37 -0800208 "${FLAGS_chroot}"/"${PORTAGE_STABLE_OVERLAY}"
Brian Harringf539bc32012-02-06 00:18:37 -0800209
Brian Harring35767822012-02-01 23:50:45 -0800210 # Some operations need an mtab.
Mike Frysingerb47a4ff2013-02-20 17:29:05 -0500211 ln -sfT /proc/mounts "${FLAGS_chroot}/etc/mtab"
Brian Harringf539bc32012-02-06 00:18:37 -0800212
213 # Set up sudoers. Inside the chroot, the user can sudo without a password.
214 # (Safe enough, since the only way into the chroot is to 'sudo chroot', so
215 # the user's already typed in one sudo password...)
216 # Make sure the sudoers.d subdir exists as older stage3 base images lack it.
David James76764882012-10-24 19:46:29 -0700217 mkdir -p "${FLAGS_chroot}/etc/sudoers.d"
Brian Harring06d3c2e2012-08-23 07:35:43 -0700218
219 # Use the standardized upgrade script to setup proxied vars.
David James76764882012-10-24 19:46:29 -0700220 load_environment_whitelist
221 bash -e "${SCRIPT_ROOT}/chroot_version_hooks.d/45_rewrite_sudoers.d" \
222 "${FLAGS_chroot}" "${SUDO_USER}" "${ENVIRONMENT_WHITELIST[@]}"
Brian Harring06d3c2e2012-08-23 07:35:43 -0700223
David James76764882012-10-24 19:46:29 -0700224 find "${FLAGS_chroot}/etc/"sudoers* -type f -exec chmod 0440 {} +
Brian Harring35767822012-02-01 23:50:45 -0800225 # Fix bad group for some.
David James76764882012-10-24 19:46:29 -0700226 chown -R root:root "${FLAGS_chroot}/etc/"sudoers*
Brian Harringf539bc32012-02-06 00:18:37 -0800227
Brian Harring35767822012-02-01 23:50:45 -0800228 info "Setting up hosts/resolv..."
229 # Copy config from outside chroot into chroot.
David James76764882012-10-24 19:46:29 -0700230 cp /etc/{hosts,resolv.conf} "$FLAGS_chroot/etc/"
231 chmod 0644 "$FLAGS_chroot"/etc/{hosts,resolv.conf}
Brian Harringf539bc32012-02-06 00:18:37 -0800232
233 # Setup host make.conf. This includes any overlay that we may be using
234 # and a pointer to pre-built packages.
Brian Harring35767822012-02-01 23:50:45 -0800235 # TODO: This should really be part of a profile in the portage.
236 info "Setting up /etc/make.*..."
Mike Frysinger53f79bb2014-04-05 22:27:52 -0400237 rm -f "${FLAGS_chroot}"/etc/{,portage/}make.{conf,profile}{,.catalyst}
Mike Frysingerc6e1ace2013-03-22 00:49:30 -0400238 mkdir -p "${FLAGS_chroot}/etc/portage"
David James76764882012-10-24 19:46:29 -0700239 ln -sf "${CHROOT_CONFIG}/make.conf.amd64-host" \
Brian Harringf539bc32012-02-06 00:18:37 -0800240 "${FLAGS_chroot}/etc/make.conf"
Mike Frysinger411b2422014-06-04 11:49:17 -0400241 ln -sf "${CHROOT_OVERLAY}/profiles/default/linux/amd64/10.0/sdk" \
Mike Frysingere9b40072015-05-19 05:07:04 -0400242 "${FLAGS_chroot}/etc/portage/make.profile"
Brian Harringf539bc32012-02-06 00:18:37 -0800243
Brian Harring35767822012-02-01 23:50:45 -0800244 # Create make.conf.user .
David James76764882012-10-24 19:46:29 -0700245 touch "${FLAGS_chroot}"/etc/make.conf.user
246 chmod 0644 "${FLAGS_chroot}"/etc/make.conf.user
Brian Harringf539bc32012-02-06 00:18:37 -0800247
248 # Create directories referred to by our conf files.
David James76764882012-10-24 19:46:29 -0700249 mkdir -p -m 775 "${FLAGS_chroot}/var/lib/portage/pkgs" \
Brian Harring7b6f3772012-09-23 14:01:13 -0700250 "${FLAGS_chroot}/var/cache/"chromeos-{cache,chrome} \
251 "${FLAGS_chroot}/etc/profile.d"
252
David James76764882012-10-24 19:46:29 -0700253 echo "export CHROMEOS_CACHEDIR=/var/cache/chromeos-cache" > \
254 "${FLAGS_chroot}/etc/profile.d/chromeos-cachedir.sh"
255 chmod 0644 "${FLAGS_chroot}/etc/profile.d/chromeos-cachedir.sh"
256 rm -rf "${FLAGS_chroot}/var/cache/distfiles"
257 ln -s chromeos-cache/distfiles "${FLAGS_chroot}/var/cache/distfiles"
Brian Harring36b102b2012-02-06 23:34:25 -0800258
259 # Run this from w/in the chroot so we use whatever uid/gid
260 # these are defined as w/in the chroot.
David James76764882012-10-24 19:46:29 -0700261 bare_chroot chown "${SUDO_USER}:portage" /var/cache/chromeos-chrome
Brian Harring7ee892d2012-02-02 09:33:10 -0800262
263 # These are created for compatibility while transitioning
264 # make.conf and friends over to the new location.
Brian Harring7b6f3772012-09-23 14:01:13 -0700265 # TODO(ferringb): remove this 01/13 or so.
David James76764882012-10-24 19:46:29 -0700266 ln -s ../../cache/chromeos-cache/distfiles/host \
Brian Harring7ee892d2012-02-02 09:33:10 -0800267 "${FLAGS_chroot}/var/lib/portage/distfiles"
David James76764882012-10-24 19:46:29 -0700268 ln -s ../../cache/chromeos-cache/distfiles/target \
Brian Harring7ee892d2012-02-02 09:33:10 -0800269 "${FLAGS_chroot}/var/lib/portage/distfiles-target"
Brian Harringf539bc32012-02-06 00:18:37 -0800270
Brian Harringf539bc32012-02-06 00:18:37 -0800271 # Add chromite/bin and depot_tools into the path globally; note that the
272 # chromite wrapper itself might also be found in depot_tools.
273 # We rely on 'env-update' getting called below.
274 target="${FLAGS_chroot}/etc/env.d/99chromiumos"
David James76764882012-10-24 19:46:29 -0700275 cat <<EOF > "${target}"
David Purselld35d7af2015-05-04 16:37:08 -0700276PATH="${CHROOT_TRUNK_DIR}/chromite/bin:${DEPOT_TOOLS_DIR}"
Brian Harring2499bfb2012-12-18 16:23:31 -0800277CROS_WORKON_SRCROOT="${CHROOT_TRUNK_DIR}"
David Purselld35d7af2015-05-04 16:37:08 -0700278PORTAGE_USERNAME="${SUDO_USER}"
Brian Harringf539bc32012-02-06 00:18:37 -0800279EOF
280
281 # TODO(zbehan): Configure stuff that is usually configured in postinst's,
Mike Frysingereb1a9b42012-03-28 16:21:04 -0400282 # but wasn't. Fix the postinst's.
Brian Harring35767822012-02-01 23:50:45 -0800283 info "Running post-inst configuration hacks"
284 early_enter_chroot env-update
Brian Harringf539bc32012-02-06 00:18:37 -0800285
Brian Harring35767822012-02-01 23:50:45 -0800286 # This is basically a sanity check of our chroot. If any of these
287 # don't exist, then either bind mounts have failed, an invocation
288 # from above is broke, or some assumption about the stage3 is no longer
289 # true.
Mike Frysingere9b40072015-05-19 05:07:04 -0400290 early_enter_chroot ls -l /etc/make.conf /etc/portage/make.profile \
Brian Harring35767822012-02-01 23:50:45 -0800291 /usr/local/portage/chromiumos/profiles/default/linux/amd64/10.0
Brian Harringf539bc32012-02-06 00:18:37 -0800292
293 target="${FLAGS_chroot}/etc/profile.d"
David James76764882012-10-24 19:46:29 -0700294 mkdir -p "${target}"
295 cat << EOF > "${target}/chromiumos-niceties.sh"
Brian Harringf539bc32012-02-06 00:18:37 -0800296# Niceties for interactive logins. (cr) denotes this is a chroot, the
297# __git_branch_ps1 prints current git branch in ./ . The $r behavior is to
298# make sure we don't reset the previous $? value which later formats in
299# $PS1 might rely on.
300PS1='\$(r=\$?; __git_branch_ps1 "(%s) "; exit \$r)'"\${PS1}"
301PS1="(cr) \${PS1}"
302EOF
303
304 # Select a small set of locales for the user if they haven't done so
305 # already. This makes glibc upgrades cheap by only generating a small
306 # set of locales. The ones listed here are basically for the buildbots
307 # which always assume these are available. This works in conjunction
308 # with `cros_sdk --enter`.
309 # http://crosbug.com/20378
310 local localegen="$FLAGS_chroot/etc/locale.gen"
311 if ! grep -q -v -e '^#' -e '^$' "${localegen}" ; then
David James76764882012-10-24 19:46:29 -0700312 cat <<EOF >> "${localegen}"
Brian Harringf539bc32012-02-06 00:18:37 -0800313en_US ISO-8859-1
314en_US.UTF-8 UTF-8
315EOF
316 fi
317
Brian Harring35767822012-02-01 23:50:45 -0800318 # Automatically change to scripts directory.
Brian Harringf539bc32012-02-06 00:18:37 -0800319 echo 'cd ${CHROOT_CWD:-~/trunk/src/scripts}' \
David Purselld35d7af2015-05-04 16:37:08 -0700320 | user_append "${FLAGS_chroot}/home/${SUDO_USER}/.bash_profile"
Brian Harringf539bc32012-02-06 00:18:37 -0800321
Brian Harring35767822012-02-01 23:50:45 -0800322 # Enable bash completion for build scripts.
Brian Harringf539bc32012-02-06 00:18:37 -0800323 echo ". ~/trunk/src/scripts/bash_completion" \
David Purselld35d7af2015-05-04 16:37:08 -0700324 | user_append "${FLAGS_chroot}/home/${SUDO_USER}/.bashrc"
Brian Harringf539bc32012-02-06 00:18:37 -0800325
Peter Mayoe18c7d42013-06-06 13:41:03 -0400326 if [[ "${SUDO_USER}" = "chrome-bot" && -d "${SUDO_HOME}/.ssh" ]]; then
Brian Harringf539bc32012-02-06 00:18:37 -0800327 # Copy ssh keys, so chroot'd chrome-bot can scp files from chrome-web.
Peter Mayo31056952013-06-06 16:22:55 -0400328 user_cp -rp "${SUDO_HOME}/.ssh" "$FLAGS_chroot/home/${SUDO_USER}/"
Brian Harringf539bc32012-02-06 00:18:37 -0800329 fi
330
David Purselld35d7af2015-05-04 16:37:08 -0700331 if [[ -f "${SUDO_HOME}/.cros_chroot_init" ]]; then
332 sudo -u "${SUDO_USER}" -- /bin/bash "${SUDO_HOME}/.cros_chroot_init" \
David James76764882012-10-24 19:46:29 -0700333 "${FLAGS_chroot}"
Luigi Semenzato2443fdd2012-05-29 10:34:04 -0700334 fi
Yunlian Jiangf219bb32018-04-30 16:24:22 -0700335
336 # Update nsswitch.conf to make glibc-2.26 and after builds. See
337 # https://wiki.gentoo.org/wiki/Project:Toolchain/nsswitch.conf_in_glibc-2.26
338 if ! grep compat "${FLAGS_chroot}/etc/nsswitch.conf" | grep -q files; then
339 sed -i 's/\<compat\>/compat files/g' "${FLAGS_chroot}/etc/nsswitch.conf"
340 fi
Brian Harringf539bc32012-02-06 00:18:37 -0800341}
342
Gilad Arnold01d458b2015-05-28 06:41:08 -0700343unpack_tarball() {
344 local tarball_path="$1"
345 local dest_dir="$2"
346 local decompress
347 case "${tarball_path}" in
348 *.tbz2|*.tar.bz2) decompress=$(type -p pbzip2 || echo bzip2) ;;
349 *.tar.xz) decompress="xz" ;;
350 *) die "Unknown tarball compression: ${tarball_path}" ;;
351 esac
352 ${decompress} -dc "${tarball_path}" | tar -xp -C "${dest_dir}"
353}
354
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600355# Find a usable VG name for a given path and device. If there is an existing
356# VG associated with the device, it will be returned. If not, find an unused
357# name in the format cros_<safe_path>_NNN, where safe_path is an escaped version
358# of the last 90 characters of the path and NNN is a counter. Example:
359# /home/user/chromiumos/chroot/ -> cros_home+user+chromiumos+chroot_000.
360# If no unused name with this pattern can be found, return an empty string.
361find_vg_name() {
362 local chroot_path="$1"
363 local chroot_dev="$2"
364 chroot_path=${chroot_path##/}
365 chroot_path=${chroot_path%%/}
366 chroot_path=${chroot_path//[^A-Za-z0-9_+.-]/+}
367 chroot_path=${chroot_path: -$((${#chroot_path} < 90 ? ${#chroot_path} : 90))}
368 local vg_name=""
369 if [ -n "$chroot_dev" ]; then
370 vg_name=$(pvs -q --noheadings -o vg_name "$chroot_dev" 2>/dev/null | \
371 sed -e 's/^ *//')
372 fi
373 if [ -z "$vg_name" ]; then
374 local counter=0
375 vg_name=$(printf "cros_%s_%03d" "$chroot_path" "$counter")
376 while [ "$counter" -lt 1000 ] && vgs "$vg_name" >&/dev/null; do
377 counter=$((counter + 1))
378 vg_name=$(printf "cros_%s_%03d" "$chroot_path" "$counter")
379 done
380 if [ "$counter" -gt 999 ]; then
381 vg_name=""
382 fi
383 fi
384 echo "$vg_name"
385}
386
387# Create a loopback image and mount it on the chroot path so that we can take
388# snapshots before building. If an image already exists, try to mount it. The
389# chroot is initially mounted inside a temporary shared chroot.build subtree
390# that should have already been set up by the parent process, and then bind
391# mounted into the correct final location. The purpose of this indirection is
392# so that processes outside our mount namespace can see the top-level chroot
393# after we finish.
394mount_chroot_image() {
395 local chroot_image="$1"
396 local mount_path="$2"
397
398 # Make sure there's an image.
399 local existing_chroot=0
400 local chroot_dev=""
401 if [ -f "$chroot_image" ]; then
402 info "Attempting to reuse existing image file ${chroot_image}"
403 chroot_dev=$(losetup -j "$chroot_image" | cut -f1 -d:)
404 existing_chroot=1
405 else
406 dd if=/dev/null of="$chroot_image" bs=1G seek=500 >&/dev/null
407 fi
408
409 # Get/scan a loopback device attached to our image.
410 if [ -n "$chroot_dev" ]; then
411 pvscan -q "$chroot_dev" >&/dev/null
412 else
413 chroot_dev=$(losetup -f "$chroot_image" --show)
414 fi
415
416 # Find/create a VG on the loopback device.
417 chroot_vg=$(find_vg_name "$mount_path" "$chroot_dev")
418 if [ -z "$chroot_vg" ]; then
419 die_notrace "Unable to find usable VG name for ${mount_path}."
420 fi
421 if vgs "$chroot_vg" >&/dev/null; then
Benjamin Gordonf68aa942017-07-21 17:00:20 -0600422 vgchange -q -a y --noudevsync "$chroot_vg" >/dev/null || :
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600423 else
424 vgcreate -q "$chroot_vg" "$chroot_dev" >/dev/null
425 fi
426
427 # Find/create an LV inside our VG. If the LV is new, also create the FS.
428 # We need to pass --noudevsync to lvcreate because we're running inside
429 # a separate IPC namespace from the udev process.
430 if lvs "$chroot_vg/chroot" >&/dev/null; then
Benjamin Gordonf68aa942017-07-21 17:00:20 -0600431 lvchange -q -ay "$chroot_vg/chroot" --noudevsync >/dev/null || :
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600432 else
433 lvcreate -q -L 499G -T "${chroot_vg}/thinpool" -V500G -n chroot \
434 --noudevsync >/dev/null
435 mke2fs -q -m 0 -t ext4 "/dev/${chroot_vg}/chroot"
436 fi
437
438 # Mount the FS into a directory that should have been set up as a shared
439 # subtree by our parent process, then bind mount it into the place where
440 # it belongs. The parent will take care of moving the mount to the correct
441 # final place on the outside of our mount namespace after we exit.
442 local temp_chroot="${FLAGS_chroot}.build/chroot"
443 if ! mount -text4 -onoatime "/dev/${chroot_vg}/chroot" "$temp_chroot"; then
444 local chroot_example_opt=""
445 if [[ "$mount_path" != "$DEFAULT_CHROOT_DIR" ]]; then
446 chroot_example_opt="--chroot=$FLAGS_chroot"
447 fi
448
449 die_notrace <<EOF
450
451Unable to mount ${chroot_vg}/chroot on ${temp_chroot}. Check for corrupted
452image ${chroot_image}, or run
453
454cros_sdk --delete $chroot_example_opt
455
456to clean up an old chroot first.
457
458EOF
459 fi
460 mount --make-private "$temp_chroot"
461 mount --bind "$temp_chroot" "$mount_path"
462 mount --make-private "$mount_path"
463 if [ "$existing_chroot" = "1" ]; then
464 info "Mounted existing chroot image."
465 fi
466}
467
Brian Harring35767822012-02-01 23:50:45 -0800468# Handle deleting an existing environment.
Brian Harringf539bc32012-02-06 00:18:37 -0800469if [[ $FLAGS_delete -eq $FLAGS_TRUE || \
Brian Harring35767822012-02-01 23:50:45 -0800470 $FLAGS_replace -eq $FLAGS_TRUE ]]; then
Brian Harringf539bc32012-02-06 00:18:37 -0800471 delete_existing
472 [[ $FLAGS_delete -eq $FLAGS_TRUE ]] && exit 0
473fi
474
475CHROOT_TRUNK="${CHROOT_TRUNK_DIR}"
476PORTAGE="${SRC_ROOT}/third_party/portage"
477OVERLAY="${SRC_ROOT}/third_party/chromiumos-overlay"
478CONFIG_DIR="${OVERLAY}/chromeos/config"
Brian Harring2499bfb2012-12-18 16:23:31 -0800479CHROOT_CONFIG="${CHROOT_TRUNK_DIR}/src/third_party/chromiumos-overlay/chromeos/config"
Mike Frysingerb45dbb52013-12-13 21:14:09 -0500480OVERLAYS_ROOT="/usr/local/portage"
481ECLASS_OVERLAY="${OVERLAYS_ROOT}/eclass-overlay"
482PORTAGE_STABLE_OVERLAY="${OVERLAYS_ROOT}/stable"
483CROSSDEV_OVERLAY="${OVERLAYS_ROOT}/crossdev"
484CHROOT_OVERLAY="${OVERLAYS_ROOT}/chromiumos"
Brian Harringf539bc32012-02-06 00:18:37 -0800485CHROOT_STATE="${FLAGS_chroot}/etc/debian_chroot"
Vincent Palatin5ce24062014-02-26 12:08:23 -0800486CHROOT_VERSION="${FLAGS_chroot}/etc/cros_chroot_version"
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600487CHROOT_IMAGE="${FLAGS_chroot}.img"
Brian Harringf539bc32012-02-06 00:18:37 -0800488
489# Pass proxy variables into the environment.
490for type in http ftp all; do
David Purselld35d7af2015-05-04 16:37:08 -0700491 value=$(env | grep "${type}_proxy" || true)
Brian Harringf539bc32012-02-06 00:18:37 -0800492 if [ -n "${value}" ]; then
493 CHROOT_PASSTHRU+=("$value")
494 fi
495done
496
Brian Harring35767822012-02-01 23:50:45 -0800497# Create the destination directory.
Brian Harringf539bc32012-02-06 00:18:37 -0800498mkdir -p "$FLAGS_chroot"
499
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600500[[ $FLAGS_useimage -eq $FLAGS_TRUE ]] && \
501 mount_chroot_image "$CHROOT_IMAGE" "$FLAGS_chroot"
502
503# If the version contains something non-zero, we were already created and this
504# is just a re-mount.
505[[ -f "$CHROOT_VERSION" && "$(<$CHROOT_VERSION)" != "0" ]] && exit 0
506
Brian Harringf539bc32012-02-06 00:18:37 -0800507echo
David Purselld35d7af2015-05-04 16:37:08 -0700508if [[ -f "${CHROOT_STATE}" ]]; then
Mike Frysinger51930072014-04-05 13:01:45 -0400509 info "stage3 already set up. Skipping..."
David Purselld35d7af2015-05-04 16:37:08 -0700510elif [[ -z "${FLAGS_stage3_path}" ]]; then
Mike Frysinger51930072014-04-05 13:01:45 -0400511 die_notrace "Please use --stage3_path when bootstrapping"
Brian Harringf539bc32012-02-06 00:18:37 -0800512else
Mike Frysinger51930072014-04-05 13:01:45 -0400513 info "Unpacking stage3..."
Gilad Arnold01d458b2015-05-28 06:41:08 -0700514 unpack_tarball "${FLAGS_stage3_path}" "${FLAGS_chroot}"
Gilad Arnold8c8e0852015-06-03 16:19:16 -0700515 if [[ -n "${FLAGS_toolchains_overlay_path}" ]]; then
516 info "Unpacking toolchains overlay..."
517 unpack_tarball "${FLAGS_toolchains_overlay_path}" "${FLAGS_chroot}"
Gilad Arnold01d458b2015-05-28 06:41:08 -0700518 fi
David James76764882012-10-24 19:46:29 -0700519 rm -f "$FLAGS_chroot/etc/"make.{globals,conf.user}
Brian Harringf539bc32012-02-06 00:18:37 -0800520fi
521
Vincent Palatin5ce24062014-02-26 12:08:23 -0800522# Ensure that we properly detect when we are inside the chroot.
523# We'll force this to the latest version at the end as needed.
David Purselld35d7af2015-05-04 16:37:08 -0700524if [[ ! -e "${CHROOT_VERSION}" ]]; then
Vincent Palatin5ce24062014-02-26 12:08:23 -0800525 echo "0" > "${CHROOT_VERSION}"
526fi
527
Brian Harring35767822012-02-01 23:50:45 -0800528# Set up users, if needed, before mkdir/mounts below.
Brian Harringf539bc32012-02-06 00:18:37 -0800529[ -f $CHROOT_STATE ] || init_users
530
Brian Harring2499bfb2012-12-18 16:23:31 -0800531# Reset internal vars to force them to the 'inside the chroot' value;
532# since user directories now exist, this can do the upgrade in place.
533set_chroot_trunk_dir "${FLAGS_chroot}" poppycock
534
Brian Harringf539bc32012-02-06 00:18:37 -0800535echo
Brian Harring35767822012-02-01 23:50:45 -0800536info "Setting up mounts..."
537# Set up necessary mounts and make sure we clean them up on exit.
Brian Harring2499bfb2012-12-18 16:23:31 -0800538mkdir -p "${FLAGS_chroot}/${CHROOT_TRUNK_DIR}" \
539 "${FLAGS_chroot}/${DEPOT_TOOLS_DIR}" "${FLAGS_chroot}/run"
Brian Harring35767822012-02-01 23:50:45 -0800540
J. Richard Barnettee80f6de2012-02-24 14:08:34 -0800541# Create a special /etc/make.conf.host_setup that we use to bootstrap
542# the chroot. The regular content for the file will be generated the
543# first time we invoke update_chroot (further down in this script).
544create_bootstrap_host_setup "${FLAGS_chroot}"
Brian Harringf539bc32012-02-06 00:18:37 -0800545
546if ! [ -f "$CHROOT_STATE" ];then
547 INITIALIZE_CHROOT=1
548fi
549
Mike Frysingerba758452012-04-02 13:28:31 -0400550if ! early_enter_chroot bash -c 'type -P pbzip2' >/dev/null ; then
551 # This chroot lacks pbzip2 early on, so we need to disable it.
552 early_env+=(
553 PORTAGE_BZIP2_COMMAND="bzip2"
554 PORTAGE_BUNZIP2_COMMAND="bunzip2"
555 )
556fi
557
Brian Harringf539bc32012-02-06 00:18:37 -0800558if [ -z "${INITIALIZE_CHROOT}" ];then
Brian Harring35767822012-02-01 23:50:45 -0800559 info "chroot already initialized. Skipping..."
Brian Harringf539bc32012-02-06 00:18:37 -0800560else
Brian Harring35767822012-02-01 23:50:45 -0800561 # Run all the init stuff to setup the env.
Brian Harringf539bc32012-02-06 00:18:37 -0800562 init_setup
563fi
564
Brian Harring35767822012-02-01 23:50:45 -0800565# Add file to indicate that it is a chroot.
Mike Frysinger51930072014-04-05 13:01:45 -0400566# Add version of stage3 for update checks.
567echo "STAGE3=${FLAGS_stage3_path}" > "${CHROOT_STATE}"
Brian Harringf539bc32012-02-06 00:18:37 -0800568
Daniel Kurtz51244842017-07-25 01:32:04 +0800569# TODO(crbug.com/747810): Remove this once stage3 is updated past 2015-Q1.
570# The 2014.09.18 stage3 uses app-admin/eselect-python, but in 2015-Q1 it moved
571# to app-eselect/eselect-python. Since portage depends on python-exec, and
572# python-exec depends on eselect-python, update python and related packages
573# before portage.
574info "Updating python"
Jason D. Clinton78d28d92018-01-19 17:43:39 -0700575early_enter_chroot emerge -uNv --quiet python:2.7 python
Daniel Kurtz51244842017-07-25 01:32:04 +0800576
577# New versions of the stage3 have Python 3 set as the default. Make sure we
578# default to 2.x as our scripts are only compatible with Python 2. We leave
579# Python 3 installed though as we've started including it in our SDK.
580# We can't just "set 1" because the option order changes for different stage3
581# tarballs.
582early_enter_chroot eselect python update --ignore "3*"
583
Brian Harring35767822012-02-01 23:50:45 -0800584info "Updating portage"
Mike Frysinger66fd81f2012-02-28 13:13:20 -0500585early_enter_chroot emerge -uNv --quiet portage
Brian Harringf539bc32012-02-06 00:18:37 -0800586
Mike Frysinger9a2978c2013-08-04 11:38:43 -0400587# Clear out openrc if it's installed as we don't want it.
David Purselld35d7af2015-05-04 16:37:08 -0700588if [[ -e "${FLAGS_chroot}/usr/share/openrc" ]]; then
Mike Frysinger9a2978c2013-08-04 11:38:43 -0400589 info "Uninstalling openrc"
590 early_enter_chroot env CLEAN_DELAY=0 emerge -qC sys-apps/openrc
Mike Frysinger47e599e2013-10-28 13:30:12 -0400591 # Now update baselayout to get our functions.sh. The unmerge
592 # above removed our copy in the process.
593 early_enter_chroot emerge -uNvq sys-apps/baselayout
Mike Frysinger9a2978c2013-08-04 11:38:43 -0400594fi
595
Bertrand SIMONNET85c96c72014-08-20 12:10:48 -0700596# Add chromite into python path.
Bertrand SIMONNET85c96c72014-08-20 12:10:48 -0700597for python_path in "${FLAGS_chroot}/usr/lib/"python2.*; do
598 python_path+="/site-packages"
599 sudo mkdir -p "${python_path}"
600 sudo ln -s -fT "${CHROOT_TRUNK_DIR}"/chromite "${python_path}"/chromite
601done
602
Chirantan Ekboteaf1b9502016-07-14 11:29:16 -0700603# The stage3 contains an old version of ncurses, which causes a slot conflict
604# later when we try to setup the toolchains. Update it here to the latest
605# version, which gracefully handles the slot issues.
606info "Updating ncurses"
607early_enter_chroot emerge -uNvq sys-libs/ncurses
608
Yunlian Jiangb09cf6e2018-05-04 11:54:09 -0700609# The stage3 contains an old version of bison and glibc 2.26+ wants a newer one.
610info "Updating bison"
611early_enter_chroot emerge -uNvq sys-devel/bison
612
Zdenek Behan2fbd5af2012-03-12 19:38:50 +0100613info "Updating host toolchain"
David Purselld35d7af2015-05-04 16:37:08 -0700614if [[ ! -e "${FLAGS_chroot}/usr/bin/crossdev" ]]; then
Mike Frysinger5e07dc72014-11-05 14:40:04 -0500615 early_enter_chroot $EMERGE_CMD -uNv crossdev
616fi
Zdenek Behan2fbd5af2012-03-12 19:38:50 +0100617TOOLCHAIN_ARGS=( --deleteold )
David Purselld35d7af2015-05-04 16:37:08 -0700618if [[ "${FLAGS_usepkg}" == "${FLAGS_FALSE}" ]]; then
Zdenek Behan2fbd5af2012-03-12 19:38:50 +0100619 TOOLCHAIN_ARGS+=( --nousepkg )
620fi
621# Note: early_enter_chroot executes as root.
Brian Harring2499bfb2012-12-18 16:23:31 -0800622early_enter_chroot "${CHROOT_TRUNK_DIR}/chromite/bin/cros_setup_toolchains" \
Zdenek Behan2fbd5af2012-03-12 19:38:50 +0100623 --hostonly "${TOOLCHAIN_ARGS[@]}"
Brian Harringf539bc32012-02-06 00:18:37 -0800624
Ben Chan0c9da662017-05-15 17:29:51 -0700625info "Running emerge curl sudo gentoolkit ..."
Mike Frysinger650bf872012-02-27 11:05:26 -0500626early_enter_chroot $EMERGE_CMD -uNv $USEPKG --select $EMERGE_JOBS \
Ben Chan0c9da662017-05-15 17:29:51 -0700627 pbzip2 dev-libs/openssl net-misc/curl sudo app-portage/gentoolkit
628
629info "Updating Perl modules"
630early_enter_chroot \
631 "${CHROOT_TRUNK_DIR}/src/scripts/build_library/perl_rebuild.sh"
Paul Drews8bae3b52012-10-10 11:18:13 -0700632
Brian Harringf539bc32012-02-06 00:18:37 -0800633if [ -n "${INITIALIZE_CHROOT}" ]; then
634 # If we're creating a new chroot, we also want to set it to the latest
635 # version.
Brian Harring35767822012-02-01 23:50:45 -0800636 enter_chroot \
David James47e0e8a2015-03-11 15:24:10 -0700637 "${CHROOT_TRUNK_DIR}/src/scripts/run_chroot_version_hooks" --init_latest
Brian Harringf539bc32012-02-06 00:18:37 -0800638fi
639
Benjamin Gordon9413b102017-11-29 20:13:38 +0000640# Update these packages early because they cause build failures when they're
641# concurrently emerged during the main update below.
642# Specific packages:
643# sys-apps/sandbox upgrade breaks dev-libs/nss.
644# sys-devel/patch 2.6 misapplies git patches in dev-embedded/coreboot-sdk.
645# older sys-devel/automake makes media-libs/freetype build flaky.
646info "Updating preinstalled build tools"
647early_enter_chroot ${EMERGE_CMD} -uNv ${USEPKG} --select ${EMERGE_JOBS} \
Yunlian Jiangb09cf6e2018-05-04 11:54:09 -0700648 sys-apps/sandbox '>=sys-devel/patch-2.7' sys-devel/automake
Benjamin Gordon9413b102017-11-29 20:13:38 +0000649
Brian Harring35767822012-02-01 23:50:45 -0800650# Update chroot.
Zdenek Behan2fbd5af2012-03-12 19:38:50 +0100651# Skip toolchain update because it already happened above, and the chroot is
652# not ready to emerge all cross toolchains.
653UPDATE_ARGS=( --skip_toolchain_update )
David Purselld35d7af2015-05-04 16:37:08 -0700654if [[ "${FLAGS_usepkg}" == "${FLAGS_TRUE}" ]]; then
Brian Harring35767822012-02-01 23:50:45 -0800655 UPDATE_ARGS+=( --usepkg )
Brian Harringf539bc32012-02-06 00:18:37 -0800656else
Brian Harring35767822012-02-01 23:50:45 -0800657 UPDATE_ARGS+=( --nousepkg )
Brian Harringf539bc32012-02-06 00:18:37 -0800658fi
David James184e3902012-02-23 20:19:28 -0800659if [[ "${FLAGS_jobs}" -ne -1 ]]; then
David Purselld35d7af2015-05-04 16:37:08 -0700660 UPDATE_ARGS+=( --jobs="${FLAGS_jobs}" )
David James184e3902012-02-23 20:19:28 -0800661fi
Brian Harring2499bfb2012-12-18 16:23:31 -0800662enter_chroot "${CHROOT_TRUNK_DIR}/src/scripts/update_chroot" "${UPDATE_ARGS[@]}"
Brian Harringf539bc32012-02-06 00:18:37 -0800663
Stefan Zager48c776b2013-10-09 13:01:25 -0700664# The java-config package atm does not support $ROOT. Select a default
665# VM ourselves until that gets fixed upstream.
666enter_chroot sudo java-config --set-system-vm 1
667
Brian Harring35767822012-02-01 23:50:45 -0800668CHROOT_EXAMPLE_OPT=""
669if [[ "$FLAGS_chroot" != "$DEFAULT_CHROOT_DIR" ]]; then
Brian Harringf539bc32012-02-06 00:18:37 -0800670 CHROOT_EXAMPLE_OPT="--chroot=$FLAGS_chroot"
671fi
672
Matt Tennant0a9d32d2012-07-30 16:51:37 -0700673command_completed
Brian Harringf539bc32012-02-06 00:18:37 -0800674
Brian Harring35767822012-02-01 23:50:45 -0800675cat <<EOF
Mike Frysingerbdc4fb12012-02-10 11:20:03 -0500676
677${CROS_LOG_PREFIX:-cros_sdk}: All set up. To enter the chroot, run:
678$ cros_sdk --enter $CHROOT_EXAMPLE_OPT
Brian Harring35767822012-02-01 23:50:45 -0800679
680CAUTION: Do *NOT* rm -rf the chroot directory; if there are stale bind
681mounts you may end up deleting your source tree too. To unmount and
682delete the chroot cleanly, use:
683$ cros_sdk --delete $CHROOT_EXAMPLE_OPT
Mike Frysingerbdc4fb12012-02-10 11:20:03 -0500684
Brian Harring35767822012-02-01 23:50:45 -0800685EOF
David James22dc2ba2012-11-29 15:46:58 -0800686
687warn_if_nfs "${SUDO_HOME}"