Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (c) 2011-2012 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """This script fetches and prepares an SDK chroot. |
| 7 | """ |
| 8 | |
| 9 | import optparse |
| 10 | import os |
| 11 | import sys |
| 12 | import urlparse |
| 13 | |
| 14 | from chromite.buildbot import constants |
Brian Harring | cfe762a | 2012-02-29 13:03:53 -0800 | [diff] [blame] | 15 | from chromite.lib import cgroups |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 16 | from chromite.lib import cros_build_lib |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 17 | from chromite.lib import locking |
Brian Harring | cfe762a | 2012-02-29 13:03:53 -0800 | [diff] [blame] | 18 | from chromite.lib import sudo |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 19 | |
| 20 | cros_build_lib.STRICT_SUDO = True |
| 21 | |
| 22 | |
| 23 | DEFAULT_URL = 'https://commondatastorage.googleapis.com/chromiumos-sdk/' |
| 24 | SRC_ROOT = os.path.realpath(constants.SOURCE_ROOT) |
| 25 | SDK_DIR = os.path.join(SRC_ROOT, 'sdks') |
| 26 | OVERLAY_DIR = os.path.join(SRC_ROOT, 'src/third_party/chromiumos-overlay') |
| 27 | SDK_VERSION_FILE = os.path.join(OVERLAY_DIR, |
| 28 | 'chromeos/binhost/host/sdk_version.conf') |
| 29 | |
| 30 | # TODO(zbehan): Remove the dependency on these, reimplement them in python |
| 31 | MAKE_CHROOT = [os.path.join(SRC_ROOT, 'src/scripts/sdk_lib/make_chroot.sh')] |
| 32 | ENTER_CHROOT = [os.path.join(SRC_ROOT, 'src/scripts/sdk_lib/enter_chroot.sh')] |
| 33 | |
| 34 | # We need these tools to run. Very common tools (tar,..) are ommited. |
| 35 | NEEDED_TOOLS = ['curl'] |
| 36 | |
| 37 | def GetHostArch(): |
| 38 | """Returns a string for the host architecture""" |
| 39 | out = cros_build_lib.RunCommand(['uname', '-m'], |
| 40 | redirect_stdout=True, print_cmd=False).output |
| 41 | return out.rstrip('\n') |
| 42 | |
| 43 | def CheckPrerequisites(needed_tools): |
| 44 | """Verifies that the required tools are present on the system. |
| 45 | |
| 46 | This is especially important as this script is intended to run |
| 47 | outside the chroot. |
| 48 | |
| 49 | Arguments: |
| 50 | needed_tools: an array of string specified binaries to look for. |
| 51 | |
| 52 | Returns: |
| 53 | True if all needed tools were found. |
| 54 | """ |
Brian Harring | 98b5490 | 2012-03-23 04:05:42 -0700 | [diff] [blame] | 55 | missing = [] |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 56 | for tool in needed_tools: |
| 57 | cmd = ['which', tool] |
| 58 | try: |
| 59 | cros_build_lib.RunCommand(cmd, print_cmd=False, redirect_stdout=True, |
| 60 | combine_stdout_stderr=True) |
| 61 | except cros_build_lib.RunCommandError: |
Brian Harring | 98b5490 | 2012-03-23 04:05:42 -0700 | [diff] [blame] | 62 | missing.append(tool) |
| 63 | return missing |
| 64 | |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 65 | |
| 66 | def GetLatestVersion(): |
| 67 | """Extracts latest version from chromiumos-overlay.""" |
| 68 | sdk_file = open(SDK_VERSION_FILE) |
| 69 | buf = sdk_file.readline().rstrip('\n').split('=') |
| 70 | if buf[0] != 'SDK_LATEST_VERSION': |
| 71 | raise Exception('Malformed version file') |
| 72 | return buf[1].strip('"') |
| 73 | |
| 74 | |
Mike Frysinger | f66d4b5 | 2012-05-03 23:48:39 -0700 | [diff] [blame^] | 75 | def GetArchStageTarball(tarballArch, version): |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 76 | """Returns the URL for a given arch/version""" |
| 77 | D = { 'x86_64': 'cros-sdk-' } |
| 78 | try: |
Mike Frysinger | f66d4b5 | 2012-05-03 23:48:39 -0700 | [diff] [blame^] | 79 | return DEFAULT_URL + D[tarballArch] + version + '.tbz2' |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 80 | except KeyError: |
Brian Harring | 98b5490 | 2012-03-23 04:05:42 -0700 | [diff] [blame] | 81 | raise SystemExit('Unsupported arch: %s' % (tarballArch,)) |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 82 | |
| 83 | |
Mike Frysinger | f66d4b5 | 2012-05-03 23:48:39 -0700 | [diff] [blame^] | 84 | def FetchRemoteTarball(url): |
| 85 | """Fetches a tarball given by url, and place it in sdk/.""" |
Zdenek Behan | 9c644dd | 2012-04-05 06:24:02 +0200 | [diff] [blame] | 86 | |
| 87 | def RunCurl(args, **kwargs): |
| 88 | """Runs curl and wraps around all necessary hacks.""" |
| 89 | cmd = ['curl'] |
| 90 | cmd.extend(args) |
| 91 | |
| 92 | result = cros_build_lib.RunCommand(cmd, error_ok=True, **kwargs) |
| 93 | if result.returncode > 0: |
| 94 | # These are the return codes of failing certs as per 'man curl'. |
| 95 | if result.returncode in (51, 58, 60): |
| 96 | print 'Download failed with certificate error? Try "sudo c_rehash".' |
| 97 | else: |
| 98 | print 'Curl failed!' |
| 99 | sys.exit(1) |
| 100 | |
| 101 | return result |
| 102 | |
Zdenek Behan | b2fa72e | 2012-03-16 04:49:30 +0100 | [diff] [blame] | 103 | tarball_name = os.path.basename(urlparse.urlparse(url).path) |
| 104 | tarball_dest = os.path.join(SDK_DIR, tarball_name) |
| 105 | |
| 106 | # Cleanup old tarballs. |
| 107 | files_to_delete = [f for f in os.listdir(SDK_DIR) if f != tarball_name] |
| 108 | if files_to_delete: |
| 109 | print 'Cleaning up old tarballs: ' + str(files_to_delete) |
| 110 | for f in files_to_delete: |
| 111 | f_path = os.path.join(SDK_DIR, f) |
| 112 | # Only delete regular files that belong to us. |
| 113 | if os.path.isfile(f_path) and os.stat(f_path).st_uid == os.getuid(): |
| 114 | os.remove(f_path) |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 115 | |
Zdenek Behan | 9c644dd | 2012-04-05 06:24:02 +0200 | [diff] [blame] | 116 | curl_opts = ['-f', '--retry', '5', '-L', '-y', '30', |
| 117 | '--output', tarball_dest] |
Mike Frysinger | f66d4b5 | 2012-05-03 23:48:39 -0700 | [diff] [blame^] | 118 | print 'Downloading sdk: "%s"' % url |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 119 | if not url.startswith('file://') and os.path.exists(tarball_dest): |
| 120 | # Only resume for remote URLs. If the file is local, there's no |
| 121 | # real speedup, and using the same filename for different files |
| 122 | # locally will cause issues. |
Zdenek Behan | 9c644dd | 2012-04-05 06:24:02 +0200 | [diff] [blame] | 123 | curl_opts.extend(['-C', '-']) |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 124 | |
| 125 | # Additionally, certain versions of curl incorrectly fail if |
| 126 | # told to resume a file that is fully downloaded, thus do a |
| 127 | # check on our own. |
| 128 | # see: |
| 129 | # https://sourceforge.net/tracker/?func=detail&atid=100976&aid=3482927&group_id=976 |
Zdenek Behan | 9c644dd | 2012-04-05 06:24:02 +0200 | [diff] [blame] | 130 | result = RunCurl(['-I', url], |
| 131 | redirect_stdout=True, |
| 132 | redirect_stderr=True, |
| 133 | print_cmd=False) |
| 134 | |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 135 | for x in result.output.splitlines(): |
| 136 | if x.lower().startswith("content-length:"): |
| 137 | length = int(x.split(":", 1)[-1].strip()) |
| 138 | if length == os.path.getsize(tarball_dest): |
| 139 | # Fully fetched; bypass invoking curl, since it can screw up handling |
| 140 | # of this (>=7.21.4 and up). |
| 141 | return tarball_dest |
| 142 | break |
Zdenek Behan | 9c644dd | 2012-04-05 06:24:02 +0200 | [diff] [blame] | 143 | curl_opts.append(url) |
| 144 | RunCurl(curl_opts) |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 145 | return tarball_dest |
| 146 | |
| 147 | |
| 148 | def BootstrapChroot(chroot_path, stage_url, replace): |
| 149 | """Builds a new chroot from source""" |
| 150 | cmd = MAKE_CHROOT + ['--chroot', chroot_path, |
| 151 | '--nousepkg'] |
| 152 | |
| 153 | stage = None |
| 154 | if stage_url: |
Mike Frysinger | f66d4b5 | 2012-05-03 23:48:39 -0700 | [diff] [blame^] | 155 | stage = FetchRemoteTarball(stage_url) |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 156 | |
| 157 | if stage: |
| 158 | cmd.extend(['--stage3_path', stage]) |
| 159 | |
| 160 | if replace: |
| 161 | cmd.append('--replace') |
| 162 | |
| 163 | try: |
| 164 | cros_build_lib.RunCommand(cmd, print_cmd=False) |
| 165 | except cros_build_lib.RunCommandError: |
Brian Harring | 98b5490 | 2012-03-23 04:05:42 -0700 | [diff] [blame] | 166 | raise SystemExit('Running %r failed!' % cmd) |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 167 | |
| 168 | |
| 169 | def CreateChroot(sdk_url, sdk_version, chroot_path, replace): |
| 170 | """Creates a new chroot from a given SDK""" |
| 171 | if not os.path.exists(SDK_DIR): |
| 172 | cros_build_lib.RunCommand(['mkdir', '-p', SDK_DIR], print_cmd=False) |
| 173 | |
| 174 | # Based on selections, fetch the tarball |
| 175 | if sdk_url: |
Mike Frysinger | f66d4b5 | 2012-05-03 23:48:39 -0700 | [diff] [blame^] | 176 | url = sdk_url |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 177 | else: |
| 178 | arch = GetHostArch() |
Mike Frysinger | f66d4b5 | 2012-05-03 23:48:39 -0700 | [diff] [blame^] | 179 | if sdk_version: |
| 180 | url = GetArchStageTarball(arch, sdk_version) |
| 181 | else: |
| 182 | url = GetArchStageTarball(arch) |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 183 | |
Mike Frysinger | f66d4b5 | 2012-05-03 23:48:39 -0700 | [diff] [blame^] | 184 | sdk = FetchRemoteTarball(url) |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 185 | |
| 186 | # TODO(zbehan): Unpack and install |
| 187 | # For now, we simply call make_chroot on the prebuilt chromeos-sdk. |
| 188 | # make_chroot provides a variety of hacks to make the chroot useable. |
| 189 | # These should all be eliminated/minimised, after which, we can change |
| 190 | # this to just unpacking the sdk. |
| 191 | cmd = MAKE_CHROOT + ['--stage3_path', sdk, |
| 192 | '--chroot', chroot_path] |
| 193 | |
| 194 | if replace: |
| 195 | cmd.append('--replace') |
| 196 | |
| 197 | try: |
| 198 | cros_build_lib.RunCommand(cmd, print_cmd=False) |
| 199 | except cros_build_lib.RunCommandError: |
Brian Harring | 98b5490 | 2012-03-23 04:05:42 -0700 | [diff] [blame] | 200 | raise SystemExit('Running %r failed!' % cmd) |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 201 | |
| 202 | |
| 203 | def DeleteChroot(chroot_path): |
| 204 | """Deletes an existing chroot""" |
| 205 | cmd = MAKE_CHROOT + ['--chroot', chroot_path, |
| 206 | '--delete'] |
| 207 | try: |
| 208 | cros_build_lib.RunCommand(cmd, print_cmd=False) |
| 209 | except cros_build_lib.RunCommandError: |
Brian Harring | 98b5490 | 2012-03-23 04:05:42 -0700 | [diff] [blame] | 210 | raise SystemExit('Running %r failed!' % cmd) |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 211 | |
| 212 | |
| 213 | def _CreateLockFile(path): |
Mike Frysinger | f66d4b5 | 2012-05-03 23:48:39 -0700 | [diff] [blame^] | 214 | """Create a lockfile via sudo that is writable by current user.""" |
| 215 | cros_build_lib.SudoRunCommand(['touch', path], print_cmd=False) |
| 216 | cros_build_lib.SudoRunCommand(['chown', str(os.getuid()), path], |
| 217 | print_cmd=False) |
| 218 | cros_build_lib.SudoRunCommand(['chmod', '644', path], print_cmd=False) |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 219 | |
| 220 | |
| 221 | def EnterChroot(chroot_path, chrome_root, chrome_root_mount, additional_args): |
| 222 | """Enters an existing SDK chroot""" |
| 223 | cmd = ENTER_CHROOT + ['--chroot', chroot_path] |
| 224 | if chrome_root: |
| 225 | cmd.extend(['--chrome_root', chrome_root]) |
| 226 | if chrome_root_mount: |
| 227 | cmd.extend(['--chrome_root_mount', chrome_root_mount]) |
| 228 | if len(additional_args) > 0: |
| 229 | cmd.append('--') |
| 230 | cmd.extend(additional_args) |
Brian Harring | 7199e7d | 2012-03-23 04:10:08 -0700 | [diff] [blame] | 231 | |
| 232 | ret = cros_build_lib.RunCommand(cmd, print_cmd=False, error_code_ok=True) |
| 233 | # If we were in interactive mode, ignore the exit code; it'll be whatever |
| 234 | # they last ran w/in the chroot and won't matter to us one way or another. |
| 235 | # Note this does allow chroot entrance to fail and be ignored during |
| 236 | # interactive; this is however a rare case and the user will immediately |
| 237 | # see it (nor will they be checking the exit code manually). |
| 238 | if ret.returncode != 0 and additional_args: |
| 239 | raise SystemExit('Running %r failed with exit code %i' |
| 240 | % (cmd, ret.returncode)) |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 241 | |
| 242 | |
Brian Harring | 6be2efc | 2012-03-01 05:04:00 -0800 | [diff] [blame] | 243 | def main(argv): |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 244 | # TODO(ferringb): make argv required once depot_tools is fixed. |
Mike Frysinger | f66d4b5 | 2012-05-03 23:48:39 -0700 | [diff] [blame^] | 245 | usage="""usage: %prog [options] [VAR1=val1 .. VARn=valn -- <args>] |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 246 | |
| 247 | This script manages a local CrOS SDK chroot. Depending on the flags, |
| 248 | it can download, build or enter a chroot. |
| 249 | |
| 250 | Action taken is the following: |
| 251 | --enter (default) .. Installs and enters a chroot |
| 252 | --download .. Just download a chroot (enter if combined with --enter) |
| 253 | --bootstrap .. Builds a chroot from source (enter if --enter) |
| 254 | --delete .. Removes a chroot |
| 255 | """ |
| 256 | sdk_latest_version = GetLatestVersion() |
| 257 | parser = optparse.OptionParser(usage) |
| 258 | # Actions: |
| 259 | parser.add_option('', '--bootstrap', |
| 260 | action='store_true', dest='bootstrap', default=False, |
| 261 | help=('Build a new SDK chroot from source')) |
| 262 | parser.add_option('', '--delete', |
| 263 | action='store_true', dest='delete', default=False, |
| 264 | help=('Delete the current SDK chroot')) |
| 265 | parser.add_option('', '--download', |
| 266 | action='store_true', dest='download', default=False, |
| 267 | help=('Download and install a prebuilt SDK')) |
| 268 | parser.add_option('', '--enter', |
| 269 | action='store_true', dest='enter', default=False, |
| 270 | help=('Enter the SDK chroot, possibly (re)create first')) |
| 271 | |
| 272 | # Global options: |
| 273 | parser.add_option('', '--chroot', |
| 274 | dest='chroot', default=constants.DEFAULT_CHROOT_DIR, |
| 275 | help=('SDK chroot dir name [%s]' % |
| 276 | constants.DEFAULT_CHROOT_DIR)) |
| 277 | |
| 278 | # Additional options: |
| 279 | parser.add_option('', '--chrome_root', |
| 280 | dest='chrome_root', default='', |
| 281 | help=('Mount this chrome root into the SDK chroot')) |
| 282 | parser.add_option('', '--chrome_root_mount', |
| 283 | dest='chrome_root_mount', default='', |
| 284 | help=('Mount chrome into this path inside SDK chroot')) |
| 285 | parser.add_option('-r', '--replace', |
| 286 | action='store_true', dest='replace', default=False, |
| 287 | help=('Replace an existing SDK chroot')) |
| 288 | parser.add_option('-u', '--url', |
| 289 | dest='sdk_url', default='', |
| 290 | help=('''Use sdk tarball located at this url. |
| 291 | Use file:// for local files.''')) |
| 292 | parser.add_option('-v', '--version', |
| 293 | dest='sdk_version', default='', |
| 294 | help=('Use this sdk version [%s]' % sdk_latest_version)) |
| 295 | (options, remaining_arguments) = parser.parse_args(argv) |
| 296 | |
| 297 | # Some sanity checks first, before we ask for sudo credentials. |
| 298 | if cros_build_lib.IsInsideChroot(): |
Brian Harring | 98b5490 | 2012-03-23 04:05:42 -0700 | [diff] [blame] | 299 | parser.error("This needs to be ran outside the chroot") |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 300 | |
Brian Harring | 98b5490 | 2012-03-23 04:05:42 -0700 | [diff] [blame] | 301 | missing = CheckPrerequisites(NEEDED_TOOLS) |
| 302 | if missing: |
| 303 | parser.error(( |
| 304 | 'The tool(s) %s were not found.' |
| 305 | 'Please install the appropriate package in your host.' |
| 306 | 'Example(ubuntu):' |
| 307 | ' sudo apt-get install <packagename>' |
| 308 | % (', '.join(missing)))) |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 309 | |
| 310 | # Default action is --enter, if no other is selected. |
| 311 | if not (options.bootstrap or options.download or options.delete): |
| 312 | options.enter = True |
| 313 | |
| 314 | # Only --enter can process additional args as passthrough commands. |
| 315 | # Warn and exit for least surprise. |
| 316 | if len(remaining_arguments) > 0 and not options.enter: |
Brian Harring | 98b5490 | 2012-03-23 04:05:42 -0700 | [diff] [blame] | 317 | parser.error("Additional arguments are not permitted, unless running " |
| 318 | "with --enter") |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 319 | |
| 320 | # Some actions can be combined, as they merely modify how is the chroot |
| 321 | # going to be made. The only option that hates all others is --delete. |
| 322 | if options.delete and \ |
| 323 | (options.enter or options.download or options.bootstrap): |
Brian Harring | 98b5490 | 2012-03-23 04:05:42 -0700 | [diff] [blame] | 324 | parser.error("--delete cannot be combined with --enter, " |
| 325 | "--download or --bootstrap") |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 326 | # NOTE: --delete is a true hater, it doesn't like other options either, but |
| 327 | # those will hardly lead to confusion. Nobody can expect to pass --version to |
| 328 | # delete and actually change something. |
| 329 | |
| 330 | if options.bootstrap and options.download: |
Brian Harring | 98b5490 | 2012-03-23 04:05:42 -0700 | [diff] [blame] | 331 | parser.error("Either --bootstrap or --download, not both") |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 332 | |
| 333 | # Bootstrap will start off from a non-selectable stage3 tarball. Attempts to |
| 334 | # select sdk by version are confusing. Warn and exit. We can still specify a |
| 335 | # tarball by path or URL though. |
| 336 | if options.bootstrap and options.sdk_version: |
Brian Harring | 98b5490 | 2012-03-23 04:05:42 -0700 | [diff] [blame] | 337 | parser.error("Cannot use --version when bootstrapping") |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 338 | |
| 339 | chroot_path = os.path.join(SRC_ROOT, options.chroot) |
| 340 | chroot_path = os.path.abspath(chroot_path) |
| 341 | chroot_path = os.path.normpath(chroot_path) |
| 342 | |
| 343 | if not options.sdk_version: |
| 344 | sdk_version = sdk_latest_version |
| 345 | else: |
| 346 | sdk_version = options.sdk_version |
| 347 | |
| 348 | if options.delete and not os.path.exists(chroot_path): |
| 349 | print "Not doing anything. The chroot you want to remove doesn't exist." |
Brian Harring | 98b5490 | 2012-03-23 04:05:42 -0700 | [diff] [blame] | 350 | return 0 |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 351 | |
| 352 | lock_path = os.path.dirname(chroot_path) |
| 353 | lock_path = os.path.join(lock_path, |
| 354 | '.%s_lock' % os.path.basename(chroot_path)) |
| 355 | with sudo.SudoKeepAlive(): |
Brian Harring | 4e6412d | 2012-03-09 20:54:02 -0800 | [diff] [blame] | 356 | with cgroups.SimpleContainChildren('cros_sdk'): |
Brian Harring | cfe762a | 2012-02-29 13:03:53 -0800 | [diff] [blame] | 357 | _CreateLockFile(lock_path) |
| 358 | with locking.FileLock(lock_path, 'chroot lock') as lock: |
| 359 | if options.delete: |
| 360 | lock.write_lock() |
| 361 | DeleteChroot(chroot_path) |
Brian Harring | 98b5490 | 2012-03-23 04:05:42 -0700 | [diff] [blame] | 362 | return 0 |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 363 | |
Brian Harring | cfe762a | 2012-02-29 13:03:53 -0800 | [diff] [blame] | 364 | # Print a suggestion for replacement, but not if running just --enter. |
| 365 | if os.path.exists(chroot_path) and not options.replace and \ |
| 366 | (options.bootstrap or options.download): |
| 367 | print "Chroot already exists. Run with --replace to re-create." |
Brian Harring | b938c78 | 2012-02-29 15:14:38 -0800 | [diff] [blame] | 368 | |
Brian Harring | cfe762a | 2012-02-29 13:03:53 -0800 | [diff] [blame] | 369 | # Chroot doesn't exist or asked to replace. |
| 370 | if not os.path.exists(chroot_path) or options.replace: |
| 371 | lock.write_lock() |
| 372 | if options.bootstrap: |
| 373 | BootstrapChroot(chroot_path, options.sdk_url, |
| 374 | options.replace) |
| 375 | else: |
| 376 | CreateChroot(options.sdk_url, sdk_version, |
| 377 | chroot_path, options.replace) |
| 378 | if options.enter: |
| 379 | lock.read_lock() |
| 380 | EnterChroot(chroot_path, options.chrome_root, |
| 381 | options.chrome_root_mount, remaining_arguments) |