blob: d9e59948b63876738186b70810b11e487b7b919f [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}"
Brian Harringf539bc32012-02-06 00:18:37 -080051
Peter Mayo4411efe2012-09-21 04:41:27 -040052CROS_LOG_PREFIX=cros_sdk:make_chroot
David Purselld35d7af2015-05-04 16:37:08 -070053SUDO_HOME=$(eval echo ~"${SUDO_USER}")
Brian Harringf539bc32012-02-06 00:18:37 -080054
Brian Harringf539bc32012-02-06 00:18:37 -080055# Set the right umask for chroot creation.
56umask 022
57
58# Only now can we die on error. shflags functions leak non-zero error codes,
Brian Harring7f175a52012-03-02 05:37:00 -080059# so will die prematurely if 'switch_to_strict_mode' is specified before now.
Brian Harringf539bc32012-02-06 00:18:37 -080060# TODO: replace shflags with something less error-prone, or contribute a fix.
Brian Harring7f175a52012-03-02 05:37:00 -080061switch_to_strict_mode
Brian Harringf539bc32012-02-06 00:18:37 -080062
Brian Harring7b6f3772012-09-23 14:01:13 -070063[[ "${FLAGS_delete}" == "${FLAGS_FALSE}" ]] && \
64 [[ -z "${FLAGS_cache_dir}" ]] && \
65 die "--cache_dir is required"
66
J. Richard Barnettee80f6de2012-02-24 14:08:34 -080067. "${SCRIPT_ROOT}"/sdk_lib/make_conf_util.sh
68
David Purselld35d7af2015-05-04 16:37:08 -070069PRIMARY_GROUP=$(id -g -n "${SUDO_USER}")
70PRIMARY_GROUP_ID=$(id -g "${SUDO_USER}")
71
Brian Harringf539bc32012-02-06 00:18:37 -080072FULLNAME="ChromeOS Developer"
David Purselld35d7af2015-05-04 16:37:08 -070073DEFGROUPS="${PRIMARY_GROUP},adm,cdrom,floppy,audio,video,portage"
74
Brian Harringf539bc32012-02-06 00:18:37 -080075USEPKG=""
Manoj Gupta51880b82019-06-19 13:50:57 -070076USEPKGONLY=""
Brian Harringf539bc32012-02-06 00:18:37 -080077if [[ $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"
Manoj Gupta51880b82019-06-19 13:50:57 -070082 # Use --usepkgonly to avoid building toolchain packages from source.
83 USEPKGONLY="--usepkgonly"
Brian Harringf539bc32012-02-06 00:18:37 -080084fi
85
Bertrand SIMONNET4dda4f52015-03-19 13:40:58 -070086EMERGE_CMD="${CHROOT_TRUNK_DIR}/chromite/bin/parallel_emerge"
Brian Harringf539bc32012-02-06 00:18:37 -080087
Brian Harring35767822012-02-01 23:50:45 -080088ENTER_CHROOT_ARGS=(
89 CROS_WORKON_SRCROOT="$CHROOT_TRUNK"
David James76764882012-10-24 19:46:29 -070090 PORTAGE_USERNAME="${SUDO_USER}"
Brian Harring35767822012-02-01 23:50:45 -080091 IGNORE_PREFLIGHT_BINHOST="$IGNORE_PREFLIGHT_BINHOST"
92)
93
94# Invoke enter_chroot. This can only be used after sudo has been installed.
Mike Frysinger6b1abb22012-05-11 13:44:06 -040095enter_chroot() {
Mike Frysingerca7cd942019-09-08 04:40:45 -040096 echo "$(date +%H:%M:%S) [enter_chroot] $*"
Brian Harring7b6f3772012-09-23 14:01:13 -070097 "$ENTER_CHROOT" --cache_dir "${FLAGS_cache_dir}" --chroot "$FLAGS_chroot" \
98 -- "${ENTER_CHROOT_ARGS[@]}" "$@"
Brian Harringf539bc32012-02-06 00:18:37 -080099}
100
Brian Harring35767822012-02-01 23:50:45 -0800101# Invoke enter_chroot running the command as root, and w/out sudo.
102# This should be used prior to sudo being merged.
Mike Frysingerba758452012-04-02 13:28:31 -0400103early_env=()
Mike Frysinger6b1abb22012-05-11 13:44:06 -0400104early_enter_chroot() {
Mike Frysingerca7cd942019-09-08 04:40:45 -0400105 echo "$(date +%H:%M:%S) [early_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 Frysingereab3f072019-08-21 22:57:49 -0400142# Appends stdin to the given file name as the sudo user.
143#
144# $1 - The output file name.
145user_append() {
146 cat >> "$1"
147 chown ${SUDO_UID}:${SUDO_GID} "$1"
148}
149
Mike Frysinger6b1abb22012-05-11 13:44:06 -0400150delete_existing() {
Brian Harring35767822012-02-01 23:50:45 -0800151 # Delete old chroot dir.
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600152 local chroot_img="${FLAGS_chroot}.img"
153 if [[ ! -e "$FLAGS_chroot" && ! -f "$chroot_img" ]]; then
Brian Harring35767822012-02-01 23:50:45 -0800154 return
Brian Harringf539bc32012-02-06 00:18:37 -0800155 fi
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600156 info "Cleaning up old mount points and loopback device..."
Brian Harring35767822012-02-01 23:50:45 -0800157 cleanup
158 info "Deleting $FLAGS_chroot..."
David James76764882012-10-24 19:46:29 -0700159 rm -rf "$FLAGS_chroot"
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600160 if [[ -f "$chroot_img" ]]; then
161 info "Deleting $chroot_img..."
162 rm -f "$chroot_img"
163 fi
Brian Harring35767822012-02-01 23:50:45 -0800164 info "Done."
Brian Harringf539bc32012-02-06 00:18:37 -0800165}
166
Mike Frysinger6b1abb22012-05-11 13:44:06 -0400167init_users () {
Brian Harring35767822012-02-01 23:50:45 -0800168 info "Set timezone..."
169 # date +%Z has trouble with daylight time, so use host's info.
David James76764882012-10-24 19:46:29 -0700170 rm -f "${FLAGS_chroot}/etc/localtime"
Brian Harringf539bc32012-02-06 00:18:37 -0800171 if [ -f /etc/localtime ] ; then
David James76764882012-10-24 19:46:29 -0700172 cp /etc/localtime "${FLAGS_chroot}/etc"
Brian Harringf539bc32012-02-06 00:18:37 -0800173 else
David James76764882012-10-24 19:46:29 -0700174 ln -sf /usr/share/zoneinfo/PST8PDT "${FLAGS_chroot}/etc/localtime"
Brian Harringf539bc32012-02-06 00:18:37 -0800175 fi
Brian Harring35767822012-02-01 23:50:45 -0800176 info "Adding user/group..."
David Purselld35d7af2015-05-04 16:37:08 -0700177 # Add the necessary groups to the chroot.
178 # Duplicate GIDs are allowed here in order to ensure that the required
179 # groups are the same inside and outside the chroot.
180 # TODO(dpursell): Handle when PRIMARY_GROUP exists in the chroot already
181 # with a different GID; groupadd will not create the new GID in that case.
182 bare_chroot groupadd -f -o -g "${PRIMARY_GROUP_ID}" "${PRIMARY_GROUP}"
Brian Harringf539bc32012-02-06 00:18:37 -0800183 # Add ourselves as a user inside the chroot.
Brian Harringf539bc32012-02-06 00:18:37 -0800184 # We need the UID to match the host user's. This can conflict with
185 # a particular chroot UID. At the same time, the added user has to
186 # be a primary user for the given UID for sudo to work, which is
187 # determined by the order in /etc/passwd. Let's put ourselves on top
188 # of the file.
David Purselld35d7af2015-05-04 16:37:08 -0700189 bare_chroot useradd -o -G "${DEFGROUPS}" -g "${PRIMARY_GROUP}" \
190 -u "${SUDO_UID}" -s /bin/bash -m -c "${FULLNAME}" "${SUDO_USER}"
Brian Harringf539bc32012-02-06 00:18:37 -0800191 # Because passwd generally isn't sorted and the entry ended up at the
192 # bottom, it is safe to just take it and move it to top instead.
David James76764882012-10-24 19:46:29 -0700193 sed -e '1{h;d};$!{H;d};$G' -i "${FLAGS_chroot}/etc/passwd"
Brian Harringf539bc32012-02-06 00:18:37 -0800194}
195
Mike Frysinger6b1abb22012-05-11 13:44:06 -0400196init_setup () {
Brian Harring35767822012-02-01 23:50:45 -0800197 info "Running init_setup()..."
David James76764882012-10-24 19:46:29 -0700198 mkdir -p -m 755 "${FLAGS_chroot}/usr" \
Mike Frysingerb45dbb52013-12-13 21:14:09 -0500199 "${FLAGS_chroot}${OVERLAYS_ROOT}" \
Mike Frysinger36beaaa2014-09-25 15:52:27 -0400200 "${FLAGS_chroot}"/"${CROSSDEV_OVERLAY}/metadata"
201 # Newer portage complains about bare overlays. Create the file that crossdev
202 # will also create later on.
203 cat <<EOF > "${FLAGS_chroot}/${CROSSDEV_OVERLAY}/metadata/layout.conf"
204# Autogenerated and managed by crossdev
205# Delete the above line if you want to manage this file yourself
206masters = portage-stable chromiumos
207repo-name = crossdev
208use-manifests = true
209thin-manifests = true
210EOF
Mike Frysingerb45dbb52013-12-13 21:14:09 -0500211 ln -sf "${CHROOT_TRUNK_DIR}/src/third_party/eclass-overlay" \
212 "${FLAGS_chroot}"/"${ECLASS_OVERLAY}"
Brian Harring2499bfb2012-12-18 16:23:31 -0800213 ln -sf "${CHROOT_TRUNK_DIR}/src/third_party/chromiumos-overlay" \
Brian Harringf539bc32012-02-06 00:18:37 -0800214 "${FLAGS_chroot}"/"${CHROOT_OVERLAY}"
Brian Harring2499bfb2012-12-18 16:23:31 -0800215 ln -sf "${CHROOT_TRUNK_DIR}/src/third_party/portage-stable" \
Brian Harringf539bc32012-02-06 00:18:37 -0800216 "${FLAGS_chroot}"/"${PORTAGE_STABLE_OVERLAY}"
Brian Harringf539bc32012-02-06 00:18:37 -0800217
Brian Harring35767822012-02-01 23:50:45 -0800218 # Some operations need an mtab.
Mike Frysingerb47a4ff2013-02-20 17:29:05 -0500219 ln -sfT /proc/mounts "${FLAGS_chroot}/etc/mtab"
Brian Harringf539bc32012-02-06 00:18:37 -0800220
221 # Set up sudoers. Inside the chroot, the user can sudo without a password.
222 # (Safe enough, since the only way into the chroot is to 'sudo chroot', so
223 # the user's already typed in one sudo password...)
224 # Make sure the sudoers.d subdir exists as older stage3 base images lack it.
David James76764882012-10-24 19:46:29 -0700225 mkdir -p "${FLAGS_chroot}/etc/sudoers.d"
Brian Harring06d3c2e2012-08-23 07:35:43 -0700226
227 # Use the standardized upgrade script to setup proxied vars.
David James76764882012-10-24 19:46:29 -0700228 load_environment_whitelist
Mike Frysinger6b05da92018-08-05 01:22:12 -0400229 bash "${SCRIPT_ROOT}/chroot_version_hooks.d/153_rewrite_sudoers.d" \
David James76764882012-10-24 19:46:29 -0700230 "${FLAGS_chroot}" "${SUDO_USER}" "${ENVIRONMENT_WHITELIST[@]}"
Brian Harring06d3c2e2012-08-23 07:35:43 -0700231
David James76764882012-10-24 19:46:29 -0700232 find "${FLAGS_chroot}/etc/"sudoers* -type f -exec chmod 0440 {} +
Brian Harring35767822012-02-01 23:50:45 -0800233 # Fix bad group for some.
David James76764882012-10-24 19:46:29 -0700234 chown -R root:root "${FLAGS_chroot}/etc/"sudoers*
Brian Harringf539bc32012-02-06 00:18:37 -0800235
Brian Harring35767822012-02-01 23:50:45 -0800236 info "Setting up hosts/resolv..."
237 # Copy config from outside chroot into chroot.
David James76764882012-10-24 19:46:29 -0700238 cp /etc/{hosts,resolv.conf} "$FLAGS_chroot/etc/"
239 chmod 0644 "$FLAGS_chroot"/etc/{hosts,resolv.conf}
Brian Harringf539bc32012-02-06 00:18:37 -0800240
241 # Setup host make.conf. This includes any overlay that we may be using
242 # and a pointer to pre-built packages.
Brian Harring35767822012-02-01 23:50:45 -0800243 # TODO: This should really be part of a profile in the portage.
244 info "Setting up /etc/make.*..."
Mike Frysinger53f79bb2014-04-05 22:27:52 -0400245 rm -f "${FLAGS_chroot}"/etc/{,portage/}make.{conf,profile}{,.catalyst}
Mike Frysingerc6e1ace2013-03-22 00:49:30 -0400246 mkdir -p "${FLAGS_chroot}/etc/portage"
David James76764882012-10-24 19:46:29 -0700247 ln -sf "${CHROOT_CONFIG}/make.conf.amd64-host" \
Brian Harringf539bc32012-02-06 00:18:37 -0800248 "${FLAGS_chroot}/etc/make.conf"
Mike Frysinger411b2422014-06-04 11:49:17 -0400249 ln -sf "${CHROOT_OVERLAY}/profiles/default/linux/amd64/10.0/sdk" \
Mike Frysingere9b40072015-05-19 05:07:04 -0400250 "${FLAGS_chroot}/etc/portage/make.profile"
Brian Harringf539bc32012-02-06 00:18:37 -0800251
Brian Harring35767822012-02-01 23:50:45 -0800252 # Create make.conf.user .
Alex Kleina28439c2019-01-14 14:48:30 -0700253 cat <<EOF > "${FLAGS_chroot}"/etc/make.conf.user
254# This file is useful for doing global (chroot and all board) changes.
255# Tweak emerge settings, ebuild env, etc...
256#
257# Make sure to append variables unless you really want to clobber all
258# existing settings. e.g. You most likely want:
259# FEATURES="${FEATURES} ..."
260# USE="${USE} foo"
261# and *not*:
262# USE="foo"
263#
264# This also is a good place to setup ACCEPT_LICENSE.
265EOF
David James76764882012-10-24 19:46:29 -0700266 chmod 0644 "${FLAGS_chroot}"/etc/make.conf.user
Brian Harringf539bc32012-02-06 00:18:37 -0800267
268 # Create directories referred to by our conf files.
David James76764882012-10-24 19:46:29 -0700269 mkdir -p -m 775 "${FLAGS_chroot}/var/lib/portage/pkgs" \
Brian Harring7b6f3772012-09-23 14:01:13 -0700270 "${FLAGS_chroot}/var/cache/"chromeos-{cache,chrome} \
271 "${FLAGS_chroot}/etc/profile.d"
272
David James76764882012-10-24 19:46:29 -0700273 echo "export CHROMEOS_CACHEDIR=/var/cache/chromeos-cache" > \
274 "${FLAGS_chroot}/etc/profile.d/chromeos-cachedir.sh"
275 chmod 0644 "${FLAGS_chroot}/etc/profile.d/chromeos-cachedir.sh"
276 rm -rf "${FLAGS_chroot}/var/cache/distfiles"
277 ln -s chromeos-cache/distfiles "${FLAGS_chroot}/var/cache/distfiles"
Brian Harring36b102b2012-02-06 23:34:25 -0800278
279 # Run this from w/in the chroot so we use whatever uid/gid
280 # these are defined as w/in the chroot.
David James76764882012-10-24 19:46:29 -0700281 bare_chroot chown "${SUDO_USER}:portage" /var/cache/chromeos-chrome
Brian Harring7ee892d2012-02-02 09:33:10 -0800282
283 # These are created for compatibility while transitioning
284 # make.conf and friends over to the new location.
Brian Harring7b6f3772012-09-23 14:01:13 -0700285 # TODO(ferringb): remove this 01/13 or so.
David James76764882012-10-24 19:46:29 -0700286 ln -s ../../cache/chromeos-cache/distfiles/host \
Brian Harring7ee892d2012-02-02 09:33:10 -0800287 "${FLAGS_chroot}/var/lib/portage/distfiles"
David James76764882012-10-24 19:46:29 -0700288 ln -s ../../cache/chromeos-cache/distfiles/target \
Brian Harring7ee892d2012-02-02 09:33:10 -0800289 "${FLAGS_chroot}/var/lib/portage/distfiles-target"
Brian Harringf539bc32012-02-06 00:18:37 -0800290
Brian Harringf539bc32012-02-06 00:18:37 -0800291 # Add chromite/bin and depot_tools into the path globally; note that the
292 # chromite wrapper itself might also be found in depot_tools.
293 # We rely on 'env-update' getting called below.
294 target="${FLAGS_chroot}/etc/env.d/99chromiumos"
David James76764882012-10-24 19:46:29 -0700295 cat <<EOF > "${target}"
David Purselld35d7af2015-05-04 16:37:08 -0700296PATH="${CHROOT_TRUNK_DIR}/chromite/bin:${DEPOT_TOOLS_DIR}"
Brian Harring2499bfb2012-12-18 16:23:31 -0800297CROS_WORKON_SRCROOT="${CHROOT_TRUNK_DIR}"
David Purselld35d7af2015-05-04 16:37:08 -0700298PORTAGE_USERNAME="${SUDO_USER}"
Brian Harringf539bc32012-02-06 00:18:37 -0800299EOF
300
301 # TODO(zbehan): Configure stuff that is usually configured in postinst's,
Mike Frysingereb1a9b42012-03-28 16:21:04 -0400302 # but wasn't. Fix the postinst's.
Brian Harring35767822012-02-01 23:50:45 -0800303 info "Running post-inst configuration hacks"
304 early_enter_chroot env-update
Brian Harringf539bc32012-02-06 00:18:37 -0800305
Brian Harring35767822012-02-01 23:50:45 -0800306 # This is basically a sanity check of our chroot. If any of these
307 # don't exist, then either bind mounts have failed, an invocation
308 # from above is broke, or some assumption about the stage3 is no longer
309 # true.
Mike Frysingere9b40072015-05-19 05:07:04 -0400310 early_enter_chroot ls -l /etc/make.conf /etc/portage/make.profile \
Brian Harring35767822012-02-01 23:50:45 -0800311 /usr/local/portage/chromiumos/profiles/default/linux/amd64/10.0
Brian Harringf539bc32012-02-06 00:18:37 -0800312
313 target="${FLAGS_chroot}/etc/profile.d"
David James76764882012-10-24 19:46:29 -0700314 mkdir -p "${target}"
315 cat << EOF > "${target}/chromiumos-niceties.sh"
Brian Harringf539bc32012-02-06 00:18:37 -0800316# Niceties for interactive logins. (cr) denotes this is a chroot, the
317# __git_branch_ps1 prints current git branch in ./ . The $r behavior is to
318# make sure we don't reset the previous $? value which later formats in
319# $PS1 might rely on.
320PS1='\$(r=\$?; __git_branch_ps1 "(%s) "; exit \$r)'"\${PS1}"
321PS1="(cr) \${PS1}"
322EOF
323
324 # Select a small set of locales for the user if they haven't done so
325 # already. This makes glibc upgrades cheap by only generating a small
326 # set of locales. The ones listed here are basically for the buildbots
327 # which always assume these are available. This works in conjunction
328 # with `cros_sdk --enter`.
329 # http://crosbug.com/20378
330 local localegen="$FLAGS_chroot/etc/locale.gen"
331 if ! grep -q -v -e '^#' -e '^$' "${localegen}" ; then
David James76764882012-10-24 19:46:29 -0700332 cat <<EOF >> "${localegen}"
Brian Harringf539bc32012-02-06 00:18:37 -0800333en_US ISO-8859-1
334en_US.UTF-8 UTF-8
335EOF
336 fi
337
Brian Harring35767822012-02-01 23:50:45 -0800338 # Automatically change to scripts directory.
Brian Harringf539bc32012-02-06 00:18:37 -0800339 echo 'cd ${CHROOT_CWD:-~/trunk/src/scripts}' \
David Purselld35d7af2015-05-04 16:37:08 -0700340 | user_append "${FLAGS_chroot}/home/${SUDO_USER}/.bash_profile"
Brian Harringf539bc32012-02-06 00:18:37 -0800341
Brian Harring35767822012-02-01 23:50:45 -0800342 # Enable bash completion for build scripts.
Brian Harringf539bc32012-02-06 00:18:37 -0800343 echo ". ~/trunk/src/scripts/bash_completion" \
David Purselld35d7af2015-05-04 16:37:08 -0700344 | user_append "${FLAGS_chroot}/home/${SUDO_USER}/.bashrc"
Brian Harringf539bc32012-02-06 00:18:37 -0800345
David Purselld35d7af2015-05-04 16:37:08 -0700346 if [[ -f "${SUDO_HOME}/.cros_chroot_init" ]]; then
347 sudo -u "${SUDO_USER}" -- /bin/bash "${SUDO_HOME}/.cros_chroot_init" \
David James76764882012-10-24 19:46:29 -0700348 "${FLAGS_chroot}"
Luigi Semenzato2443fdd2012-05-29 10:34:04 -0700349 fi
Brian Harringf539bc32012-02-06 00:18:37 -0800350}
351
Gilad Arnold01d458b2015-05-28 06:41:08 -0700352unpack_tarball() {
353 local tarball_path="$1"
354 local dest_dir="$2"
355 local decompress
356 case "${tarball_path}" in
357 *.tbz2|*.tar.bz2) decompress=$(type -p pbzip2 || echo bzip2) ;;
Mike Frysinger978efbf2018-12-20 16:43:26 -0500358 *.tar.xz) decompress=$(type -p pixz || echo xz) ;;
Gilad Arnold01d458b2015-05-28 06:41:08 -0700359 *) die "Unknown tarball compression: ${tarball_path}" ;;
360 esac
Mike Frysinger978efbf2018-12-20 16:43:26 -0500361 ${decompress} -dc <"${tarball_path}" | tar -xp -C "${dest_dir}"
Gilad Arnold01d458b2015-05-28 06:41:08 -0700362}
363
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600364# Find a usable VG name for a given path and device. If there is an existing
365# VG associated with the device, it will be returned. If not, find an unused
366# name in the format cros_<safe_path>_NNN, where safe_path is an escaped version
367# of the last 90 characters of the path and NNN is a counter. Example:
368# /home/user/chromiumos/chroot/ -> cros_home+user+chromiumos+chroot_000.
369# If no unused name with this pattern can be found, return an empty string.
370find_vg_name() {
371 local chroot_path="$1"
372 local chroot_dev="$2"
373 chroot_path=${chroot_path##/}
374 chroot_path=${chroot_path%%/}
375 chroot_path=${chroot_path//[^A-Za-z0-9_+.-]/+}
376 chroot_path=${chroot_path: -$((${#chroot_path} < 90 ? ${#chroot_path} : 90))}
377 local vg_name=""
378 if [ -n "$chroot_dev" ]; then
379 vg_name=$(pvs -q --noheadings -o vg_name "$chroot_dev" 2>/dev/null | \
380 sed -e 's/^ *//')
381 fi
382 if [ -z "$vg_name" ]; then
383 local counter=0
384 vg_name=$(printf "cros_%s_%03d" "$chroot_path" "$counter")
385 while [ "$counter" -lt 1000 ] && vgs "$vg_name" >&/dev/null; do
386 counter=$((counter + 1))
387 vg_name=$(printf "cros_%s_%03d" "$chroot_path" "$counter")
388 done
389 if [ "$counter" -gt 999 ]; then
390 vg_name=""
391 fi
392 fi
393 echo "$vg_name"
394}
395
396# Create a loopback image and mount it on the chroot path so that we can take
397# snapshots before building. If an image already exists, try to mount it. The
398# chroot is initially mounted inside a temporary shared chroot.build subtree
399# that should have already been set up by the parent process, and then bind
400# mounted into the correct final location. The purpose of this indirection is
401# so that processes outside our mount namespace can see the top-level chroot
402# after we finish.
403mount_chroot_image() {
404 local chroot_image="$1"
405 local mount_path="$2"
406
407 # Make sure there's an image.
408 local existing_chroot=0
409 local chroot_dev=""
410 if [ -f "$chroot_image" ]; then
411 info "Attempting to reuse existing image file ${chroot_image}"
412 chroot_dev=$(losetup -j "$chroot_image" | cut -f1 -d:)
413 existing_chroot=1
414 else
415 dd if=/dev/null of="$chroot_image" bs=1G seek=500 >&/dev/null
416 fi
417
418 # Get/scan a loopback device attached to our image.
419 if [ -n "$chroot_dev" ]; then
420 pvscan -q "$chroot_dev" >&/dev/null
421 else
422 chroot_dev=$(losetup -f "$chroot_image" --show)
423 fi
424
425 # Find/create a VG on the loopback device.
426 chroot_vg=$(find_vg_name "$mount_path" "$chroot_dev")
427 if [ -z "$chroot_vg" ]; then
428 die_notrace "Unable to find usable VG name for ${mount_path}."
429 fi
430 if vgs "$chroot_vg" >&/dev/null; then
Benjamin Gordonf68aa942017-07-21 17:00:20 -0600431 vgchange -q -a y --noudevsync "$chroot_vg" >/dev/null || :
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600432 else
433 vgcreate -q "$chroot_vg" "$chroot_dev" >/dev/null
434 fi
435
436 # Find/create an LV inside our VG. If the LV is new, also create the FS.
437 # We need to pass --noudevsync to lvcreate because we're running inside
438 # a separate IPC namespace from the udev process.
439 if lvs "$chroot_vg/chroot" >&/dev/null; then
Benjamin Gordonf68aa942017-07-21 17:00:20 -0600440 lvchange -q -ay "$chroot_vg/chroot" --noudevsync >/dev/null || :
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600441 else
442 lvcreate -q -L 499G -T "${chroot_vg}/thinpool" -V500G -n chroot \
443 --noudevsync >/dev/null
444 mke2fs -q -m 0 -t ext4 "/dev/${chroot_vg}/chroot"
445 fi
446
447 # Mount the FS into a directory that should have been set up as a shared
448 # subtree by our parent process, then bind mount it into the place where
449 # it belongs. The parent will take care of moving the mount to the correct
450 # final place on the outside of our mount namespace after we exit.
451 local temp_chroot="${FLAGS_chroot}.build/chroot"
452 if ! mount -text4 -onoatime "/dev/${chroot_vg}/chroot" "$temp_chroot"; then
453 local chroot_example_opt=""
454 if [[ "$mount_path" != "$DEFAULT_CHROOT_DIR" ]]; then
455 chroot_example_opt="--chroot=$FLAGS_chroot"
456 fi
457
458 die_notrace <<EOF
459
460Unable to mount ${chroot_vg}/chroot on ${temp_chroot}. Check for corrupted
461image ${chroot_image}, or run
462
463cros_sdk --delete $chroot_example_opt
464
465to clean up an old chroot first.
466
467EOF
468 fi
469 mount --make-private "$temp_chroot"
470 mount --bind "$temp_chroot" "$mount_path"
471 mount --make-private "$mount_path"
472 if [ "$existing_chroot" = "1" ]; then
473 info "Mounted existing chroot image."
474 fi
475}
476
Brian Harring35767822012-02-01 23:50:45 -0800477# Handle deleting an existing environment.
Brian Harringf539bc32012-02-06 00:18:37 -0800478if [[ $FLAGS_delete -eq $FLAGS_TRUE || \
Brian Harring35767822012-02-01 23:50:45 -0800479 $FLAGS_replace -eq $FLAGS_TRUE ]]; then
Brian Harringf539bc32012-02-06 00:18:37 -0800480 delete_existing
481 [[ $FLAGS_delete -eq $FLAGS_TRUE ]] && exit 0
482fi
483
484CHROOT_TRUNK="${CHROOT_TRUNK_DIR}"
485PORTAGE="${SRC_ROOT}/third_party/portage"
486OVERLAY="${SRC_ROOT}/third_party/chromiumos-overlay"
487CONFIG_DIR="${OVERLAY}/chromeos/config"
Brian Harring2499bfb2012-12-18 16:23:31 -0800488CHROOT_CONFIG="${CHROOT_TRUNK_DIR}/src/third_party/chromiumos-overlay/chromeos/config"
Mike Frysingerb45dbb52013-12-13 21:14:09 -0500489OVERLAYS_ROOT="/usr/local/portage"
490ECLASS_OVERLAY="${OVERLAYS_ROOT}/eclass-overlay"
491PORTAGE_STABLE_OVERLAY="${OVERLAYS_ROOT}/stable"
492CROSSDEV_OVERLAY="${OVERLAYS_ROOT}/crossdev"
493CHROOT_OVERLAY="${OVERLAYS_ROOT}/chromiumos"
Brian Harringf539bc32012-02-06 00:18:37 -0800494CHROOT_STATE="${FLAGS_chroot}/etc/debian_chroot"
Vincent Palatin5ce24062014-02-26 12:08:23 -0800495CHROOT_VERSION="${FLAGS_chroot}/etc/cros_chroot_version"
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600496CHROOT_IMAGE="${FLAGS_chroot}.img"
Brian Harringf539bc32012-02-06 00:18:37 -0800497
498# Pass proxy variables into the environment.
499for type in http ftp all; do
David Purselld35d7af2015-05-04 16:37:08 -0700500 value=$(env | grep "${type}_proxy" || true)
Brian Harringf539bc32012-02-06 00:18:37 -0800501 if [ -n "${value}" ]; then
502 CHROOT_PASSTHRU+=("$value")
503 fi
504done
505
Brian Harring35767822012-02-01 23:50:45 -0800506# Create the destination directory.
Brian Harringf539bc32012-02-06 00:18:37 -0800507mkdir -p "$FLAGS_chroot"
508
Benjamin Gordon1d5afed2017-06-14 16:35:32 -0600509[[ $FLAGS_useimage -eq $FLAGS_TRUE ]] && \
510 mount_chroot_image "$CHROOT_IMAGE" "$FLAGS_chroot"
511
512# If the version contains something non-zero, we were already created and this
513# is just a re-mount.
514[[ -f "$CHROOT_VERSION" && "$(<$CHROOT_VERSION)" != "0" ]] && exit 0
515
Brian Harringf539bc32012-02-06 00:18:37 -0800516echo
David Purselld35d7af2015-05-04 16:37:08 -0700517if [[ -f "${CHROOT_STATE}" ]]; then
Mike Frysinger51930072014-04-05 13:01:45 -0400518 info "stage3 already set up. Skipping..."
David Purselld35d7af2015-05-04 16:37:08 -0700519elif [[ -z "${FLAGS_stage3_path}" ]]; then
Mike Frysinger51930072014-04-05 13:01:45 -0400520 die_notrace "Please use --stage3_path when bootstrapping"
Brian Harringf539bc32012-02-06 00:18:37 -0800521else
Mike Frysinger51930072014-04-05 13:01:45 -0400522 info "Unpacking stage3..."
Gilad Arnold01d458b2015-05-28 06:41:08 -0700523 unpack_tarball "${FLAGS_stage3_path}" "${FLAGS_chroot}"
David James76764882012-10-24 19:46:29 -0700524 rm -f "$FLAGS_chroot/etc/"make.{globals,conf.user}
Brian Harringf539bc32012-02-06 00:18:37 -0800525fi
526
Vincent Palatin5ce24062014-02-26 12:08:23 -0800527# Ensure that we properly detect when we are inside the chroot.
528# We'll force this to the latest version at the end as needed.
David Purselld35d7af2015-05-04 16:37:08 -0700529if [[ ! -e "${CHROOT_VERSION}" ]]; then
Vincent Palatin5ce24062014-02-26 12:08:23 -0800530 echo "0" > "${CHROOT_VERSION}"
531fi
532
Brian Harring35767822012-02-01 23:50:45 -0800533# Set up users, if needed, before mkdir/mounts below.
Brian Harringf539bc32012-02-06 00:18:37 -0800534[ -f $CHROOT_STATE ] || init_users
535
Brian Harring2499bfb2012-12-18 16:23:31 -0800536# Reset internal vars to force them to the 'inside the chroot' value;
537# since user directories now exist, this can do the upgrade in place.
538set_chroot_trunk_dir "${FLAGS_chroot}" poppycock
539
Brian Harringf539bc32012-02-06 00:18:37 -0800540echo
Brian Harring35767822012-02-01 23:50:45 -0800541info "Setting up mounts..."
542# Set up necessary mounts and make sure we clean them up on exit.
Brian Harring2499bfb2012-12-18 16:23:31 -0800543mkdir -p "${FLAGS_chroot}/${CHROOT_TRUNK_DIR}" \
544 "${FLAGS_chroot}/${DEPOT_TOOLS_DIR}" "${FLAGS_chroot}/run"
Brian Harring35767822012-02-01 23:50:45 -0800545
J. Richard Barnettee80f6de2012-02-24 14:08:34 -0800546# Create a special /etc/make.conf.host_setup that we use to bootstrap
547# the chroot. The regular content for the file will be generated the
548# first time we invoke update_chroot (further down in this script).
549create_bootstrap_host_setup "${FLAGS_chroot}"
Brian Harringf539bc32012-02-06 00:18:37 -0800550
551if ! [ -f "$CHROOT_STATE" ];then
552 INITIALIZE_CHROOT=1
553fi
554
Mike Frysingerba758452012-04-02 13:28:31 -0400555if ! early_enter_chroot bash -c 'type -P pbzip2' >/dev/null ; then
556 # This chroot lacks pbzip2 early on, so we need to disable it.
557 early_env+=(
558 PORTAGE_BZIP2_COMMAND="bzip2"
559 PORTAGE_BUNZIP2_COMMAND="bunzip2"
560 )
561fi
562
Brian Harringf539bc32012-02-06 00:18:37 -0800563if [ -z "${INITIALIZE_CHROOT}" ];then
Brian Harring35767822012-02-01 23:50:45 -0800564 info "chroot already initialized. Skipping..."
Brian Harringf539bc32012-02-06 00:18:37 -0800565else
Brian Harring35767822012-02-01 23:50:45 -0800566 # Run all the init stuff to setup the env.
Brian Harringf539bc32012-02-06 00:18:37 -0800567 init_setup
568fi
569
Brian Harring35767822012-02-01 23:50:45 -0800570# Add file to indicate that it is a chroot.
Mike Frysinger51930072014-04-05 13:01:45 -0400571# Add version of stage3 for update checks.
572echo "STAGE3=${FLAGS_stage3_path}" > "${CHROOT_STATE}"
Brian Harringf539bc32012-02-06 00:18:37 -0800573
Daniel Kurtz51244842017-07-25 01:32:04 +0800574# New versions of the stage3 have Python 3 set as the default. Make sure we
575# default to 2.x as our scripts are only compatible with Python 2. We leave
576# Python 3 installed though as we've started including it in our SDK.
577# We can't just "set 1" because the option order changes for different stage3
578# tarballs.
579early_enter_chroot eselect python update --ignore "3*"
580
Brian Harring35767822012-02-01 23:50:45 -0800581info "Updating portage"
Mike Frysinger66fd81f2012-02-28 13:13:20 -0500582early_enter_chroot emerge -uNv --quiet portage
Brian Harringf539bc32012-02-06 00:18:37 -0800583
Mike Frysinger9a2978c2013-08-04 11:38:43 -0400584# Clear out openrc if it's installed as we don't want it.
David Purselld35d7af2015-05-04 16:37:08 -0700585if [[ -e "${FLAGS_chroot}/usr/share/openrc" ]]; then
Mike Frysinger9a2978c2013-08-04 11:38:43 -0400586 info "Uninstalling openrc"
587 early_enter_chroot env CLEAN_DELAY=0 emerge -qC sys-apps/openrc
Mike Frysinger47e599e2013-10-28 13:30:12 -0400588 # Now update baselayout to get our functions.sh. The unmerge
589 # above removed our copy in the process.
590 early_enter_chroot emerge -uNvq sys-apps/baselayout
Mike Frysinger9a2978c2013-08-04 11:38:43 -0400591fi
592
Bertrand SIMONNET85c96c72014-08-20 12:10:48 -0700593# Add chromite into python path.
Bertrand SIMONNET85c96c72014-08-20 12:10:48 -0700594for python_path in "${FLAGS_chroot}/usr/lib/"python2.*; do
595 python_path+="/site-packages"
596 sudo mkdir -p "${python_path}"
597 sudo ln -s -fT "${CHROOT_TRUNK_DIR}"/chromite "${python_path}"/chromite
598done
599
Chirantan Ekboteaf1b9502016-07-14 11:29:16 -0700600# The stage3 contains an old version of ncurses, which causes a slot conflict
601# later when we try to setup the toolchains. Update it here to the latest
602# version, which gracefully handles the slot issues.
603info "Updating ncurses"
604early_enter_chroot emerge -uNvq sys-libs/ncurses
605
Manoj Gupta63ee9f52018-05-11 18:09:37 -0700606# Update these packages early because they cause build failures when they're
607# concurrently emerged during the main update below.
608# Specific packages:
609# sys-apps/sandbox upgrade breaks dev-libs/nss, also needed by newer libtool.
610# sys-devel/patch 2.6 misapplies git patches in dev-embedded/coreboot-sdk.
611# older sys-devel/automake makes media-libs/freetype build flaky.
612# glibc 2.26+ needs a newer bison.
613info "Updating preinstalled build tools"
Mike Frysinger697ab962019-11-04 20:02:43 -0500614early_enter_chroot ${EMERGE_CMD} -uNv ${USEPKG} ${EMERGE_JOBS} \
Manoj Gupta63ee9f52018-05-11 18:09:37 -0700615 sys-apps/sandbox '>=sys-devel/patch-2.7' sys-devel/automake sys-devel/bison
616
Mike Frysingeraf95b612018-12-20 17:08:19 -0500617# Now that many of the fundamental packages should be in a good state, update
618# the host toolchain. We have to do this step by step ourselves to avoid races
619# when building tools that are actively used (e.g. updating the assembler while
620# also compiling other packages that use the assembler).
621# https://crbug.com/715788
Zdenek Behan2fbd5af2012-03-12 19:38:50 +0100622info "Updating host toolchain"
David Purselld35d7af2015-05-04 16:37:08 -0700623if [[ ! -e "${FLAGS_chroot}/usr/bin/crossdev" ]]; then
Manoj Gupta9b8f8bc2019-06-19 14:17:35 -0700624 early_enter_chroot ${EMERGE_CMD} -uNv crossdev
Mike Frysinger5e07dc72014-11-05 14:40:04 -0500625fi
Zdenek Behan2fbd5af2012-03-12 19:38:50 +0100626TOOLCHAIN_ARGS=( --deleteold )
David Purselld35d7af2015-05-04 16:37:08 -0700627if [[ "${FLAGS_usepkg}" == "${FLAGS_FALSE}" ]]; then
Zdenek Behan2fbd5af2012-03-12 19:38:50 +0100628 TOOLCHAIN_ARGS+=( --nousepkg )
629fi
Mike Frysingeraf95b612018-12-20 17:08:19 -0500630# First the low level compiler tools. These should be fairly independent of
631# the C library, so we can do it first.
Manoj Gupta51880b82019-06-19 13:50:57 -0700632early_enter_chroot ${EMERGE_CMD} -uNv ${USEPKG} ${USEPKGONLY} ${EMERGE_JOBS} \
Mike Frysingeraf95b612018-12-20 17:08:19 -0500633 sys-devel/binutils
634# Next the C library. The compilers often use newer features, but the C library
635# is often designed to work with older compilers.
Manoj Gupta51880b82019-06-19 13:50:57 -0700636early_enter_chroot ${EMERGE_CMD} -uNv ${USEPKG} ${USEPKGONLY} ${EMERGE_JOBS} \
Mike Frysingeraf95b612018-12-20 17:08:19 -0500637 sys-kernel/linux-headers sys-libs/glibc
638# Now we can let the rest of the compiler packages build in parallel as they
639# don't generally rely on each other.
Zdenek Behan2fbd5af2012-03-12 19:38:50 +0100640# Note: early_enter_chroot executes as root.
Brian Harring2499bfb2012-12-18 16:23:31 -0800641early_enter_chroot "${CHROOT_TRUNK_DIR}/chromite/bin/cros_setup_toolchains" \
Zdenek Behan2fbd5af2012-03-12 19:38:50 +0100642 --hostonly "${TOOLCHAIN_ARGS[@]}"
Brian Harringf539bc32012-02-06 00:18:37 -0800643
Ben Chan0c9da662017-05-15 17:29:51 -0700644info "Running emerge curl sudo gentoolkit ..."
Mike Frysinger697ab962019-11-04 20:02:43 -0500645early_enter_chroot ${EMERGE_CMD} -uNv ${USEPKG} ${EMERGE_JOBS} \
Ben Chan0c9da662017-05-15 17:29:51 -0700646 pbzip2 dev-libs/openssl net-misc/curl sudo app-portage/gentoolkit
647
648info "Updating Perl modules"
649early_enter_chroot \
650 "${CHROOT_TRUNK_DIR}/src/scripts/build_library/perl_rebuild.sh"
Paul Drews8bae3b52012-10-10 11:18:13 -0700651
Brian Harringf539bc32012-02-06 00:18:37 -0800652if [ -n "${INITIALIZE_CHROOT}" ]; then
653 # If we're creating a new chroot, we also want to set it to the latest
654 # version.
Alex Kleine5e0ea92018-09-13 17:18:15 -0600655 enter_chroot run_chroot_version_hooks --init-latest
Brian Harringf539bc32012-02-06 00:18:37 -0800656fi
657
Brian Harring35767822012-02-01 23:50:45 -0800658# Update chroot.
Zdenek Behan2fbd5af2012-03-12 19:38:50 +0100659# Skip toolchain update because it already happened above, and the chroot is
660# not ready to emerge all cross toolchains.
661UPDATE_ARGS=( --skip_toolchain_update )
David Purselld35d7af2015-05-04 16:37:08 -0700662if [[ "${FLAGS_usepkg}" == "${FLAGS_TRUE}" ]]; then
Brian Harring35767822012-02-01 23:50:45 -0800663 UPDATE_ARGS+=( --usepkg )
Brian Harringf539bc32012-02-06 00:18:37 -0800664else
Brian Harring35767822012-02-01 23:50:45 -0800665 UPDATE_ARGS+=( --nousepkg )
Brian Harringf539bc32012-02-06 00:18:37 -0800666fi
David James184e3902012-02-23 20:19:28 -0800667if [[ "${FLAGS_jobs}" -ne -1 ]]; then
David Purselld35d7af2015-05-04 16:37:08 -0700668 UPDATE_ARGS+=( --jobs="${FLAGS_jobs}" )
David James184e3902012-02-23 20:19:28 -0800669fi
Brian Harring2499bfb2012-12-18 16:23:31 -0800670enter_chroot "${CHROOT_TRUNK_DIR}/src/scripts/update_chroot" "${UPDATE_ARGS[@]}"
Brian Harringf539bc32012-02-06 00:18:37 -0800671
Stefan Zager48c776b2013-10-09 13:01:25 -0700672# The java-config package atm does not support $ROOT. Select a default
673# VM ourselves until that gets fixed upstream.
674enter_chroot sudo java-config --set-system-vm 1
675
Brian Harring35767822012-02-01 23:50:45 -0800676CHROOT_EXAMPLE_OPT=""
677if [[ "$FLAGS_chroot" != "$DEFAULT_CHROOT_DIR" ]]; then
Brian Harringf539bc32012-02-06 00:18:37 -0800678 CHROOT_EXAMPLE_OPT="--chroot=$FLAGS_chroot"
679fi
680
Matt Tennant0a9d32d2012-07-30 16:51:37 -0700681command_completed
Brian Harringf539bc32012-02-06 00:18:37 -0800682
Brian Harring35767822012-02-01 23:50:45 -0800683cat <<EOF
Mike Frysingerbdc4fb12012-02-10 11:20:03 -0500684
685${CROS_LOG_PREFIX:-cros_sdk}: All set up. To enter the chroot, run:
686$ cros_sdk --enter $CHROOT_EXAMPLE_OPT
Brian Harring35767822012-02-01 23:50:45 -0800687
688CAUTION: Do *NOT* rm -rf the chroot directory; if there are stale bind
689mounts you may end up deleting your source tree too. To unmount and
690delete the chroot cleanly, use:
691$ cros_sdk --delete $CHROOT_EXAMPLE_OPT
Mike Frysingerbdc4fb12012-02-10 11:20:03 -0500692
Brian Harring35767822012-02-01 23:50:45 -0800693EOF
David James22dc2ba2012-11-29 15:46:58 -0800694
Mike Frysinger60b580b2019-07-29 00:39:16 -0400695is_nfs() {
696 [[ $(stat -f -L -c %T "$1") == "nfs" ]]
697}
698
Mike Frysinger88cd8c82019-10-03 16:51:28 -0400699if is_nfs "${SUDO_HOME}"; then
700 warn "${SUDO_HOME} is on NFS. This is untested. Send patches if it's broken."
Mike Frysinger60b580b2019-07-29 00:39:16 -0400701fi