OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # Script to install the Chrome OS fonts on Linux. | 6 # Script to install the Chrome OS fonts on Linux. |
7 # This script can be run manually (as root), but is also run as part | 7 # This script can be run manually (as root), but is also run as part |
8 # install-build-deps.sh. | 8 # install-build-deps.sh. |
9 | 9 |
10 import os | 10 import os |
11 import shutil | 11 import shutil |
12 import subprocess | 12 import subprocess |
13 import sys | 13 import sys |
14 | 14 |
15 URL_PREFIX = 'https://commondatastorage.googleapis.com' | 15 # Taken from the media-fonts/notofonts ebuild in chromiumos-overlay. |
16 URL_DIR = 'chromeos-localmirror/distfiles' | 16 VERSION = '20140815' |
17 URL_FILE = 'notofonts-20121206.tar.gz' | 17 URL = ('https://commondatastorage.googleapis.com/chromeos-localmirror/' |
| 18 'distfiles/notofonts-%s.tar.bz2') % (VERSION) |
18 FONTS_DIR = '/usr/local/share/fonts' | 19 FONTS_DIR = '/usr/local/share/fonts' |
19 | 20 |
20 # The URL matches the URL in the ebuild script in chromiumos. See: | |
21 # /path/to/chromiumos/src/ | |
22 # third_party/chromiumos-overlay/media-fonts/notofonts/ | |
23 # notofonts-20121206.ebuild | |
24 | |
25 def main(args): | 21 def main(args): |
26 if not sys.platform.startswith('linux'): | 22 if not sys.platform.startswith('linux'): |
27 print "Error: %s must be run on Linux." % __file__ | 23 print "Error: %s must be run on Linux." % __file__ |
28 return 1 | 24 return 1 |
29 | 25 |
30 if os.getuid() != 0: | 26 if os.getuid() != 0: |
31 print "Error: %s must be run as root." % __file__ | 27 print "Error: %s must be run as root." % __file__ |
32 return 1 | 28 return 1 |
33 | 29 |
34 if not os.path.isdir(FONTS_DIR): | 30 if not os.path.isdir(FONTS_DIR): |
35 print "Error: Destination directory does not exist: %s" % FONTS_DIR | 31 print "Error: Destination directory does not exist: %s" % FONTS_DIR |
36 return 1 | 32 return 1 |
37 | 33 |
38 dest_dir = os.path.join(FONTS_DIR, 'chromeos') | 34 dest_dir = os.path.join(FONTS_DIR, 'chromeos') |
39 | 35 |
40 url = "%s/%s/%s" % (URL_PREFIX, URL_DIR, URL_FILE) | |
41 | |
42 stamp = os.path.join(dest_dir, ".stamp02") | 36 stamp = os.path.join(dest_dir, ".stamp02") |
43 if os.path.exists(stamp): | 37 if os.path.exists(stamp): |
44 with open(stamp) as s: | 38 with open(stamp) as s: |
45 if s.read() == url: | 39 if s.read() == URL: |
46 print "Chrome OS fonts already up-to-date in %s." % dest_dir | 40 print "Chrome OS fonts already up-to-date in %s." % dest_dir |
47 return 0 | 41 return 0 |
48 | 42 |
49 if os.path.isdir(dest_dir): | 43 if os.path.isdir(dest_dir): |
50 shutil.rmtree(dest_dir) | 44 shutil.rmtree(dest_dir) |
51 os.mkdir(dest_dir) | 45 os.mkdir(dest_dir) |
52 os.chmod(dest_dir, 0755) | 46 os.chmod(dest_dir, 0755) |
53 | 47 |
54 print "Installing Chrome OS fonts to %s." % dest_dir | 48 print "Installing Chrome OS fonts to %s." % dest_dir |
55 tarball = os.path.join(dest_dir, URL_FILE) | 49 tarball = os.path.join(dest_dir, os.path.basename(URL)) |
56 subprocess.check_call(['curl', '-L', url, '-o', tarball]) | 50 subprocess.check_call(['curl', '-L', URL, '-o', tarball]) |
57 subprocess.check_call(['tar', '--no-same-owner', '--no-same-permissions', | 51 subprocess.check_call(['tar', '--no-same-owner', '--no-same-permissions', |
58 '-xf', tarball, '-C', dest_dir]) | 52 '-xf', tarball, '-C', dest_dir]) |
59 os.remove(tarball) | 53 os.remove(tarball) |
60 | 54 |
61 readme = os.path.join(dest_dir, "README") | 55 readme = os.path.join(dest_dir, "README") |
62 with open(readme, 'w') as s: | 56 with open(readme, 'w') as s: |
63 s.write("This directory and its contents are auto-generated.\n") | 57 s.write("This directory and its contents are auto-generated.\n") |
64 s.write("It may be deleted and recreated. Do not modify.\n") | 58 s.write("It may be deleted and recreated. Do not modify.\n") |
65 s.write("Script: %s\n" % __file__) | 59 s.write("Script: %s\n" % __file__) |
66 | 60 |
67 with open(stamp, 'w') as s: | 61 with open(stamp, 'w') as s: |
68 s.write(url) | 62 s.write(URL) |
69 | 63 |
70 for base, dirs, files in os.walk(dest_dir): | 64 for base, dirs, files in os.walk(dest_dir): |
71 for dir in dirs: | 65 for dir in dirs: |
72 os.chmod(os.path.join(base, dir), 0755) | 66 os.chmod(os.path.join(base, dir), 0755) |
73 for file in files: | 67 for file in files: |
74 os.chmod(os.path.join(base, file), 0644) | 68 os.chmod(os.path.join(base, file), 0644) |
75 | 69 |
76 return 0 | 70 return 0 |
77 | 71 |
78 if __name__ == '__main__': | 72 if __name__ == '__main__': |
79 sys.exit(main(sys.argv[1:])) | 73 sys.exit(main(sys.argv[1:])) |
OLD | NEW |