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 # This script sets up an Ubuntu chroot environment. The ideas come | 7 # This script sets up an Ubuntu chroot environment. The ideas come |
8 # from https://wiki.ubuntu.com/DebootstrapChroot and conversations with | 8 # from https://wiki.ubuntu.com/DebootstrapChroot and conversations with |
9 # tedbo. The script is passed the path to an empty folder, which will be | 9 # tedbo. The script is passed the path to an empty folder, which will be |
10 # populated with the files to form an Ubuntu Jaunty system with the packages | 10 # populated with the files to form an Ubuntu Jaunty system with the packages |
11 # listed in PACKAGE_LIST_FILE (below) and their dependencies. Once created, | 11 # listed in PACKAGE_LIST_FILE (below) and their dependencies. Once created, |
12 # the password is set to PASSWORD (below). One can enter the chrooted | 12 # the password is set to PASSWORD (below). One can enter the chrooted |
13 # environment for work by running | 13 # environment for work by running |
14 # enter_chroot_dev_environment.sh /path/to/chroot-root | 14 # enter_chroot_dev_environment.sh /path/to/chroot-root |
15 | 15 |
16 # Load common constants. This should be the first executable line. | 16 # Load common constants. This should be the first executable line. |
17 # The path to common.sh should be relative to your script's location. | 17 # The path to common.sh should be relative to your script's location. |
18 . "$(dirname "$0")/common.sh" | 18 . "$(dirname "$0")/common.sh" |
19 | 19 |
20 # Script must be run outside the chroot and as a regular user. | 20 # Script must be run outside the chroot and as a regular user. |
21 assert_outside_chroot | 21 assert_outside_chroot |
22 assert_not_root_user | 22 assert_not_root_user |
23 | 23 |
24 DEFAULT_PKGLIST="$SRC_ROOT/package_repo/package-list-dev.txt" | 24 DEFAULT_PKGLIST="$SRC_ROOT/package_repo/package-list-dev.txt" |
25 | 25 |
26 # Define command line flags | 26 # Define command line flags |
27 # See http://code.google.com/p/shflags/wiki/Documentation10x | 27 # See http://code.google.com/p/shflags/wiki/Documentation10x |
28 DEFINE_string suite "$DEFAULT_DEV_SUITE" "Repository suite to base image on." | 28 DEFINE_string suite "$DEFAULT_DEV_SUITE" \ |
29 DEFINE_string mirror "$DEFAULT_DEV_MIRROR" "Local repository mirror to use." | 29 "Ubuntu suite to use to create the development chroot." |
30 DEFINE_string mirror2 "" "Additional repository mirror to use (URL only)." | 30 DEFINE_string mirror "$DEFAULT_DEV_MIRROR" \ |
31 DEFINE_string suite2 "" "Repository suite for additional mirror." | 31 "Ubuntu mirror to use to create the development chroot." |
32 DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \ | 32 DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \ |
33 "Destination dir for the chroot environment." | 33 "Destination dir for the chroot environment." |
34 DEFINE_string pkglist "$DEFAULT_PKGLIST" \ | 34 DEFINE_string pkglist "$DEFAULT_PKGLIST" \ |
35 "File listing additional packages to install." | 35 "File listing additional packages to install." |
36 DEFINE_boolean delete $FLAGS_FALSE "Delete an existing chroot." | 36 DEFINE_boolean delete $FLAGS_FALSE "Delete an existing chroot." |
37 DEFINE_boolean replace $FLAGS_FALSE "Overwrite existing chroot, if any." | 37 DEFINE_boolean replace $FLAGS_FALSE "Overwrite existing chroot, if any." |
38 | 38 |
39 # Parse command line flags | 39 # Parse command line flags |
40 FLAGS "$@" || exit 1 | 40 FLAGS "$@" || exit 1 |
41 eval set -- "${FLAGS_ARGV}" | 41 eval set -- "${FLAGS_ARGV}" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 echo "Directory $FLAGS_chroot already exists." | 105 echo "Directory $FLAGS_chroot already exists." |
106 echo "Use --replace if you really want to overwrite it." | 106 echo "Use --replace if you really want to overwrite it." |
107 exit 1 | 107 exit 1 |
108 fi | 108 fi |
109 fi | 109 fi |
110 | 110 |
111 # Create the destination directory | 111 # Create the destination directory |
112 mkdir -p "$FLAGS_chroot" | 112 mkdir -p "$FLAGS_chroot" |
113 | 113 |
114 # Run debootstrap to create the base chroot environment | 114 # Run debootstrap to create the base chroot environment |
115 echo "Running debootstrap..." | 115 echo "Running debootstrap $FLAGS_mirror $FLAGS_suite ..." |
116 echo "You may need to enter password for sudo now..." | 116 echo "You may need to enter password for sudo now..." |
117 sudo debootstrap --arch=i386 --exclude=rsyslog,ubuntu-minimal \ | 117 sudo debootstrap --arch=i386 --exclude=rsyslog,ubuntu-minimal \ |
118 "$FLAGS_suite" "$FLAGS_chroot" "$FLAGS_mirror" | 118 "$FLAGS_suite" "$FLAGS_chroot" "$FLAGS_mirror" |
119 echo "Done running debootstrap." | 119 echo "Done running debootstrap." |
120 | 120 |
121 # Set up necessary mounts | 121 # Set up necessary mounts |
122 sudo mount none -t proc "$FLAGS_chroot/proc" | 122 sudo mount none -t proc "$FLAGS_chroot/proc" |
123 sudo mount none -t devpts "$FLAGS_chroot/dev/pts" | 123 sudo mount none -t devpts "$FLAGS_chroot/dev/pts" |
124 # ...and make sure we clean them up on exit | 124 # ...and make sure we clean them up on exit |
125 trap cleanup EXIT | 125 trap cleanup EXIT |
126 | 126 |
127 # Set up sudoers. Inside the chroot, the user can sudo without a password. | 127 # Set up sudoers. Inside the chroot, the user can sudo without a password. |
128 # (Safe enough, since the only way into the chroot is to 'sudo chroot', so | 128 # (Safe enough, since the only way into the chroot is to 'sudo chroot', so |
129 # the user's already typed in one sudo password...) | 129 # the user's already typed in one sudo password...) |
130 bash_chroot "echo %admin ALL=\(ALL\) ALL >> /etc/sudoers" | 130 bash_chroot "echo %admin ALL=\(ALL\) ALL >> /etc/sudoers" |
131 bash_chroot "echo $USER ALL=NOPASSWD: ALL >> /etc/sudoers" | 131 bash_chroot "echo $USER ALL=NOPASSWD: ALL >> /etc/sudoers" |
132 | 132 |
133 # Set up apt sources | 133 # Set up apt sources. |
134 # If a local repository is used, it will have a different path when | 134 # prefer our tools or custom packages |
135 # bind-mounted inside the chroot | 135 bash_chroot "echo deb $DEFAULT_CHROMEOS_SERVER/tools chromiumos_dev \ |
136 MIRROR_INSIDE="${FLAGS_mirror/$GCLIENT_ROOT/$CHROOT_TRUNK_DIR}" | 136 main > /etc/apt/sources.list" |
137 bash_chroot "echo deb $MIRROR_INSIDE $FLAGS_suite \ | 137 # use specified mirror and suite for the rest of the development chroot |
138 main restricted multiverse universe > /etc/apt/sources.list" | 138 bash_chroot "echo deb $FLAGS_mirror $FLAGS_suite \ |
139 # Additional repo? Note: Not mounted inside - must use URL | 139 main restricted multiverse universe >> /etc/apt/sources.list" |
140 if [ -n "$FLAGS_mirror2" ]; then | 140 # NOTE: Add additional repos here, possibly via command-line args. |
141 bash_chroot "echo deb $FLAGS_mirror2 $FLAGS_suite2 \ | |
142 main restricted multiverse universe >> /etc/apt/sources.list" | |
143 fi | |
144 | 141 |
145 # TODO: enable sources when needed. Currently, kernel source is checked in | 142 # Enable sources for upstream packages. Currently, kernel source is checked in |
146 # and all other sources are pulled via DEPS files. | 143 # and all other sources are pulled via DEPS files. |
147 #bash_chroot "echo deb-src $MIRROR_INSIDE $FLAGS_suite \ | 144 bash_chroot "echo deb-src $FLAGS_mirror $FLAGS_suite \ |
148 # main restricted multiverse universe >> /etc/apt/sources.list" | 145 main restricted multiverse universe >> /etc/apt/sources.list" |
149 | 146 |
150 # Set /etc/debian_chroot so '(chroot)' shows up in shell prompts | 147 # Set /etc/debian_chroot so '(chroot)' shows up in shell prompts |
151 CHROOT_BASE=`basename $FLAGS_chroot` | 148 CHROOT_BASE=`basename $FLAGS_chroot` |
152 bash_chroot "echo $CHROOT_BASE > /etc/debian_chroot" | 149 bash_chroot "echo $CHROOT_BASE > /etc/debian_chroot" |
153 | 150 |
154 # Copy config from outside chroot into chroot | 151 # Copy config from outside chroot into chroot |
155 sudo cp /etc/hosts "$FLAGS_chroot/etc/hosts" | 152 sudo cp /etc/hosts "$FLAGS_chroot/etc/hosts" |
156 | 153 |
157 # Add ourselves as a user inside the chroot | 154 # Add ourselves as a user inside the chroot |
158 in_chroot groupadd admin | 155 in_chroot groupadd admin |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 CHROOT_EXAMPLE_OPT="--chroot=$FLAGS_chroot" | 203 CHROOT_EXAMPLE_OPT="--chroot=$FLAGS_chroot" |
207 fi | 204 fi |
208 | 205 |
209 echo "All set up. To enter the chroot, run:" | 206 echo "All set up. To enter the chroot, run:" |
210 echo " $SCRIPTS_DIR/enter_chroot.sh $CHROOT_EXAMPLE_OPT" | 207 echo " $SCRIPTS_DIR/enter_chroot.sh $CHROOT_EXAMPLE_OPT" |
211 echo "" | 208 echo "" |
212 echo "CAUTION: Do *NOT* rm -rf the chroot directory; if there are stale bind" | 209 echo "CAUTION: Do *NOT* rm -rf the chroot directory; if there are stale bind" |
213 echo "mounts you may end up deleting your source tree too. To unmount and" | 210 echo "mounts you may end up deleting your source tree too. To unmount and" |
214 echo "delete the chroot cleanly, use:" | 211 echo "delete the chroot cleanly, use:" |
215 echo " $0 --delete $CHROOT_EXAMPLE_OPT" | 212 echo " $0 --delete $CHROOT_EXAMPLE_OPT" |
OLD | NEW |