Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Matt Tennant | 0a9d32d | 2012-07-30 16:51:37 -0700 | [diff] [blame] | 3 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 4 | # 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 | |
| 12 | SCRIPT_ROOT=$(readlink -f $(dirname "$0")/..) |
| 13 | . "${SCRIPT_ROOT}/common.sh" || exit 1 |
| 14 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 15 | ENTER_CHROOT=$(readlink -f $(dirname "$0")/enter_chroot.sh) |
| 16 | |
Zdenek Behan | 4d21a29 | 2012-08-17 04:02:29 +0200 | [diff] [blame] | 17 | if [ -n "${USE}" ]; then |
| 18 | echo "$SCRIPT_NAME: Building with a non-empty USE: ${USE}" |
| 19 | echo "This modifies the expected behaviour and can fail." |
| 20 | fi |
| 21 | |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 22 | # Check if the host machine architecture is supported. |
| 23 | ARCHITECTURE="$(uname -m)" |
| 24 | if [[ "$ARCHITECTURE" != "x86_64" ]]; then |
| 25 | echo "$SCRIPT_NAME: $ARCHITECTURE is not supported as a host machine architecture." |
| 26 | exit 1 |
| 27 | fi |
| 28 | |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 29 | # Script must be run outside the chroot and as root. |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 30 | assert_outside_chroot |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 31 | assert_root_user |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 32 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 33 | # Define command line flags. |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 34 | # See http://code.google.com/p/shflags/wiki/Documentation10x |
| 35 | |
| 36 | DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \ |
| 37 | "Destination dir for the chroot environment." |
| 38 | DEFINE_boolean usepkg $FLAGS_TRUE "Use binary packages to bootstrap." |
| 39 | DEFINE_boolean delete $FLAGS_FALSE "Delete an existing chroot." |
| 40 | DEFINE_boolean replace $FLAGS_FALSE "Overwrite existing chroot, if any." |
| 41 | DEFINE_integer jobs -1 "How many packages to build in parallel at maximum." |
| 42 | DEFINE_boolean fast ${DEFAULT_FAST} "Call many emerges in parallel" |
| 43 | DEFINE_string stage3_date "2010.03.09" \ |
| 44 | "Use the stage3 with the given date." |
| 45 | DEFINE_string stage3_path "" \ |
| 46 | "Use the stage3 located on this path." |
Brian Harring | 7b6f377 | 2012-09-23 14:01:13 -0700 | [diff] [blame] | 47 | DEFINE_string cache_dir "" "Directory to store caches within." |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 48 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 49 | # Parse command line flags. |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 50 | FLAGS_HELP="usage: $SCRIPT_NAME [flags]" |
| 51 | FLAGS "$@" || exit 1 |
| 52 | eval set -- "${FLAGS_ARGV}" |
| 53 | check_flags_only_and_allow_null_arg "$@" && set -- |
| 54 | |
Peter Mayo | 4411efe | 2012-09-21 04:41:27 -0400 | [diff] [blame] | 55 | CROS_LOG_PREFIX=cros_sdk:make_chroot |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 56 | SUDO_HOME=$(eval echo ~${SUDO_USER}) |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 57 | |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 58 | # Set the right umask for chroot creation. |
| 59 | umask 022 |
| 60 | |
| 61 | # Only now can we die on error. shflags functions leak non-zero error codes, |
Brian Harring | 7f175a5 | 2012-03-02 05:37:00 -0800 | [diff] [blame] | 62 | # so will die prematurely if 'switch_to_strict_mode' is specified before now. |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 63 | # TODO: replace shflags with something less error-prone, or contribute a fix. |
Brian Harring | 7f175a5 | 2012-03-02 05:37:00 -0800 | [diff] [blame] | 64 | switch_to_strict_mode |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 65 | |
Brian Harring | 7b6f377 | 2012-09-23 14:01:13 -0700 | [diff] [blame] | 66 | [[ "${FLAGS_delete}" == "${FLAGS_FALSE}" ]] && \ |
| 67 | [[ -z "${FLAGS_cache_dir}" ]] && \ |
| 68 | die "--cache_dir is required" |
| 69 | |
J. Richard Barnette | e80f6de | 2012-02-24 14:08:34 -0800 | [diff] [blame] | 70 | . "${SCRIPT_ROOT}"/sdk_lib/make_conf_util.sh |
| 71 | |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 72 | FULLNAME="ChromeOS Developer" |
| 73 | DEFGROUPS="eng,adm,cdrom,floppy,audio,video,portage" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 74 | |
| 75 | USEPKG="" |
| 76 | if [[ $FLAGS_usepkg -eq $FLAGS_TRUE ]]; then |
| 77 | # Use binary packages. Include all build-time dependencies, |
| 78 | # so as to avoid unnecessary differences between source |
| 79 | # and binary builds. |
| 80 | USEPKG="--getbinpkg --usepkg --with-bdeps y" |
| 81 | fi |
| 82 | |
| 83 | # Support faster build if necessary. |
| 84 | EMERGE_CMD="emerge" |
| 85 | if [ "$FLAGS_fast" -eq "${FLAGS_TRUE}" ]; then |
Brian Harring | 2499bfb | 2012-12-18 16:23:31 -0800 | [diff] [blame] | 86 | CHROOT_CHROMITE_DIR="${CHROOT_TRUNK_DIR}/chromite" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 87 | EMERGE_CMD="${CHROOT_CHROMITE_DIR}/bin/parallel_emerge" |
| 88 | fi |
| 89 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 90 | ENTER_CHROOT_ARGS=( |
| 91 | CROS_WORKON_SRCROOT="$CHROOT_TRUNK" |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 92 | PORTAGE_USERNAME="${SUDO_USER}" |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 93 | IGNORE_PREFLIGHT_BINHOST="$IGNORE_PREFLIGHT_BINHOST" |
| 94 | ) |
| 95 | |
| 96 | # Invoke enter_chroot. This can only be used after sudo has been installed. |
Mike Frysinger | 6b1abb2 | 2012-05-11 13:44:06 -0400 | [diff] [blame] | 97 | enter_chroot() { |
Brian Harring | 7b6f377 | 2012-09-23 14:01:13 -0700 | [diff] [blame] | 98 | "$ENTER_CHROOT" --cache_dir "${FLAGS_cache_dir}" --chroot "$FLAGS_chroot" \ |
| 99 | -- "${ENTER_CHROOT_ARGS[@]}" "$@" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 100 | } |
| 101 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 102 | # Invoke enter_chroot running the command as root, and w/out sudo. |
| 103 | # This should be used prior to sudo being merged. |
Mike Frysinger | ba75845 | 2012-04-02 13:28:31 -0400 | [diff] [blame] | 104 | early_env=() |
Mike Frysinger | 6b1abb2 | 2012-05-11 13:44:06 -0400 | [diff] [blame] | 105 | early_enter_chroot() { |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 106 | "$ENTER_CHROOT" --chroot "$FLAGS_chroot" --early_make_chroot \ |
Brian Harring | 7b6f377 | 2012-09-23 14:01:13 -0700 | [diff] [blame] | 107 | --cache_dir "${FLAGS_cache_dir}" \ |
Mike Frysinger | ba75845 | 2012-04-02 13:28:31 -0400 | [diff] [blame] | 108 | -- "${ENTER_CHROOT_ARGS[@]}" "${early_env[@]}" "$@" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Mike Frysinger | 4bb8645 | 2013-08-02 13:44:18 -0400 | [diff] [blame] | 111 | # 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 James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 117 | bare_chroot() { |
Mike Frysinger | 4bb8645 | 2013-08-02 13:44:18 -0400 | [diff] [blame] | 118 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:${PATH} \ |
| 119 | chroot "${FLAGS_chroot}" "$@" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 120 | } |
| 121 | |
Mike Frysinger | 6b1abb2 | 2012-05-11 13:44:06 -0400 | [diff] [blame] | 122 | cleanup() { |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 123 | # Clean up mounts |
| 124 | safe_umount_tree "${FLAGS_chroot}" |
| 125 | } |
| 126 | |
Mike Frysinger | 6b1abb2 | 2012-05-11 13:44:06 -0400 | [diff] [blame] | 127 | delete_existing() { |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 128 | # Delete old chroot dir. |
| 129 | if [[ ! -e "$FLAGS_chroot" ]]; then |
| 130 | return |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 131 | fi |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 132 | info "Cleaning up old mount points..." |
| 133 | cleanup |
| 134 | info "Deleting $FLAGS_chroot..." |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 135 | rm -rf "$FLAGS_chroot" |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 136 | info "Done." |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 137 | } |
| 138 | |
Mike Frysinger | 6b1abb2 | 2012-05-11 13:44:06 -0400 | [diff] [blame] | 139 | init_users () { |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 140 | info "Set timezone..." |
| 141 | # date +%Z has trouble with daylight time, so use host's info. |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 142 | rm -f "${FLAGS_chroot}/etc/localtime" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 143 | if [ -f /etc/localtime ] ; then |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 144 | cp /etc/localtime "${FLAGS_chroot}/etc" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 145 | else |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 146 | ln -sf /usr/share/zoneinfo/PST8PDT "${FLAGS_chroot}/etc/localtime" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 147 | fi |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 148 | info "Adding user/group..." |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 149 | # Add ourselves as a user inside the chroot. |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 150 | bare_chroot groupadd -g 5000 eng |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 151 | # We need the UID to match the host user's. This can conflict with |
| 152 | # a particular chroot UID. At the same time, the added user has to |
| 153 | # be a primary user for the given UID for sudo to work, which is |
| 154 | # determined by the order in /etc/passwd. Let's put ourselves on top |
| 155 | # of the file. |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 156 | bare_chroot useradd -o -G ${DEFGROUPS} -g eng -u ${SUDO_UID} -s \ |
Simran Basi | ccfc7ee | 2014-10-14 13:43:10 -0700 | [diff] [blame^] | 157 | /bin/bash -m -c "${FULLNAME}" ${SUDO_USER} |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 158 | # Because passwd generally isn't sorted and the entry ended up at the |
| 159 | # bottom, it is safe to just take it and move it to top instead. |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 160 | sed -e '1{h;d};$!{H;d};$G' -i "${FLAGS_chroot}/etc/passwd" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 161 | } |
| 162 | |
Mike Frysinger | 6b1abb2 | 2012-05-11 13:44:06 -0400 | [diff] [blame] | 163 | init_setup () { |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 164 | info "Running init_setup()..." |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 165 | mkdir -p -m 755 "${FLAGS_chroot}/usr" \ |
Mike Frysinger | b45dbb5 | 2013-12-13 21:14:09 -0500 | [diff] [blame] | 166 | "${FLAGS_chroot}${OVERLAYS_ROOT}" \ |
Mike Frysinger | 36beaaa | 2014-09-25 15:52:27 -0400 | [diff] [blame] | 167 | "${FLAGS_chroot}"/"${CROSSDEV_OVERLAY}/metadata" |
| 168 | # Newer portage complains about bare overlays. Create the file that crossdev |
| 169 | # will also create later on. |
| 170 | cat <<EOF > "${FLAGS_chroot}/${CROSSDEV_OVERLAY}/metadata/layout.conf" |
| 171 | # Autogenerated and managed by crossdev |
| 172 | # Delete the above line if you want to manage this file yourself |
| 173 | masters = portage-stable chromiumos |
| 174 | repo-name = crossdev |
| 175 | use-manifests = true |
| 176 | thin-manifests = true |
| 177 | EOF |
Mike Frysinger | b45dbb5 | 2013-12-13 21:14:09 -0500 | [diff] [blame] | 178 | ln -sf "${CHROOT_TRUNK_DIR}/src/third_party/eclass-overlay" \ |
| 179 | "${FLAGS_chroot}"/"${ECLASS_OVERLAY}" |
Brian Harring | 2499bfb | 2012-12-18 16:23:31 -0800 | [diff] [blame] | 180 | ln -sf "${CHROOT_TRUNK_DIR}/src/third_party/chromiumos-overlay" \ |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 181 | "${FLAGS_chroot}"/"${CHROOT_OVERLAY}" |
Brian Harring | 2499bfb | 2012-12-18 16:23:31 -0800 | [diff] [blame] | 182 | ln -sf "${CHROOT_TRUNK_DIR}/src/third_party/portage-stable" \ |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 183 | "${FLAGS_chroot}"/"${PORTAGE_STABLE_OVERLAY}" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 184 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 185 | # Some operations need an mtab. |
Mike Frysinger | b47a4ff | 2013-02-20 17:29:05 -0500 | [diff] [blame] | 186 | ln -sfT /proc/mounts "${FLAGS_chroot}/etc/mtab" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 187 | |
| 188 | # Set up sudoers. Inside the chroot, the user can sudo without a password. |
| 189 | # (Safe enough, since the only way into the chroot is to 'sudo chroot', so |
| 190 | # the user's already typed in one sudo password...) |
| 191 | # Make sure the sudoers.d subdir exists as older stage3 base images lack it. |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 192 | mkdir -p "${FLAGS_chroot}/etc/sudoers.d" |
Brian Harring | 06d3c2e | 2012-08-23 07:35:43 -0700 | [diff] [blame] | 193 | |
| 194 | # Use the standardized upgrade script to setup proxied vars. |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 195 | load_environment_whitelist |
| 196 | bash -e "${SCRIPT_ROOT}/chroot_version_hooks.d/45_rewrite_sudoers.d" \ |
| 197 | "${FLAGS_chroot}" "${SUDO_USER}" "${ENVIRONMENT_WHITELIST[@]}" |
Brian Harring | 06d3c2e | 2012-08-23 07:35:43 -0700 | [diff] [blame] | 198 | |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 199 | find "${FLAGS_chroot}/etc/"sudoers* -type f -exec chmod 0440 {} + |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 200 | # Fix bad group for some. |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 201 | chown -R root:root "${FLAGS_chroot}/etc/"sudoers* |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 202 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 203 | info "Setting up hosts/resolv..." |
| 204 | # Copy config from outside chroot into chroot. |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 205 | cp /etc/{hosts,resolv.conf} "$FLAGS_chroot/etc/" |
| 206 | chmod 0644 "$FLAGS_chroot"/etc/{hosts,resolv.conf} |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 207 | |
| 208 | # Setup host make.conf. This includes any overlay that we may be using |
| 209 | # and a pointer to pre-built packages. |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 210 | # TODO: This should really be part of a profile in the portage. |
| 211 | info "Setting up /etc/make.*..." |
Mike Frysinger | c6e1ace | 2013-03-22 00:49:30 -0400 | [diff] [blame] | 212 | rm -f "${FLAGS_chroot}"/etc/{,portage/}make.{conf,profile} |
| 213 | mkdir -p "${FLAGS_chroot}/etc/portage" |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 214 | ln -sf "${CHROOT_CONFIG}/make.conf.amd64-host" \ |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 215 | "${FLAGS_chroot}/etc/make.conf" |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 216 | ln -sf "${CHROOT_OVERLAY}/profiles/default/linux/amd64/10.0" \ |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 217 | "${FLAGS_chroot}/etc/make.profile" |
| 218 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 219 | # Create make.conf.user . |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 220 | touch "${FLAGS_chroot}"/etc/make.conf.user |
| 221 | chmod 0644 "${FLAGS_chroot}"/etc/make.conf.user |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 222 | |
| 223 | # Create directories referred to by our conf files. |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 224 | mkdir -p -m 775 "${FLAGS_chroot}/var/lib/portage/pkgs" \ |
Brian Harring | 7b6f377 | 2012-09-23 14:01:13 -0700 | [diff] [blame] | 225 | "${FLAGS_chroot}/var/cache/"chromeos-{cache,chrome} \ |
| 226 | "${FLAGS_chroot}/etc/profile.d" |
| 227 | |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 228 | echo "export CHROMEOS_CACHEDIR=/var/cache/chromeos-cache" > \ |
| 229 | "${FLAGS_chroot}/etc/profile.d/chromeos-cachedir.sh" |
| 230 | chmod 0644 "${FLAGS_chroot}/etc/profile.d/chromeos-cachedir.sh" |
| 231 | rm -rf "${FLAGS_chroot}/var/cache/distfiles" |
| 232 | ln -s chromeos-cache/distfiles "${FLAGS_chroot}/var/cache/distfiles" |
Brian Harring | 36b102b | 2012-02-06 23:34:25 -0800 | [diff] [blame] | 233 | |
| 234 | # Run this from w/in the chroot so we use whatever uid/gid |
| 235 | # these are defined as w/in the chroot. |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 236 | bare_chroot chown "${SUDO_USER}:portage" /var/cache/chromeos-chrome |
Brian Harring | 7ee892d | 2012-02-02 09:33:10 -0800 | [diff] [blame] | 237 | |
| 238 | # These are created for compatibility while transitioning |
| 239 | # make.conf and friends over to the new location. |
Brian Harring | 7b6f377 | 2012-09-23 14:01:13 -0700 | [diff] [blame] | 240 | # TODO(ferringb): remove this 01/13 or so. |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 241 | ln -s ../../cache/chromeos-cache/distfiles/host \ |
Brian Harring | 7ee892d | 2012-02-02 09:33:10 -0800 | [diff] [blame] | 242 | "${FLAGS_chroot}/var/lib/portage/distfiles" |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 243 | ln -s ../../cache/chromeos-cache/distfiles/target \ |
Brian Harring | 7ee892d | 2012-02-02 09:33:10 -0800 | [diff] [blame] | 244 | "${FLAGS_chroot}/var/lib/portage/distfiles-target" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 245 | |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 246 | # Add chromite/bin and depot_tools into the path globally; note that the |
| 247 | # chromite wrapper itself might also be found in depot_tools. |
| 248 | # We rely on 'env-update' getting called below. |
| 249 | target="${FLAGS_chroot}/etc/env.d/99chromiumos" |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 250 | cat <<EOF > "${target}" |
Brian Harring | 2499bfb | 2012-12-18 16:23:31 -0800 | [diff] [blame] | 251 | PATH=${CHROOT_TRUNK_DIR}/chromite/bin:${DEPOT_TOOLS_DIR} |
| 252 | CROS_WORKON_SRCROOT="${CHROOT_TRUNK_DIR}" |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 253 | PORTAGE_USERNAME=${SUDO_USER} |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 254 | EOF |
| 255 | |
| 256 | # TODO(zbehan): Configure stuff that is usually configured in postinst's, |
Mike Frysinger | eb1a9b4 | 2012-03-28 16:21:04 -0400 | [diff] [blame] | 257 | # but wasn't. Fix the postinst's. |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 258 | info "Running post-inst configuration hacks" |
| 259 | early_enter_chroot env-update |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 260 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 261 | # This is basically a sanity check of our chroot. If any of these |
| 262 | # don't exist, then either bind mounts have failed, an invocation |
| 263 | # from above is broke, or some assumption about the stage3 is no longer |
| 264 | # true. |
| 265 | early_enter_chroot ls -l /etc/make.{conf,profile} \ |
| 266 | /usr/local/portage/chromiumos/profiles/default/linux/amd64/10.0 |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 267 | |
| 268 | target="${FLAGS_chroot}/etc/profile.d" |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 269 | mkdir -p "${target}" |
| 270 | cat << EOF > "${target}/chromiumos-niceties.sh" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 271 | # Niceties for interactive logins. (cr) denotes this is a chroot, the |
| 272 | # __git_branch_ps1 prints current git branch in ./ . The $r behavior is to |
| 273 | # make sure we don't reset the previous $? value which later formats in |
| 274 | # $PS1 might rely on. |
| 275 | PS1='\$(r=\$?; __git_branch_ps1 "(%s) "; exit \$r)'"\${PS1}" |
| 276 | PS1="(cr) \${PS1}" |
| 277 | EOF |
| 278 | |
| 279 | # Select a small set of locales for the user if they haven't done so |
| 280 | # already. This makes glibc upgrades cheap by only generating a small |
| 281 | # set of locales. The ones listed here are basically for the buildbots |
| 282 | # which always assume these are available. This works in conjunction |
| 283 | # with `cros_sdk --enter`. |
| 284 | # http://crosbug.com/20378 |
| 285 | local localegen="$FLAGS_chroot/etc/locale.gen" |
| 286 | if ! grep -q -v -e '^#' -e '^$' "${localegen}" ; then |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 287 | cat <<EOF >> "${localegen}" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 288 | en_US ISO-8859-1 |
| 289 | en_US.UTF-8 UTF-8 |
| 290 | EOF |
| 291 | fi |
| 292 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 293 | # Automatically change to scripts directory. |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 294 | echo 'cd ${CHROOT_CWD:-~/trunk/src/scripts}' \ |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 295 | | user_append "$FLAGS_chroot/home/${SUDO_USER}/.bash_profile" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 296 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 297 | # Enable bash completion for build scripts. |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 298 | echo ". ~/trunk/src/scripts/bash_completion" \ |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 299 | | user_append "$FLAGS_chroot/home/${SUDO_USER}/.bashrc" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 300 | |
Peter Mayo | e18c7d4 | 2013-06-06 13:41:03 -0400 | [diff] [blame] | 301 | if [[ "${SUDO_USER}" = "chrome-bot" && -d "${SUDO_HOME}/.ssh" ]]; then |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 302 | # Copy ssh keys, so chroot'd chrome-bot can scp files from chrome-web. |
Peter Mayo | 3105695 | 2013-06-06 16:22:55 -0400 | [diff] [blame] | 303 | user_cp -rp "${SUDO_HOME}/.ssh" "$FLAGS_chroot/home/${SUDO_USER}/" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 304 | fi |
| 305 | |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 306 | if [[ -f ${SUDO_HOME}/.gitconfig ]]; then |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 307 | # Copy .gitconfig into chroot so repo and git can be used from inside. |
| 308 | # This is required for repo to work since it validates the email address. |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 309 | echo "Copying ~/.gitconfig into chroot" |
David James | 22dc2ba | 2012-11-29 15:46:58 -0800 | [diff] [blame] | 310 | user_cp "${SUDO_HOME}/.gitconfig" "$FLAGS_chroot/home/${SUDO_USER}/" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 311 | fi |
Luigi Semenzato | 2443fdd | 2012-05-29 10:34:04 -0700 | [diff] [blame] | 312 | |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 313 | # If the user didn't set up their username in their gitconfig, look |
| 314 | # at the default git settings for the user. |
| 315 | if ! git config -f "${SUDO_HOME}/.gitconfig" user.email >& /dev/null; then |
| 316 | ident=$(cd /; sudo -u ${SUDO_USER} -- git var GIT_COMMITTER_IDENT || :) |
| 317 | ident_name=${ident%% <*} |
| 318 | ident_email=${ident%%>*}; ident_email=${ident_email##*<} |
| 319 | gitconfig=${FLAGS_chroot}/home/${SUDO_USER}/.gitconfig |
| 320 | git config -f ${gitconfig} --replace-all user.name "${ident_name}" || : |
| 321 | git config -f ${gitconfig} --replace-all user.email "${ident_email}" || : |
| 322 | chown ${SUDO_UID}:${SUDO_GID} ${FLAGS_chroot}/home/${SUDO_USER}/.gitconfig |
| 323 | fi |
| 324 | |
| 325 | if [[ -f ${SUDO_HOME}/.cros_chroot_init ]]; then |
| 326 | sudo -u ${SUDO_USER} -- /bin/bash "${SUDO_HOME}/.cros_chroot_init" \ |
| 327 | "${FLAGS_chroot}" |
Luigi Semenzato | 2443fdd | 2012-05-29 10:34:04 -0700 | [diff] [blame] | 328 | fi |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 329 | } |
| 330 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 331 | # Handle deleting an existing environment. |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 332 | if [[ $FLAGS_delete -eq $FLAGS_TRUE || \ |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 333 | $FLAGS_replace -eq $FLAGS_TRUE ]]; then |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 334 | delete_existing |
| 335 | [[ $FLAGS_delete -eq $FLAGS_TRUE ]] && exit 0 |
| 336 | fi |
| 337 | |
| 338 | CHROOT_TRUNK="${CHROOT_TRUNK_DIR}" |
| 339 | PORTAGE="${SRC_ROOT}/third_party/portage" |
| 340 | OVERLAY="${SRC_ROOT}/third_party/chromiumos-overlay" |
| 341 | CONFIG_DIR="${OVERLAY}/chromeos/config" |
Brian Harring | 2499bfb | 2012-12-18 16:23:31 -0800 | [diff] [blame] | 342 | CHROOT_CONFIG="${CHROOT_TRUNK_DIR}/src/third_party/chromiumos-overlay/chromeos/config" |
Mike Frysinger | b45dbb5 | 2013-12-13 21:14:09 -0500 | [diff] [blame] | 343 | OVERLAYS_ROOT="/usr/local/portage" |
| 344 | ECLASS_OVERLAY="${OVERLAYS_ROOT}/eclass-overlay" |
| 345 | PORTAGE_STABLE_OVERLAY="${OVERLAYS_ROOT}/stable" |
| 346 | CROSSDEV_OVERLAY="${OVERLAYS_ROOT}/crossdev" |
| 347 | CHROOT_OVERLAY="${OVERLAYS_ROOT}/chromiumos" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 348 | CHROOT_STATE="${FLAGS_chroot}/etc/debian_chroot" |
Vincent Palatin | 5ce2406 | 2014-02-26 12:08:23 -0800 | [diff] [blame] | 349 | CHROOT_VERSION="${FLAGS_chroot}/etc/cros_chroot_version" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 350 | |
| 351 | # Pass proxy variables into the environment. |
| 352 | for type in http ftp all; do |
| 353 | value=$(env | grep ${type}_proxy || true) |
| 354 | if [ -n "${value}" ]; then |
| 355 | CHROOT_PASSTHRU+=("$value") |
| 356 | fi |
| 357 | done |
| 358 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 359 | # Create the destination directory. |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 360 | mkdir -p "$FLAGS_chroot" |
| 361 | |
| 362 | echo |
Mike Frysinger | 5193007 | 2014-04-05 13:01:45 -0400 | [diff] [blame] | 363 | if [[ -f ${CHROOT_STATE} ]]; then |
| 364 | info "stage3 already set up. Skipping..." |
| 365 | elif [[ -z ${FLAGS_stage3_path} ]]; then |
| 366 | die_notrace "Please use --stage3_path when bootstrapping" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 367 | else |
Mike Frysinger | 5193007 | 2014-04-05 13:01:45 -0400 | [diff] [blame] | 368 | info "Unpacking stage3..." |
| 369 | case ${FLAGS_stage3_path} in |
Zdenek Behan | 074f9ef | 2012-05-30 01:23:59 +0200 | [diff] [blame] | 370 | *.tbz2|*.tar.bz2) DECOMPRESS=$(type -p pbzip2 || echo bzip2) ;; |
| 371 | *.tar.xz) DECOMPRESS="xz" ;; |
Mike Frysinger | 5193007 | 2014-04-05 13:01:45 -0400 | [diff] [blame] | 372 | *) die "Unknown tarball compression: ${FLAGS_stage3_path}" ;; |
Zdenek Behan | 074f9ef | 2012-05-30 01:23:59 +0200 | [diff] [blame] | 373 | esac |
Mike Frysinger | 5193007 | 2014-04-05 13:01:45 -0400 | [diff] [blame] | 374 | ${DECOMPRESS} -dc "${FLAGS_stage3_path}" | \ |
David James | 7676488 | 2012-10-24 19:46:29 -0700 | [diff] [blame] | 375 | tar -xp -C "${FLAGS_chroot}" |
| 376 | rm -f "$FLAGS_chroot/etc/"make.{globals,conf.user} |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 377 | fi |
| 378 | |
Vincent Palatin | 5ce2406 | 2014-02-26 12:08:23 -0800 | [diff] [blame] | 379 | # Ensure that we properly detect when we are inside the chroot. |
| 380 | # We'll force this to the latest version at the end as needed. |
| 381 | if [[ ! -e ${CHROOT_VERSION} ]]; then |
| 382 | echo "0" > "${CHROOT_VERSION}" |
| 383 | fi |
| 384 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 385 | # Set up users, if needed, before mkdir/mounts below. |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 386 | [ -f $CHROOT_STATE ] || init_users |
| 387 | |
Brian Harring | 2499bfb | 2012-12-18 16:23:31 -0800 | [diff] [blame] | 388 | # Reset internal vars to force them to the 'inside the chroot' value; |
| 389 | # since user directories now exist, this can do the upgrade in place. |
| 390 | set_chroot_trunk_dir "${FLAGS_chroot}" poppycock |
| 391 | |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 392 | echo |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 393 | info "Setting up mounts..." |
| 394 | # Set up necessary mounts and make sure we clean them up on exit. |
Brian Harring | 2499bfb | 2012-12-18 16:23:31 -0800 | [diff] [blame] | 395 | mkdir -p "${FLAGS_chroot}/${CHROOT_TRUNK_DIR}" \ |
| 396 | "${FLAGS_chroot}/${DEPOT_TOOLS_DIR}" "${FLAGS_chroot}/run" |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 397 | |
J. Richard Barnette | e80f6de | 2012-02-24 14:08:34 -0800 | [diff] [blame] | 398 | # Create a special /etc/make.conf.host_setup that we use to bootstrap |
| 399 | # the chroot. The regular content for the file will be generated the |
| 400 | # first time we invoke update_chroot (further down in this script). |
| 401 | create_bootstrap_host_setup "${FLAGS_chroot}" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 402 | |
| 403 | if ! [ -f "$CHROOT_STATE" ];then |
| 404 | INITIALIZE_CHROOT=1 |
| 405 | fi |
| 406 | |
Mike Frysinger | ba75845 | 2012-04-02 13:28:31 -0400 | [diff] [blame] | 407 | if ! early_enter_chroot bash -c 'type -P pbzip2' >/dev/null ; then |
| 408 | # This chroot lacks pbzip2 early on, so we need to disable it. |
| 409 | early_env+=( |
| 410 | PORTAGE_BZIP2_COMMAND="bzip2" |
| 411 | PORTAGE_BUNZIP2_COMMAND="bunzip2" |
| 412 | ) |
| 413 | fi |
| 414 | |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 415 | if [ -z "${INITIALIZE_CHROOT}" ];then |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 416 | info "chroot already initialized. Skipping..." |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 417 | else |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 418 | # Run all the init stuff to setup the env. |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 419 | init_setup |
| 420 | fi |
| 421 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 422 | # Add file to indicate that it is a chroot. |
Mike Frysinger | 5193007 | 2014-04-05 13:01:45 -0400 | [diff] [blame] | 423 | # Add version of stage3 for update checks. |
| 424 | echo "STAGE3=${FLAGS_stage3_path}" > "${CHROOT_STATE}" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 425 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 426 | info "Updating portage" |
Mike Frysinger | 66fd81f | 2012-02-28 13:13:20 -0500 | [diff] [blame] | 427 | early_enter_chroot emerge -uNv --quiet portage |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 428 | |
Mike Frysinger | 9a2978c | 2013-08-04 11:38:43 -0400 | [diff] [blame] | 429 | # Clear out openrc if it's installed as we don't want it. |
| 430 | if [[ -e ${FLAGS_chroot}/usr/share/openrc ]]; then |
| 431 | info "Uninstalling openrc" |
| 432 | early_enter_chroot env CLEAN_DELAY=0 emerge -qC sys-apps/openrc |
Mike Frysinger | 47e599e | 2013-10-28 13:30:12 -0400 | [diff] [blame] | 433 | # Now update baselayout to get our functions.sh. The unmerge |
| 434 | # above removed our copy in the process. |
| 435 | early_enter_chroot emerge -uNvq sys-apps/baselayout |
Mike Frysinger | 9a2978c | 2013-08-04 11:38:43 -0400 | [diff] [blame] | 436 | fi |
| 437 | |
David James | 31097c3 | 2013-11-06 18:56:59 -0800 | [diff] [blame] | 438 | # The stage3 contains an old version of Python. Upgrade it first so that |
| 439 | # parallel_emerge (and chromite libs) can use the latest Python syntax. |
| 440 | info "Updating python-2.x" |
| 441 | early_enter_chroot emerge -uNvq =dev-lang/python-2* |
| 442 | |
| 443 | # New versions of the stage3 have Python 3 set as the default. Get rid of it, |
| 444 | # as our scripts are only compatible with Python 2. |
| 445 | early_enter_chroot eselect python set 1 |
| 446 | early_enter_chroot env CLEAN_DELAY=0 emerge -qC =dev-lang/python-3* || true |
Mike Frysinger | 83520dd | 2013-03-22 01:37:37 -0400 | [diff] [blame] | 447 | |
Bertrand SIMONNET | 85c96c7 | 2014-08-20 12:10:48 -0700 | [diff] [blame] | 448 | # Add chromite into python path. |
| 449 | # This needs to happen after the python update or the correct /usr/lib/python2.* |
| 450 | # may not exist. |
| 451 | for python_path in "${FLAGS_chroot}/usr/lib/"python2.*; do |
| 452 | python_path+="/site-packages" |
| 453 | sudo mkdir -p "${python_path}" |
| 454 | sudo ln -s -fT "${CHROOT_TRUNK_DIR}"/chromite "${python_path}"/chromite |
| 455 | done |
| 456 | |
Paul Drews | 8bae3b5 | 2012-10-10 11:18:13 -0700 | [diff] [blame] | 457 | # Packages that inherit cros-workon commonly get a circular dependency |
| 458 | # curl->openssl->git->curl that is broken by emerging an early version of git |
| 459 | # without curl (and webdav that depends on it). |
Mike Frysinger | 96c5c1c | 2012-10-30 18:59:00 -0400 | [diff] [blame] | 460 | # We also need to do this before the toolchain as those will sometimes also |
| 461 | # fetch via remote git trees (for some bot configs). |
Paul Drews | 8bae3b5 | 2012-10-10 11:18:13 -0700 | [diff] [blame] | 462 | if [[ ! -e "${FLAGS_chroot}/usr/bin/git" ]]; then |
Paul Drews | 8bae3b5 | 2012-10-10 11:18:13 -0700 | [diff] [blame] | 463 | info "Updating early git" |
Mike Frysinger | 96c5c1c | 2012-10-30 18:59:00 -0400 | [diff] [blame] | 464 | USE="-curl -webdav" early_enter_chroot $EMERGE_CMD -uNv $USEPKG dev-vcs/git |
| 465 | |
Mike Frysinger | 96c5c1c | 2012-10-30 18:59:00 -0400 | [diff] [blame] | 466 | early_enter_chroot $EMERGE_CMD -uNv $USEPKG --select $EMERGE_JOBS \ |
| 467 | dev-libs/openssl net-misc/curl |
| 468 | |
| 469 | # (Re-)emerge the full version of git. |
| 470 | info "Updating full version of git" |
| 471 | early_enter_chroot $EMERGE_CMD -uNv $USEPKG dev-vcs/git |
Paul Drews | 8bae3b5 | 2012-10-10 11:18:13 -0700 | [diff] [blame] | 472 | fi |
| 473 | |
Zdenek Behan | 2fbd5af | 2012-03-12 19:38:50 +0100 | [diff] [blame] | 474 | info "Updating host toolchain" |
Mike Frysinger | 96c5c1c | 2012-10-30 18:59:00 -0400 | [diff] [blame] | 475 | early_enter_chroot $EMERGE_CMD -uNv crossdev |
Zdenek Behan | 2fbd5af | 2012-03-12 19:38:50 +0100 | [diff] [blame] | 476 | TOOLCHAIN_ARGS=( --deleteold ) |
| 477 | if [[ ${FLAGS_usepkg} -eq ${FLAGS_FALSE} ]]; then |
| 478 | TOOLCHAIN_ARGS+=( --nousepkg ) |
| 479 | fi |
| 480 | # Note: early_enter_chroot executes as root. |
Brian Harring | 2499bfb | 2012-12-18 16:23:31 -0800 | [diff] [blame] | 481 | early_enter_chroot "${CHROOT_TRUNK_DIR}/chromite/bin/cros_setup_toolchains" \ |
Zdenek Behan | 2fbd5af | 2012-03-12 19:38:50 +0100 | [diff] [blame] | 482 | --hostonly "${TOOLCHAIN_ARGS[@]}" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 483 | |
Mike Frysinger | 279f103 | 2012-05-17 15:54:31 -0400 | [diff] [blame] | 484 | info "Running emerge curl sudo ..." |
Mike Frysinger | 650bf87 | 2012-02-27 11:05:26 -0500 | [diff] [blame] | 485 | early_enter_chroot $EMERGE_CMD -uNv $USEPKG --select $EMERGE_JOBS \ |
Paul Drews | 8bae3b5 | 2012-10-10 11:18:13 -0700 | [diff] [blame] | 486 | pbzip2 dev-libs/openssl net-misc/curl sudo |
| 487 | |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 488 | if [ -n "${INITIALIZE_CHROOT}" ]; then |
| 489 | # If we're creating a new chroot, we also want to set it to the latest |
| 490 | # version. |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 491 | enter_chroot \ |
Brian Harring | 2499bfb | 2012-12-18 16:23:31 -0800 | [diff] [blame] | 492 | "${CHROOT_TRUNK_DIR}/src/scripts/run_chroot_version_hooks" --force_latest |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 493 | fi |
| 494 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 495 | # Update chroot. |
Zdenek Behan | 2fbd5af | 2012-03-12 19:38:50 +0100 | [diff] [blame] | 496 | # Skip toolchain update because it already happened above, and the chroot is |
| 497 | # not ready to emerge all cross toolchains. |
| 498 | UPDATE_ARGS=( --skip_toolchain_update ) |
| 499 | if [[ ${FLAGS_usepkg} -eq ${FLAGS_TRUE} ]]; then |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 500 | UPDATE_ARGS+=( --usepkg ) |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 501 | else |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 502 | UPDATE_ARGS+=( --nousepkg ) |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 503 | fi |
| 504 | if [[ ${FLAGS_fast} -eq ${FLAGS_TRUE} ]]; then |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 505 | UPDATE_ARGS+=( --fast ) |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 506 | else |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 507 | UPDATE_ARGS+=( --nofast ) |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 508 | fi |
David James | 184e390 | 2012-02-23 20:19:28 -0800 | [diff] [blame] | 509 | if [[ "${FLAGS_jobs}" -ne -1 ]]; then |
| 510 | UPDATE_ARGS+=( --jobs=${FLAGS_jobs} ) |
| 511 | fi |
Brian Harring | 2499bfb | 2012-12-18 16:23:31 -0800 | [diff] [blame] | 512 | enter_chroot "${CHROOT_TRUNK_DIR}/src/scripts/update_chroot" "${UPDATE_ARGS[@]}" |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 513 | |
Stefan Zager | 48c776b | 2013-10-09 13:01:25 -0700 | [diff] [blame] | 514 | # The java-config package atm does not support $ROOT. Select a default |
| 515 | # VM ourselves until that gets fixed upstream. |
| 516 | enter_chroot sudo java-config --set-system-vm 1 |
| 517 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 518 | CHROOT_EXAMPLE_OPT="" |
| 519 | if [[ "$FLAGS_chroot" != "$DEFAULT_CHROOT_DIR" ]]; then |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 520 | CHROOT_EXAMPLE_OPT="--chroot=$FLAGS_chroot" |
| 521 | fi |
| 522 | |
Zdenek Behan | 2fbd5af | 2012-03-12 19:38:50 +0100 | [diff] [blame] | 523 | # As a final pass, build all desired cross-toolchains. |
| 524 | info "Updating toolchains" |
Brian Harring | 2499bfb | 2012-12-18 16:23:31 -0800 | [diff] [blame] | 525 | enter_chroot sudo -E "${CHROOT_TRUNK_DIR}/chromite/bin/cros_setup_toolchains" \ |
Zdenek Behan | 2fbd5af | 2012-03-12 19:38:50 +0100 | [diff] [blame] | 526 | "${TOOLCHAIN_ARGS[@]}" |
| 527 | |
Matt Tennant | 0a9d32d | 2012-07-30 16:51:37 -0700 | [diff] [blame] | 528 | command_completed |
Brian Harring | f539bc3 | 2012-02-06 00:18:37 -0800 | [diff] [blame] | 529 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 530 | cat <<EOF |
Mike Frysinger | bdc4fb1 | 2012-02-10 11:20:03 -0500 | [diff] [blame] | 531 | |
| 532 | ${CROS_LOG_PREFIX:-cros_sdk}: All set up. To enter the chroot, run: |
| 533 | $ cros_sdk --enter $CHROOT_EXAMPLE_OPT |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 534 | |
| 535 | CAUTION: Do *NOT* rm -rf the chroot directory; if there are stale bind |
| 536 | mounts you may end up deleting your source tree too. To unmount and |
| 537 | delete the chroot cleanly, use: |
| 538 | $ cros_sdk --delete $CHROOT_EXAMPLE_OPT |
Mike Frysinger | bdc4fb1 | 2012-02-10 11:20:03 -0500 | [diff] [blame] | 539 | |
Brian Harring | 3576782 | 2012-02-01 23:50:45 -0800 | [diff] [blame] | 540 | EOF |
David James | 22dc2ba | 2012-11-29 15:46:58 -0800 | [diff] [blame] | 541 | |
| 542 | warn_if_nfs "${SUDO_HOME}" |