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