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 16 matching lines...) Expand all Loading... | |
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 DEFINE_boolean ssh_agent $FLAGS_TRUE "Import ssh agent." |
35 | 35 |
36 # More useful help | 36 # More useful help |
37 FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- \"command\"] | 37 FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- command [arg1] [arg2] ...] |
38 | 38 |
39 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 |
40 the chroot environment. For example: | 40 the chroot environment. For example: |
41 | 41 |
42 $0 FOO=bar BAZ=bel | 42 $0 FOO=bar BAZ=bel |
43 | 43 |
44 If [-- \"command\"] is present, runs the command inside the chroot, | 44 If [-- command] is present, runs the command inside the chroot, |
45 after changing directory to /$USER/trunk/src/scripts. Note that the | 45 after changing directory to /$USER/trunk/src/scripts. Note that neither |
46 command should be enclosed in quotes to prevent interpretation by the | 46 the command nor args should include single quotes. For example: |
47 shell before getting into the chroot. For example: | |
48 | 47 |
49 $0 -- \"./build_platform_packages.sh\" | 48 $0 -- ./build_platform_packages.sh |
50 | 49 |
51 Otherwise, provides an interactive shell. | 50 Otherwise, provides an interactive shell. |
52 " | 51 " |
53 | 52 |
53 # Double up on the first '--' argument. Why? For enter_chroot, we want to | |
54 # emulate the behavior of sudo for setting environment vars. That is, we want: | |
55 # ./enter_chroot [flags] [VAR=val] [-- command] | |
56 # ...but shflags ends up eating the '--' out of the command line and gives | |
57 # us back "VAR=val" and "command" together in one chunk. By doubling up, we | |
58 # end up getting what we want back from shflags. | |
59 # | |
60 # Examples of how people might be using enter_chroot: | |
61 # 1. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2 -- cmd arg1 arg2 | |
62 # Set env vars and run cmd w/ args | |
63 # 2. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2 | |
64 # Set env vars and run cmd w/ args | |
65 # 3. ./enter_chroot [chroot_flags] -- cmd arg1 arg2 | |
66 # Run cmd w/ args | |
67 # 4. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2 cmd arg1 arg2 | |
68 # Like #1 _if_ args aren't flags (if they are, enter_chroot will claim them) | |
69 # 5. ./enter_chroot [chroot_flags] cmd arg1 arg2 | |
70 # Like #3 _if_ args aren't flags (if they are, enter_chroot will claim them) | |
71 _FLAGS_FIXED='' | |
72 _SAW_DASHDASH=0 | |
73 while [ $# -gt 0 ]; do | |
74 _FLAGS_FIXED="${_FLAGS_FIXED:+${_FLAGS_FIXED} }'$1'" | |
sosa
2010/12/16 22:32:45
can you do this less bashy? i.e. _FLAGS_FIXED="${
diandersAtChromium
2010/12/16 22:43:01
Going to leave this, since it's copied almost verb
| |
75 if [[ "${_SAW_DASHDASH} $1" == "0 --" ]]; then | |
sosa
2010/12/16 22:32:45
Prefer if you split this into two checks that are
diandersAtChromium
2010/12/16 22:43:01
Done.
| |
76 _FLAGS_FIXED="${_FLAGS_FIXED:+${_FLAGS_FIXED} }'--'" | |
77 _SAW_DASHDASH=1 | |
78 fi | |
79 shift | |
80 done | |
81 eval set -- "${_FLAGS_FIXED}" | |
82 | |
83 | |
54 # Parse command line flags | 84 # Parse command line flags |
55 FLAGS "$@" || exit 1 | 85 FLAGS "$@" || exit 1 |
56 eval set -- "${FLAGS_ARGV}" | 86 eval set -- "${FLAGS_ARGV}" |
57 | 87 |
58 if [ $FLAGS_official_build -eq $FLAGS_TRUE ] | 88 if [ $FLAGS_official_build -eq $FLAGS_TRUE ] |
59 then | 89 then |
60 CHROMEOS_OFFICIAL=1 | 90 CHROMEOS_OFFICIAL=1 |
61 fi | 91 fi |
62 | 92 |
63 # Only now can we die on error. shflags functions leak non-zero error codes, | 93 # Only now can we die on error. shflags functions leak non-zero error codes, |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 | 326 |
297 # Configure committer username and email in chroot .gitconfig | 327 # Configure committer username and email in chroot .gitconfig |
298 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all user.name \ | 328 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all user.name \ |
299 "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/ *<.*//')" | 329 "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/ *<.*//')" |
300 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all user.email \ | 330 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all user.email \ |
301 "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/.*<\([^>]*\)>.*/\1/')" | 331 "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/.*<\([^>]*\)>.*/\1/')" |
302 | 332 |
303 # Run command or interactive shell. Also include the non-chrooted path to | 333 # Run command or interactive shell. Also include the non-chrooted path to |
304 # the source trunk for scripts that may need to print it (e.g. | 334 # the source trunk for scripts that may need to print it (e.g. |
305 # build_image.sh). | 335 # build_image.sh). |
306 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ | 336 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ |
307 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ | 337 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ |
308 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" -- "$@" | 338 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@" |
309 | 339 |
310 # Remove trap and explicitly unmount | 340 # Remove trap and explicitly unmount |
311 trap - EXIT | 341 trap - EXIT |
312 teardown_env | 342 teardown_env |
OLD | NEW |