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