OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 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 |
| 4 # found in the LICENSE file. |
| 5 |
| 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 |
| 8 # install-build-deps.sh. |
| 9 |
| 10 import os |
| 11 import shutil |
| 12 import subprocess |
| 13 import sys |
| 14 |
| 15 URL_TEMPLATE = ('https://commondatastorage.googleapis.com/chromeos-localmirror/' |
| 16 'distfiles/%(name)s-%(version)s.tar.bz2') |
| 17 |
| 18 # Taken from the media-fonts/<name> ebuilds in chromiumos-overlay. |
| 19 SOURCES = [ |
| 20 { |
| 21 'name': 'notofonts', |
| 22 'version': '20150706' |
| 23 }, { |
| 24 'name': 'robotofonts', |
| 25 'version': '20150625' |
| 26 } |
| 27 ] |
| 28 |
| 29 URLS = sorted([URL_TEMPLATE % d for d in SOURCES]) |
| 30 FONTS_DIR = '/usr/local/share/fonts' |
| 31 |
| 32 def main(args): |
| 33 if not sys.platform.startswith('linux'): |
| 34 print "Error: %s must be run on Linux." % __file__ |
| 35 return 1 |
| 36 |
| 37 if os.getuid() != 0: |
| 38 print "Error: %s must be run as root." % __file__ |
| 39 return 1 |
| 40 |
| 41 if not os.path.isdir(FONTS_DIR): |
| 42 print "Error: Destination directory does not exist: %s" % FONTS_DIR |
| 43 return 1 |
| 44 |
| 45 dest_dir = os.path.join(FONTS_DIR, 'chromeos') |
| 46 |
| 47 stamp = os.path.join(dest_dir, ".stamp02") |
| 48 if os.path.exists(stamp): |
| 49 with open(stamp) as s: |
| 50 if s.read() == '\n'.join(URLS): |
| 51 print "Chrome OS fonts already up-to-date in %s." % dest_dir |
| 52 return 0 |
| 53 |
| 54 if os.path.isdir(dest_dir): |
| 55 shutil.rmtree(dest_dir) |
| 56 os.mkdir(dest_dir) |
| 57 os.chmod(dest_dir, 0755) |
| 58 |
| 59 print "Installing Chrome OS fonts to %s." % dest_dir |
| 60 for url in URLS: |
| 61 tarball = os.path.join(dest_dir, os.path.basename(url)) |
| 62 subprocess.check_call(['curl', '-L', url, '-o', tarball]) |
| 63 subprocess.check_call(['tar', '--no-same-owner', '--no-same-permissions', |
| 64 '-xf', tarball, '-C', dest_dir]) |
| 65 os.remove(tarball) |
| 66 |
| 67 readme = os.path.join(dest_dir, "README") |
| 68 with open(readme, 'w') as s: |
| 69 s.write("This directory and its contents are auto-generated.\n") |
| 70 s.write("It may be deleted and recreated. Do not modify.\n") |
| 71 s.write("Script: %s\n" % __file__) |
| 72 |
| 73 with open(stamp, 'w') as s: |
| 74 s.write('\n'.join(URLS)) |
| 75 |
| 76 for base, dirs, files in os.walk(dest_dir): |
| 77 for dir in dirs: |
| 78 os.chmod(os.path.join(base, dir), 0755) |
| 79 for file in files: |
| 80 os.chmod(os.path.join(base, file), 0644) |
| 81 |
| 82 return 0 |
| 83 |
| 84 if __name__ == '__main__': |
| 85 sys.exit(main(sys.argv[1:])) |
OLD | NEW |