Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(740)

Side by Side Diff: enter_chroot.sh

Issue 6240018: This starts to fix the scripts so that they load from /usr/lib/crosutils (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: fixing bad merge Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « enable_localaccount.sh ('k') | get_latest_image.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash 1 #!/bin/bash
2 2
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 # Script to enter the chroot environment 7 # Script to enter the chroot environment
8 8
9 # Load common constants. This should be the first executable line. 9 # --- BEGIN COMMON.SH BOILERPLATE ---
10 # The path to common.sh should be relative to your script's location. 10 # Load common CrOS utilities. Inside the chroot this file is installed in
11 . "$(dirname "$0")/common.sh" 11 # /usr/lib/crosutils. Outside the chroot we find it relative to the script's
12 # location.
13 find_common_sh() {
14 local common_paths=(/usr/lib/crosutils $(dirname "$(readlink -f "$0")"))
15 local path
16
17 SCRIPT_ROOT=
18 for path in "${common_paths[@]}"; do
19 if [ -r "${path}/common.sh" ]; then
20 SCRIPT_ROOT=${path}
21 break
22 fi
23 done
24 }
25
26 find_common_sh
27 . "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1)
28 # --- END COMMON.SH BOILERPLATE ---
12 29
13 # Script must be run outside the chroot and as a regular user. 30 # Script must be run outside the chroot and as a regular user.
14 assert_outside_chroot 31 assert_outside_chroot
15 assert_not_root_user 32 assert_not_root_user
16 33
17 # Define command line flags 34 # Define command line flags
18 # See http://code.google.com/p/shflags/wiki/Documentation10x 35 # See http://code.google.com/p/shflags/wiki/Documentation10x
19 DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \ 36 DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \
20 "The destination dir for the chroot environment." "d" 37 "The destination dir for the chroot environment." "d"
21 DEFINE_string trunk "$GCLIENT_ROOT" \ 38 DEFINE_string trunk "$GCLIENT_ROOT" \
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 fi 97 fi
81 shift 98 shift
82 done 99 done
83 eval set -- "${_FLAGS_FIXED}" 100 eval set -- "${_FLAGS_FIXED}"
84 101
85 102
86 # Parse command line flags 103 # Parse command line flags
87 FLAGS "$@" || exit 1 104 FLAGS "$@" || exit 1
88 eval set -- "${FLAGS_ARGV}" 105 eval set -- "${FLAGS_ARGV}"
89 106
90 if [ $FLAGS_official_build -eq $FLAGS_TRUE ] 107 if [ $FLAGS_official_build -eq $FLAGS_TRUE ]; then
91 then
92 CHROMEOS_OFFICIAL=1 108 CHROMEOS_OFFICIAL=1
93 fi 109 fi
94 110
95 # Only now can we die on error. shflags functions leak non-zero error codes, 111 # Only now can we die on error. shflags functions leak non-zero error codes,
96 # so will die prematurely if 'set -e' is specified before now. 112 # so will die prematurely if 'set -e' is specified before now.
97 # TODO: replace shflags with something less error-prone, or contribute a fix. 113 # TODO: replace shflags with something less error-prone, or contribute a fix.
98 set -e 114 set -e
99 115
100 INNER_CHROME_ROOT=$FLAGS_chrome_root_mount # inside chroot 116 INNER_CHROME_ROOT=$FLAGS_chrome_root_mount # inside chroot
101 CHROME_ROOT_CONFIG="/var/cache/chrome_root" # inside chroot 117 CHROME_ROOT_CONFIG="/var/cache/chrome_root" # inside chroot
102 INNER_DEPOT_TOOLS_ROOT="/home/$USER/depot_tools" # inside chroot 118 INNER_DEPOT_TOOLS_ROOT="/home/$USER/depot_tools" # inside chroot
103 FUSE_DEVICE="/dev/fuse" 119 FUSE_DEVICE="/dev/fuse"
104 AUTOMOUNT_PREF="/apps/nautilus/preferences/media_automount" 120 AUTOMOUNT_PREF="/apps/nautilus/preferences/media_automount"
105 SAVED_AUTOMOUNT_PREF_FILE="/tmp/.automount_pref" 121 SAVED_AUTOMOUNT_PREF_FILE="/tmp/.automount_pref"
106 122
107 sudo chmod 0777 "$FLAGS_chroot/var/lock" 123 sudo chmod 0777 "$FLAGS_chroot/var/lock"
108 124
109 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" 125 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot"
110 126
111 function setup_env { 127 function setup_env {
112 ( 128 (
113 flock 200 129 flock 200
114 echo $$ >> "$LOCKFILE" 130 echo $$ >> "$LOCKFILE"
115 131
116 info "Mounting chroot environment." 132 info "Mounting chroot environment."
117 133
118 # Mount only if not already mounted 134 # Mount only if not already mounted
119 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" 135 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")"
120 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] 136 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
121 then
122 sudo mount none -t proc "$MOUNTED_PATH" || \ 137 sudo mount none -t proc "$MOUNTED_PATH" || \
123 die "Could not mount $MOUNTED_PATH" 138 die "Could not mount $MOUNTED_PATH"
124 fi 139 fi
125 140
126 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/sys")" 141 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/sys")"
127 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] 142 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
128 then
129 sudo mount none -t sysfs "$MOUNTED_PATH" || \ 143 sudo mount none -t sysfs "$MOUNTED_PATH" || \
130 die "Could not mount $MOUNTED_PATH" 144 die "Could not mount $MOUNTED_PATH"
131 fi 145 fi
132 146
133 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev")" 147 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev")"
134 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] 148 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
135 then
136 sudo mount --bind /dev "$MOUNTED_PATH" || \ 149 sudo mount --bind /dev "$MOUNTED_PATH" || \
137 die "Could not mount $MOUNTED_PATH" 150 die "Could not mount $MOUNTED_PATH"
138 fi 151 fi
139 152
140 if [ $FLAGS_ssh_agent -eq $FLAGS_TRUE ]; then 153 if [ $FLAGS_ssh_agent -eq $FLAGS_TRUE ]; then
141 TARGET_DIR="$(readlink -f "${FLAGS_chroot}/home/${USER}/.ssh")" 154 TARGET_DIR="$(readlink -f "${FLAGS_chroot}/home/${USER}/.ssh")"
142 if [ -n "${SSH_AUTH_SOCK}" \ 155 if [ -n "${SSH_AUTH_SOCK}" -a -d "${HOME}/.ssh" ]; then
143 -a -d "${HOME}/.ssh" ]
144 then
145 mkdir -p "${TARGET_DIR}" 156 mkdir -p "${TARGET_DIR}"
146 cp -r "${HOME}/.ssh/known_hosts" "${TARGET_DIR}" 157 cp -r "${HOME}/.ssh/known_hosts" "${TARGET_DIR}"
147 cp -r "${HOME}/.ssh/config" "${TARGET_DIR}" 158 cp -r "${HOME}/.ssh/config" "${TARGET_DIR}"
148 ASOCK="$(dirname "${SSH_AUTH_SOCK}")" 159 ASOCK="$(dirname "${SSH_AUTH_SOCK}")"
149 mkdir -p "${FLAGS_chroot}/${ASOCK}" 160 mkdir -p "${FLAGS_chroot}/${ASOCK}"
150 sudo mount --bind "${ASOCK}" "${FLAGS_chroot}/${ASOCK}" || \ 161 sudo mount --bind "${ASOCK}" "${FLAGS_chroot}/${ASOCK}" || \
151 die "Count not mount ${ASOCK}" 162 die "Count not mount ${ASOCK}"
152 fi 163 fi
153 fi 164 fi
154 165
155 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev/pts")" 166 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev/pts")"
156 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] 167 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
157 then
158 sudo mount none -t devpts "$MOUNTED_PATH" || \ 168 sudo mount none -t devpts "$MOUNTED_PATH" || \
159 die "Could not mount $MOUNTED_PATH" 169 die "Could not mount $MOUNTED_PATH"
160 fi 170 fi
161 171
162 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}$CHROOT_TRUNK_DIR")" 172 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}$CHROOT_TRUNK_DIR")"
163 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] 173 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
164 then
165 sudo mount --bind "$FLAGS_trunk" "$MOUNTED_PATH" || \ 174 sudo mount --bind "$FLAGS_trunk" "$MOUNTED_PATH" || \
166 die "Could not mount $MOUNTED_PATH" 175 die "Could not mount $MOUNTED_PATH"
167 fi 176 fi
168 177
169 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")" 178 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")"
170 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] 179 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
171 then
172 ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")" 180 ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")"
173 if [ -z "$CHROME_ROOT" ]; then 181 if [ -z "$CHROME_ROOT" ]; then
174 ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \ 182 ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \
175 2>/dev/null)" 183 2>/dev/null)"
176 fi 184 fi
177 if [[ ( -z "$CHROME_ROOT" ) || ( ! -d "${CHROME_ROOT}/src" ) ]]; then 185 if [[ ( -z "$CHROME_ROOT" ) || ( ! -d "${CHROME_ROOT}/src" ) ]]; then
178 info "Not mounting chrome source" 186 info "Not mounting chrome source"
179 sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" 187 sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}"
180 else 188 else
181 info "Mounting chrome source at: $INNER_CHROME_ROOT" 189 info "Mounting chrome source at: $INNER_CHROME_ROOT"
182 echo "$CHROME_ROOT" | \ 190 echo "$CHROME_ROOT" | \
183 sudo dd of="${FLAGS_chroot}${CHROME_ROOT_CONFIG}" 191 sudo dd of="${FLAGS_chroot}${CHROME_ROOT_CONFIG}"
184 mkdir -p "$MOUNTED_PATH" 192 mkdir -p "$MOUNTED_PATH"
185 sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" || \ 193 sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" || \
186 die "Could not mount $MOUNTED_PATH" 194 die "Could not mount $MOUNTED_PATH"
187 fi 195 fi
188 fi 196 fi
189 197
190 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")" 198 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")"
191 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] 199 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
192 then
193 if [ $(which gclient 2>/dev/null) ]; then 200 if [ $(which gclient 2>/dev/null) ]; then
194 info "Mounting depot_tools" 201 info "Mounting depot_tools"
195 DEPOT_TOOLS=$(dirname $(which gclient) ) 202 DEPOT_TOOLS=$(dirname "$(which gclient)")
196 mkdir -p "$MOUNTED_PATH" 203 mkdir -p "$MOUNTED_PATH"
197 if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then 204 if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then
198 warn "depot_tools failed to mount; perhaps it's on NFS?" 205 warn "depot_tools failed to mount; perhaps it's on NFS?"
199 warn "This may impact chromium build." 206 warn "This may impact chromium build."
200 fi 207 fi
201 fi 208 fi
202 fi 209 fi
203 210
204 # Install fuse module. 211 # Install fuse module.
205 if [ -c "${FUSE_DEVICE}" ] ; then 212 if [ -c "${FUSE_DEVICE}" ]; then
206 sudo modprobe fuse 2> /dev/null ||\ 213 sudo modprobe fuse 2> /dev/null ||\
207 warn "-- Note: modprobe fuse failed. gmergefs will not work" 214 warn "-- Note: modprobe fuse failed. gmergefs will not work"
208 fi 215 fi
209 216
210 # Turn off automounting of external media when we enter the 217 # Turn off automounting of external media when we enter the
211 # chroot; thus we don't have to worry about being able to unmount 218 # chroot; thus we don't have to worry about being able to unmount
212 # from inside. 219 # from inside.
213 if [ $(which gconftool-2 2>/dev/null) ]; then 220 if [ $(which gconftool-2 2>/dev/null) ]; then
214 gconftool-2 -g ${AUTOMOUNT_PREF} > \ 221 gconftool-2 -g ${AUTOMOUNT_PREF} > \
215 "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}" 222 "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 # sort the list of mounts in reverse order, to ensure umount of 271 # sort the list of mounts in reverse order, to ensure umount of
265 # cascading mounts in proper order 272 # cascading mounts in proper order
266 for i in \ 273 for i in \
267 $(mount | grep -F "on $MOUNTED_PATH/" | sort -r | awk '{print $3}'); do 274 $(mount | grep -F "on $MOUNTED_PATH/" | sort -r | awk '{print $3}'); do
268 safe_umount "$i" 275 safe_umount "$i"
269 done 276 done
270 fi 277 fi
271 ) 200>>"$LOCKFILE" || die "teardown_env failed" 278 ) 200>>"$LOCKFILE" || die "teardown_env failed"
272 } 279 }
273 280
274 if [ $FLAGS_mount -eq $FLAGS_TRUE ] 281 if [ $FLAGS_mount -eq $FLAGS_TRUE ]; then
275 then
276 setup_env 282 setup_env
277 info "Make sure you run" 283 info "Make sure you run"
278 info " $0 --unmount" 284 info " $0 --unmount"
279 info "before deleting $FLAGS_chroot" 285 info "before deleting $FLAGS_chroot"
280 info "or you'll end up deleting $FLAGS_trunk too!" 286 info "or you'll end up deleting $FLAGS_trunk too!"
281 exit 0 287 exit 0
282 fi 288 fi
283 289
284 if [ $FLAGS_unmount -eq $FLAGS_TRUE ] 290 if [ $FLAGS_unmount -eq $FLAGS_TRUE ]; then
285 then
286 teardown_env 291 teardown_env
287 exit 0 292 exit 0
288 fi 293 fi
289 294
290 # Apply any hacks needed to update the chroot. 295 # Apply any hacks needed to update the chroot.
291 chroot_hacks_from_outside "${FLAGS_chroot}" 296 chroot_hacks_from_outside "${FLAGS_chroot}"
292 297
293 298
294 # Make sure we unmount before exiting 299 # Make sure we unmount before exiting
295 trap teardown_env EXIT 300 trap teardown_env EXIT
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 # Run command or interactive shell. Also include the non-chrooted path to 344 # Run command or interactive shell. Also include the non-chrooted path to
340 # the source trunk for scripts that may need to print it (e.g. 345 # the source trunk for scripts that may need to print it (e.g.
341 # build_image.sh). 346 # build_image.sh).
342 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ 347 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \
343 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ 348 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \
344 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@" 349 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@"
345 350
346 # Remove trap and explicitly unmount 351 # Remove trap and explicitly unmount
347 trap - EXIT 352 trap - EXIT
348 teardown_env 353 teardown_env
OLDNEW
« no previous file with comments | « enable_localaccount.sh ('k') | get_latest_image.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698