This repository has been archived by the owner on Oct 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 173
/
install
120 lines (104 loc) · 3.54 KB
/
install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby
# Adapted from the Homebrew installer: http://brew.sh
SF_PREFIX = '/Library/Fonts'
SF_REPO = 'https://github.com/supermarin/YosemiteSanFranciscoFont'
module Tty extend self
def blue; bold 34; end
def white; bold 39; end
def red; bold 31; end
def reset; escape 0; end
def bold n; escape "1;#{n}" end
def underline n; escape "4;#{n}" end
def escape n; "\033[#{n}m" if STDOUT.tty? end
end
class Array
def shell_s
cp = dup
first = cp.shift
cp.map{ |arg| arg.gsub " ", "\\ " }.unshift(first) * " "
end
end
def ohai *args
puts "#{Tty.blue}==>#{Tty.white} #{args.shell_s}#{Tty.reset}"
end
def warn warning
puts "#{Tty.red}==>#{Tty.reset} #{warning.chomp}"
end
def system *args
abort "Failed during: #{args.shell_s}" unless Kernel.system(*args)
end
def getc # NOTE only tested on OS X
system "/bin/stty raw -echo"
if STDIN.respond_to?(:getbyte)
STDIN.getbyte
else
STDIN.getc
end
ensure
system "/bin/stty -raw echo"
end
def wait_for_user
puts
ohai "Press RETURN to continue or any other key to abort."
c = getc
# we test for \r and \n because some stuff does \r instead
abort unless c == 13 or c == 10
end
def wait_for_reinstall
ohai "Press RETURN to reinstall or any other key to abort."
c = getc
# we test for \r and \n because some stuff does \r instead
abort unless c == 13 or c == 10
end
module Version
def <=>(other)
split(".").map { |i| i.to_i } <=> other.split(".").map { |i| i.to_i }
end
end
def macos_version
@macos_version ||= `/usr/bin/sw_vers -productVersion`.chomp[/10\.\d+/].extend(Version)
end
#######################################################################
abort "San Francisco is only available on OS X 10.10 Yosemite." if /linux/i === RUBY_PLATFORM
abort "San Francisco is only available on OS X 10.10 Yosemite." if macos_version < "10.10"
abort "Don't run this as root!" if Process.uid == 0
abort <<-EOABORT unless `groups`.split.include? "admin"
This script requires the user #{ENV['USER']} to be an Administrator. If you
still want to use this script set your user to be an Administrator in
System Preferences or `su' to a non-root user with Administrator privileges.
EOABORT
unless Dir["#{SF_PREFIX}/System\ San\ Francisco*"].empty?
puts
ohai "It appears San Francisco System is already installed."
puts
warn "If you want to uninstall, run this command:"
warn "sudo rm -rf #{SF_PREFIX}/System\\ San\\ Francisco*"
puts
wait_for_reinstall if STDIN.tty?
system "sudo -v"
ohai "Preparing the old version for update..."
system "/usr/bin/sudo chown #{ENV['USER']}:staff /Library/Fonts/System\\ San\\ Francisco*"
end
if Dir["#{SF_PREFIX}/System\ San\ Francisco*"].empty?
puts
ohai "This script will install:"
puts
puts Dir.glob('*.ttf').join("\n")
wait_for_user if STDIN.tty?
system "/usr/bin/sudo -v"
end
Dir.chdir SF_PREFIX do
ohai "Downloading and installing San Francisco System..."
system "/bin/bash -o pipefail -c '/usr/bin/curl -fsSL #{SF_REPO}/tarball/master | /usr/bin/tar xz -m --strip 1 --include='*System*' --exclude='*Text*''"
ohai "Setting file ownership..."
system "/usr/bin/sudo chown root:wheel /Library/Fonts/System\\ San\\ Francisco*"
ohai "Clearing OS X Font Cache..."
system "sudo /usr/bin/atsutil databases -remove"
ohai "Repairing Disk Permissions (Just to be safe)..."
system "diskutil repairPermissions /"
end
ohai "Installation successful!"
puts
warn "Next steps:"
warn "Restart your computer for the changes to take effect."
warn "Need help? Visit #{SF_REPO}"