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. |
11 . "$(dirname "$0")/common.sh" | 11 . "$(dirname "$0")/common.sh" |
12 | 12 |
13 # Script must be run outside the chroot and as a regular user. | 13 # Script must be run outside the chroot and as a regular user. |
14 assert_outside_chroot | 14 assert_outside_chroot |
15 assert_not_root_user | 15 assert_not_root_user |
16 | 16 |
17 # Define command line flags | 17 # Define command line flags |
18 # See http://code.google.com/p/shflags/wiki/Documentation10x | 18 # See http://code.google.com/p/shflags/wiki/Documentation10x |
19 DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \ | 19 DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \ |
20 "The destination dir for the chroot environment." "d" | 20 "The destination dir for the chroot environment." "d" |
21 DEFINE_string trunk "$GCLIENT_ROOT" \ | 21 DEFINE_string trunk "$GCLIENT_ROOT" \ |
22 "The source trunk to bind mount within the chroot." "s" | 22 "The source trunk to bind mount within the chroot." "s" |
23 DEFINE_string build_number "" \ | 23 DEFINE_string build_number "" \ |
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 git_config $FLAGS_TRUE \ |
| 31 "Config git to work with your user/pass in the chroot." |
30 DEFINE_boolean official_build $FLAGS_FALSE \ | 32 DEFINE_boolean official_build $FLAGS_FALSE \ |
31 "Set CHROMEOS_OFFICIAL=1 for release builds." | 33 "Set CHROMEOS_OFFICIAL=1 for release builds." |
32 DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts." | 34 DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts." |
33 DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts." | 35 DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts." |
34 DEFINE_boolean ssh_agent $FLAGS_TRUE "Import ssh agent." | 36 DEFINE_boolean ssh_agent $FLAGS_TRUE "Import ssh agent." |
35 | 37 |
36 # More useful help | 38 # More useful help |
37 FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- command [arg1] [arg2] ...] | 39 FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- command [arg1] [arg2] ...] |
38 | 40 |
39 One or more VAR=value pairs can be specified to export variables into | 41 One or more VAR=value pairs can be specified to export variables into |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 info "mounting ~/.subversion into chroot" | 321 info "mounting ~/.subversion into chroot" |
320 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/home/${USER}/.subversion")" | 322 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/home/${USER}/.subversion")" |
321 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then | 323 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
322 mkdir -p "$MOUNTED_PATH" | 324 mkdir -p "$MOUNTED_PATH" |
323 sudo mount --bind "$HOME/.subversion" "$MOUNTED_PATH" || \ | 325 sudo mount --bind "$HOME/.subversion" "$MOUNTED_PATH" || \ |
324 die "Could not mount $MOUNTED_PATH" | 326 die "Could not mount $MOUNTED_PATH" |
325 fi | 327 fi |
326 fi | 328 fi |
327 | 329 |
328 # Configure committer username and email in chroot .gitconfig | 330 # Configure committer username and email in chroot .gitconfig |
329 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all user.name \ | 331 if [ $FLAGS_git_config -eq $FLAGS_TRUE ]; then |
330 "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/ *<.*//')" | 332 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ |
331 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all user.email \ | 333 user.name "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/ *<.*//')" |
332 "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/.*<\([^>]*\)>.*/\1/')" | 334 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ |
| 335 user.email "$(cd /tmp; git var GIT_COMMITTER_IDENT | \ |
| 336 sed -e 's/.*<\([^>]*\)>.*/\1/')" |
| 337 fi |
333 | 338 |
334 # Run command or interactive shell. Also include the non-chrooted path to | 339 # Run command or interactive shell. Also include the non-chrooted path to |
335 # the source trunk for scripts that may need to print it (e.g. | 340 # the source trunk for scripts that may need to print it (e.g. |
336 # build_image.sh). | 341 # build_image.sh). |
337 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ | 342 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ |
338 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ | 343 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ |
339 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@" | 344 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@" |
340 | 345 |
341 # Remove trap and explicitly unmount | 346 # Remove trap and explicitly unmount |
342 trap - EXIT | 347 trap - EXIT |
343 teardown_env | 348 teardown_env |
OLD | NEW |