OLD | NEW |
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 # --- BEGIN COMMON.SH BOILERPLATE --- | 9 # --- BEGIN COMMON.SH BOILERPLATE --- |
10 # Load common CrOS utilities. Inside the chroot this file is installed in | 10 # Load common CrOS utilities. Inside the chroot this file is installed in |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 function ensure_mounted { | 136 function ensure_mounted { |
137 # If necessary, mount $source in the host FS at $target inside the | 137 # If necessary, mount $source in the host FS at $target inside the |
138 # chroot directory with $mount_args. | 138 # chroot directory with $mount_args. |
139 local source="$1" | 139 local source="$1" |
140 local mount_args="$2" | 140 local mount_args="$2" |
141 local target="$3" | 141 local target="$3" |
142 | 142 |
143 local mounted_path="$(readlink -f "${FLAGS_chroot}/$target")" | 143 local mounted_path="$(readlink -f "${FLAGS_chroot}/$target")" |
144 | 144 |
145 if [ -z "$(mount | grep -F "on ${mounted_path} ")" ]; then | 145 if [ -z "$(mount | grep -F "on ${mounted_path} ")" ]; then |
| 146 # Attempt to make the mountpoint as the user. This depends on the |
| 147 # fact that all mountpoints that should be owned by root are |
| 148 # already present. |
| 149 mkdir -p "${mounted_path}" |
| 150 |
146 # NB: mount_args deliberately left unquoted | 151 # NB: mount_args deliberately left unquoted |
147 debug mount ${mount_args} "${source}" "${mounted_path}" | 152 debug mount ${mount_args} "${source}" "${mounted_path}" |
148 sudo -- mount ${mount_args} "${source}" "${mounted_path}" || \ | 153 sudo -- mount ${mount_args} "${source}" "${mounted_path}" || \ |
149 die "Could not mount ${source} on ${mounted_path}" | 154 die "Could not mount ${source} on ${mounted_path}" |
150 fi | 155 fi |
151 } | 156 } |
152 | 157 |
153 function setup_env { | 158 function setup_env { |
154 # Validate sudo timestamp before entering the critical section so that we | 159 # Validate sudo timestamp before entering the critical section so that we |
155 # don't stall for a password while we have the lockfile. | 160 # don't stall for a password while we have the lockfile. |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 # Run command or interactive shell. Also include the non-chrooted path to | 390 # Run command or interactive shell. Also include the non-chrooted path to |
386 # the source trunk for scripts that may need to print it (e.g. | 391 # the source trunk for scripts that may need to print it (e.g. |
387 # build_image.sh). | 392 # build_image.sh). |
388 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ | 393 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ |
389 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ | 394 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ |
390 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@" | 395 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@" |
391 | 396 |
392 # Remove trap and explicitly unmount | 397 # Remove trap and explicitly unmount |
393 trap - EXIT | 398 trap - EXIT |
394 teardown_env | 399 teardown_env |
OLD | NEW |