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 # Load common constants. This should be the first executable line. | 9 # Load common constants. This should be the first executable line. |
10 # The path to common.sh should be relative to your script's location. | 10 # The path to common.sh should be relative to your script's location. |
(...skipping 13 matching lines...) Expand all Loading... |
24 "The build-bot build number (when called by buildbot only)." "b" | 24 "The build-bot build number (when called by buildbot only)." "b" |
25 DEFINE_string chrome_root "" \ | 25 DEFINE_string chrome_root "" \ |
26 "The root of your chrome browser source. Should contain a 'src' subdir." | 26 "The root of your chrome browser source. Should contain a 'src' subdir." |
27 DEFINE_string chrome_root_mount "/home/$USER/chrome_root" \ | 27 DEFINE_string chrome_root_mount "/home/$USER/chrome_root" \ |
28 "The mount point of the chrome broswer source in the chroot." | 28 "The mount point of the chrome broswer source in the chroot." |
29 | 29 |
30 DEFINE_boolean official_build $FLAGS_FALSE \ | 30 DEFINE_boolean official_build $FLAGS_FALSE \ |
31 "Set CHROMEOS_OFFICIAL=1 for release builds." | 31 "Set CHROMEOS_OFFICIAL=1 for release builds." |
32 DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts." | 32 DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts." |
33 DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts." | 33 DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts." |
| 34 DEFINE_boolean ssh_agent $FLAGS_TRUE "Import ssh agent." |
34 | 35 |
35 # More useful help | 36 # More useful help |
36 FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- \"command\"] | 37 FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- \"command\"] |
37 | 38 |
38 One or more VAR=value pairs can be specified to export variables into | 39 One or more VAR=value pairs can be specified to export variables into |
39 the chroot environment. For example: | 40 the chroot environment. For example: |
40 | 41 |
41 $0 FOO=bar BAZ=bel | 42 $0 FOO=bar BAZ=bel |
42 | 43 |
43 If [-- \"command\"] is present, runs the command inside the chroot, | 44 If [-- \"command\"] is present, runs the command inside the chroot, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 die "Could not mount $MOUNTED_PATH" | 98 die "Could not mount $MOUNTED_PATH" |
98 fi | 99 fi |
99 | 100 |
100 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev")" | 101 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev")" |
101 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] | 102 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
102 then | 103 then |
103 sudo mount --bind /dev "$MOUNTED_PATH" || \ | 104 sudo mount --bind /dev "$MOUNTED_PATH" || \ |
104 die "Could not mount $MOUNTED_PATH" | 105 die "Could not mount $MOUNTED_PATH" |
105 fi | 106 fi |
106 | 107 |
| 108 if [ $FLAGS_ssh_agent -eq $FLAGS_TRUE ]; then |
| 109 TARGET_DIR="$(readlink -f "${FLAGS_chroot}/home/${USER}/.ssh")" |
| 110 if [ -n "${SSH_AUTH_SOCK}" \ |
| 111 -a -d "${HOME}/.ssh" ] |
| 112 then |
| 113 mkdir -p "${TARGET_DIR}" |
| 114 cp -r "${HOME}/.ssh/known_hosts" "${TARGET_DIR}" |
| 115 ASOCK="$(dirname "${SSH_AUTH_SOCK}")" |
| 116 mkdir -p "${FLAGS_chroot}/${ASOCK}" |
| 117 sudo mount --bind "${ASOCK}" "${FLAGS_chroot}/${ASOCK}" || \ |
| 118 die "Count not mount ${ASOCK}" |
| 119 fi |
| 120 fi |
| 121 |
107 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev/pts")" | 122 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev/pts")" |
108 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] | 123 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
109 then | 124 then |
110 sudo mount none -t devpts "$MOUNTED_PATH" || \ | 125 sudo mount none -t devpts "$MOUNTED_PATH" || \ |
111 die "Could not mount $MOUNTED_PATH" | 126 die "Could not mount $MOUNTED_PATH" |
112 fi | 127 fi |
113 | 128 |
114 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}$CHROOT_TRUNK_DIR")" | 129 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}$CHROOT_TRUNK_DIR")" |
115 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] | 130 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
116 then | 131 then |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 mkdir -p "$MOUNTED_PATH" | 282 mkdir -p "$MOUNTED_PATH" |
268 sudo mount --bind "$HOME/.subversion" "$MOUNTED_PATH" || \ | 283 sudo mount --bind "$HOME/.subversion" "$MOUNTED_PATH" || \ |
269 die "Could not mount $MOUNTED_PATH" | 284 die "Could not mount $MOUNTED_PATH" |
270 fi | 285 fi |
271 fi | 286 fi |
272 | 287 |
273 # Run command or interactive shell. Also include the non-chrooted path to | 288 # Run command or interactive shell. Also include the non-chrooted path to |
274 # the source trunk for scripts that may need to print it (e.g. | 289 # the source trunk for scripts that may need to print it (e.g. |
275 # build_image.sh). | 290 # build_image.sh). |
276 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ | 291 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ |
277 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C -- "$@" | 292 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ |
| 293 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" -- "$@" |
278 | 294 |
279 # Remove trap and explicitly unmount | 295 # Remove trap and explicitly unmount |
280 trap - EXIT | 296 trap - EXIT |
281 teardown_env | 297 teardown_env |
OLD | NEW |