aroben | c3aee5a | 2007-06-12 23:58:50 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import os, random, sys, time, urllib |
| 4 | |
| 5 | # |
| 6 | # Options |
| 7 | # |
| 8 | |
| 9 | dry_run = len(sys.argv) > 1 and "--dry-run" in set(sys.argv[1:]) |
| 10 | quiet = len(sys.argv) > 1 and "--quiet" in set(sys.argv[1:]) |
| 11 | |
| 12 | # |
| 13 | # Functions and constants |
| 14 | # |
| 15 | |
| 16 | def download_progress_hook(block_count, block_size, total_blocks): |
| 17 | if quiet or random.random() > 0.5: |
| 18 | return |
| 19 | sys.stdout.write(".") |
| 20 | sys.stdout.flush() |
| 21 | |
| 22 | def download_url_to_file(url, file, message): |
| 23 | if not quiet: |
| 24 | print message + " ", |
| 25 | if not dry_run: |
| 26 | dir = os.path.dirname(file) |
| 27 | if len(dir) and not os.path.exists(dir): |
| 28 | os.makedirs(dir) |
| 29 | urllib.urlretrieve(url, file, download_progress_hook) |
| 30 | if not quiet: |
| 31 | print |
| 32 | |
| 33 | # This is mostly just the list of North America http mirrors from http://cygwin.com/mirrors.html, |
| 34 | # but a few have been removed that seemed unresponsive from Cupertino. |
| 35 | mirror_servers = ["http://cygwin.elite-systems.org/", |
| 36 | "http://mirror.mcs.anl.gov/cygwin/", |
| 37 | "http://cygwin.osuosl.org/", |
| 38 | "http://mirrors.kernel.org/sourceware/cygwin/", |
aroben | c3aee5a | 2007-06-12 23:58:50 +0000 | [diff] [blame] | 39 | "http://mirrors.xmission.com/cygwin/", |
| 40 | "http://sourceware.mirrors.tds.net/pub/sourceware.org/cygwin/"] |
| 41 | |
| 42 | package_mirror_url = mirror_servers[random.choice(range(len(mirror_servers)))] |
| 43 | |
| 44 | def download_package(package, message): |
| 45 | download_url_to_file(package_mirror_url + package["path"], package["path"], message) |
| 46 | |
agomez@igalia.com | 6d022e8 | 2014-04-04 08:11:34 +0000 | [diff] [blame] | 47 | required_packages = frozenset(["bc", |
aroben | c3aee5a | 2007-06-12 23:58:50 +0000 | [diff] [blame] | 48 | "bison", |
| 49 | "curl", |
weinig | 04411e8 | 2007-06-14 21:42:56 +0000 | [diff] [blame] | 50 | "diffutils", |
aroben | c3aee5a | 2007-06-12 23:58:50 +0000 | [diff] [blame] | 51 | "e2fsprogs", |
| 52 | "emacs", |
| 53 | "flex", |
agomez@igalia.com | 6d022e8 | 2014-04-04 08:11:34 +0000 | [diff] [blame] | 54 | "gcc-g++", |
aroben | c3aee5a | 2007-06-12 23:58:50 +0000 | [diff] [blame] | 55 | "gperf", |
aroben | 24ab02e | 2007-10-03 00:18:47 +0000 | [diff] [blame] | 56 | "keychain", |
roger_fong@apple.com | 29ea466 | 2013-09-09 21:59:18 +0000 | [diff] [blame] | 57 | "lighttpd", |
aroben | c3aee5a | 2007-06-12 23:58:50 +0000 | [diff] [blame] | 58 | "make", |
| 59 | "nano", |
| 60 | "openssh", |
| 61 | "patch", |
| 62 | "perl", |
| 63 | "perl-libwin32", |
aroben | fb01b1b | 2007-09-26 01:56:43 +0000 | [diff] [blame] | 64 | "python", |
aroben | c3aee5a | 2007-06-12 23:58:50 +0000 | [diff] [blame] | 65 | "rebase", |
aroben | fb01b1b | 2007-09-26 01:56:43 +0000 | [diff] [blame] | 66 | "rsync", |
aroben@apple.com | 5bae8ab | 2008-03-21 16:29:09 +0000 | [diff] [blame] | 67 | "ruby", |
aroben | c3aee5a | 2007-06-12 23:58:50 +0000 | [diff] [blame] | 68 | "subversion", |
| 69 | "unzip", |
| 70 | "vim", |
| 71 | "zip"]) |
| 72 | |
agomez@igalia.com | ac65be9 | 2014-04-17 16:47:56 +0000 | [diff] [blame] | 73 | required_packages_versions = {"curl": "7.33.0-1", |
| 74 | "libcurl4": "7.33.0-1", |
| 75 | "python": "2.6.8-2", |
| 76 | "subversion": "1.7.14-1"} |
agomez@igalia.com | 6d022e8 | 2014-04-04 08:11:34 +0000 | [diff] [blame] | 77 | |
aroben | c3aee5a | 2007-06-12 23:58:50 +0000 | [diff] [blame] | 78 | # |
| 79 | # Main |
| 80 | # |
| 81 | |
| 82 | print "Using Cygwin mirror server " + package_mirror_url + " to download setup.ini..." |
| 83 | |
roger_fong@apple.com | a9a1367 | 2013-09-12 22:46:57 +0000 | [diff] [blame] | 84 | urllib.urlretrieve(package_mirror_url + "x86/setup.ini", "setup.ini.orig") |
aroben | c3aee5a | 2007-06-12 23:58:50 +0000 | [diff] [blame] | 85 | |
| 86 | downloaded_packages_file_path = "setup.ini.orig" |
| 87 | downloaded_packages_file = file(downloaded_packages_file_path, "r") |
| 88 | if not dry_run: |
| 89 | modified_packages_file = file("setup.ini", "w") |
| 90 | |
| 91 | packages = {} |
| 92 | current_package = '' |
| 93 | for line in downloaded_packages_file.readlines(): |
| 94 | if line[0] == "@": |
| 95 | current_package = line[2:-1] |
agomez@igalia.com | 6d022e8 | 2014-04-04 08:11:34 +0000 | [diff] [blame] | 96 | packages[current_package] = {"name": current_package, "needs_download": False, "requires": [], "path": "", "version": "", "found_version": False} |
| 97 | if current_package in required_packages_versions: |
| 98 | packages[current_package]["version"] = required_packages_versions[current_package] |
aroben | c3aee5a | 2007-06-12 23:58:50 +0000 | [diff] [blame] | 99 | elif line[:10] == "category: ": |
| 100 | if current_package in required_packages: |
| 101 | line = "category: Base\n" |
| 102 | if "Base" in set(line[10:-1].split()): |
| 103 | packages[current_package]["needs_download"] = True |
| 104 | elif line[:10] == "requires: ": |
| 105 | packages[current_package]["requires"] = line[10:].split() |
| 106 | packages[current_package]["requires"].sort() |
agomez@igalia.com | 6d022e8 | 2014-04-04 08:11:34 +0000 | [diff] [blame] | 107 | elif line[:9] == "version: " and not packages[current_package]["found_version"]: |
| 108 | if not len(packages[current_package]["version"]): |
| 109 | packages[current_package]["version"] = line[9:-1] |
| 110 | packages[current_package]["found_version"] = True |
| 111 | else: |
| 112 | packages[current_package]["found_version"] = (packages[current_package]["version"] == line[9:-1]) |
| 113 | elif line[:9] == "install: " and packages[current_package]["found_version"] and not len(packages[current_package]["path"]): |
aroben | c3aee5a | 2007-06-12 23:58:50 +0000 | [diff] [blame] | 114 | end_of_path = line.find(" ", 9) |
| 115 | if end_of_path != -1: |
| 116 | packages[current_package]["path"] = line[9:end_of_path] |
| 117 | if not dry_run: |
| 118 | modified_packages_file.write(line) |
| 119 | |
| 120 | downloaded_packages_file.close() |
| 121 | os.remove(downloaded_packages_file_path) |
| 122 | if not dry_run: |
| 123 | modified_packages_file.close() |
| 124 | |
| 125 | names_to_download = set() |
| 126 | package_names = packages.keys() |
| 127 | package_names.sort() |
| 128 | |
| 129 | def add_package_and_dependencies(name): |
| 130 | if name in names_to_download: |
| 131 | return |
jhoneycutt@apple.com | 5525faa | 2008-07-17 06:20:23 +0000 | [diff] [blame] | 132 | if not name in packages: |
alp@webkit.org | 422ef29 | 2008-05-25 05:25:11 +0000 | [diff] [blame] | 133 | return |
aroben | c3aee5a | 2007-06-12 23:58:50 +0000 | [diff] [blame] | 134 | packages[name]["needs_download"] = True |
| 135 | names_to_download.add(name) |
| 136 | for dep in packages[name]["requires"]: |
| 137 | add_package_and_dependencies(dep) |
| 138 | |
| 139 | for name in package_names: |
| 140 | if packages[name]["needs_download"]: |
| 141 | add_package_and_dependencies(name) |
| 142 | |
| 143 | downloaded_so_far = 0 |
| 144 | for name in package_names: |
| 145 | if packages[name]["needs_download"]: |
| 146 | downloaded_so_far += 1 |
| 147 | download_package(packages[name], "Downloading package %3d of %3d (%s)" % (downloaded_so_far, len(names_to_download), name)) |
| 148 | |
roger_fong@apple.com | 29ea466 | 2013-09-09 21:59:18 +0000 | [diff] [blame] | 149 | download_url_to_file("http://cygwin.com/setup-x86.exe", "setup.exe", "Downloading setup.exe") |
aroben | c3aee5a | 2007-06-12 23:58:50 +0000 | [diff] [blame] | 150 | |
| 151 | seconds_to_sleep = 10 |
| 152 | |
| 153 | print """ |
| 154 | Finished downloading Cygwin. In %d seconds, |
agomez@igalia.com | ee1256c | 2014-04-16 18:51:56 +0000 | [diff] [blame] | 155 | I will run setup.exe. All the suitable options have |
| 156 | been already selected for you. |
| 157 | """ % (seconds_to_sleep) |
aroben | c3aee5a | 2007-06-12 23:58:50 +0000 | [diff] [blame] | 158 | |
| 159 | |
| 160 | while seconds_to_sleep > 0: |
| 161 | print "%d..." % seconds_to_sleep, |
| 162 | sys.stdout.flush() |
| 163 | time.sleep(1) |
| 164 | seconds_to_sleep -= 1 |
| 165 | print |
| 166 | |
| 167 | if not dry_run: |
agomez@igalia.com | ee1256c | 2014-04-16 18:51:56 +0000 | [diff] [blame] | 168 | os.execv("setup.exe", list(("-L", "-l", os.getcwd(), "-P", ",".join(required_packages)))) |