| 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 "" \ |
| 24 "The build-bot build number (when called by buildbot only)." "b" |
| 23 | 25 |
| 24 DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts." | 26 DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts." |
| 25 DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts." | 27 DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts." |
| 26 DEFINE_boolean revision $FLAGS_FALSE "Pass subversion revision into chroot." | |
| 27 | 28 |
| 28 # More useful help | 29 # More useful help |
| 29 FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- \"command\"] | 30 FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- \"command\"] |
| 30 | 31 |
| 31 One or more VAR=value pairs can be specified to export variables into | 32 One or more VAR=value pairs can be specified to export variables into |
| 32 the chroot environment. For example: | 33 the chroot environment. For example: |
| 33 | 34 |
| 34 $0 FOO=bar BAZ=bel | 35 $0 FOO=bar BAZ=bel |
| 35 | 36 |
| 36 If [-- \"command\"] is present, runs the command inside the chroot, | 37 If [-- \"command\"] is present, runs the command inside the chroot, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 if [ $FLAGS_unmount -eq $FLAGS_TRUE ] | 95 if [ $FLAGS_unmount -eq $FLAGS_TRUE ] |
| 95 then | 96 then |
| 96 teardown_env | 97 teardown_env |
| 97 exit 0 | 98 exit 0 |
| 98 fi | 99 fi |
| 99 | 100 |
| 100 # Make sure we unmount before exiting | 101 # Make sure we unmount before exiting |
| 101 trap teardown_env EXIT | 102 trap teardown_env EXIT |
| 102 setup_env | 103 setup_env |
| 103 | 104 |
| 104 if [ $FLAGS_revision -eq $FLAGS_TRUE ] | 105 # Get the git revision to pass into the chroot. |
| 106 # |
| 107 # This must be determined outside the chroot because (1) there is no |
| 108 # git inside the chroot, and (2) if there were it would likely be |
| 109 # the wrong version, which would mess up the .git directories. |
| 110 # |
| 111 # Note that this fixes $CHROMEOS_REVISION at the time the chroot is |
| 112 # entered. That's ok for the main use case of automated builds, |
| 113 # which pass each command line into a separate call to enter_chroot |
| 114 # so always have up-to-date info. For developer builds, there isn't |
| 115 # really a single revision anyway, since the developer may have |
| 116 # hand-sync'd some subdirs and edited files in others. |
| 117 # Use git:8 chars of sha1 |
| 118 REVISION=$(git rev-parse HEAD) |
| 119 ORIGIN_REVISION=$(git rev-parse origin/HEAD) |
| 120 if [ "$REVISION" != "$ORIGIN_REVISION" ] |
| 105 then | 121 then |
| 106 # Get the subversion revision to pass into the chroot. | 122 # Mark dirty tree with "**" |
| 107 # | 123 REVISION="${REVISION:0:8}**" |
| 108 # This must be determined outside the chroot because (1) there is no | 124 else |
| 109 # svn/git inside the chroot, and (2) if there were it would likely be | 125 REVISION="${REVISION:0:8}" |
| 110 # the wrong version, which would mess up the .svn/.git directories. | |
| 111 # | |
| 112 # Note that this fixes $CHROMEOS_REVISION at the time the chroot is | |
| 113 # entered. That's ok for the main use case of automated builds, | |
| 114 # which pass each command line into a separate call to enter_chroot | |
| 115 # so always have up-to-date info. For developer builds, there isn't | |
| 116 # really a single revision anyway, since the developer may have | |
| 117 # hand-sync'd some subdirs and edited files in others. | |
| 118 REVISION="$(svn info 2>&- | grep "Revision: " | awk '{print $2}')" | |
| 119 if [ -z "$REVISION" ] | |
| 120 then | |
| 121 # Use git:8 chars of sha1 | |
| 122 REVISION=$(git rev-parse HEAD) | |
| 123 REVISION="${REVISION:8}" | |
| 124 fi | |
| 125 REVISION="CHROMEOS_REVISION=$REVISION" | |
| 126 fi | 126 fi |
| 127 REVISION="CHROMEOS_REVISION=$REVISION BUILDBOT_BUILD=$FLAGS_build_number" |
| 127 | 128 |
| 128 # Run command or interactive shell. Also include the non-chrooted path to | 129 # Run command or interactive shell. Also include the non-chrooted path to |
| 129 # the source trunk for scripts that may need to print it (e.g. | 130 # the source trunk for scripts that may need to print it (e.g. |
| 130 # build_image.sh). | 131 # build_image.sh). |
| 131 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $REVISION \ | 132 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $REVISION \ |
| 132 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" "$@" | 133 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" "$@" |
| 133 | 134 |
| 134 # Remove trap and explicitly unmount | 135 # Remove trap and explicitly unmount |
| 135 trap - EXIT | 136 trap - EXIT |
| 136 teardown_env | 137 teardown_env |
| OLD | NEW |