-
Notifications
You must be signed in to change notification settings - Fork 4
/
install
215 lines (175 loc) · 6.68 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
# This is a installer for the command line tool arcanist.
# This installer was ONLY written for mac os x in mind. Use at your own risk if you choose to try and install
# this on a linux distro.
#
# Give credit where credit is due -- https://raw.github.com/mxcl/homebrew/go
# This script was heavily based on the awesome homebrew installer
# This script installs to /usr/local only. To install elsewhere you will have to manually do it yourself!
# --- Manual Install to /usr/local ---
# mkdir /usr/local/phabricator
# chmod g+rwx /usr/local/phabricator
# chgrp admin /usr/local/phabricator
# cd /usr/local/phabricator
# git clone https://github.com/facebook/arcanist.git
# git clone https://github.com/facebook/libphutil.git
# ln -s /usr/local/phabricator/arcanist/bin/arc /usr/local/bin/arc
# --- Manual Install to home directory ---
# mkdir ~/phabricator
# cd ~/phabricator
# git clone https://github.com/facebook/arcanist.git
# git clone https://github.com/facebook/libphutil.git
# ln -s ~/phabricator/arcanist/bin/arc /usr/local/bin/arc
ARCANIST_INSTALL_LOCATION = "/usr/local/phabricator"
USR_LOCAL_BIN = "/usr/local/bin"
module Tty extend self
def blue; bold 34; end
def white; bold 39; end
def red; underline 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}Warning#{Tty.reset}: #{warning.chomp}"
end
def system *args
abort "Failed during: #{args.shell_s}" unless Kernel.system *args
end
def sudo *args
args = if args.length > 1
args.unshift "/usr/bin/sudo"
else
"/usr/bin/sudo #{args.first}"
end
ohai *args
system *args
end
def getc # NOTE only tested on OS X
system "/bin/stty raw -echo"
if RUBY_VERSION >= '1.8.7'
STDIN.getbyte
else
STDIN.getc
end
ensure
system "/bin/stty -raw echo"
end
def macos_version
@macos_version ||= formatted_macos_version
end
def formatted_macos_version
version = /(\d+)\.(\d+)\.(\d+)?/.match(`/usr/bin/sw_vers -productVersion`).captures
{
major: version[0].to_i || 0,
minor: version[1].to_i || 0,
patch: version[2].to_i || 0
}
end
def file_exists file_path
File.exists?(file_path) || File.symlink?(file_path)
end
### Validation functions ###
# Leaving this here even though it should work regardless of version number.
# I have no way to test Mac OS versions before 10.6 to verify, comment out the following line at your own risk.
def current_os?
abort "MacOS too old, upgrade to at least 10.6" if macos_version[:major] < 10 && macos_version[:minor] < 5
end
def not_root?
abort "Don't run this as root!" if Process.uid == 0
end
def git_installed?
abort <<-EOABORT if `which git`.strip == ""
Git does not appear to be installed on this machine. Please install it before tyring to install arc.
Installing Git:
If you have homebrew installed just type
'brew install git'
Othwerise use one of the following links
http://git-scm.com/downloads/
http://code.google.com/p/git-osx-installer/
EOABORT
end
def user_admin?
abort <<-EOABORT unless `groups`.split.include? "admin"
This script requires the user #{ENV['USER']} to be an Administrator. Theoretically you're a developer
installing ARC on your machine so this shouldn't be a problem. Just make sure you're on the right user account
before re-running the script
EOABORT
end
def arcanist_already_installed?
abort <<-EOABORT if file_exists ARCANIST_INSTALL_LOCATION
#{ARCANIST_INSTALL_LOCATION} already exists! Looks like you've already installed this software.
If you wish to proceed with installation manually delete #{ARCANIST_INSTALL_LOCATION}.
Type 'arc upgrade' to upgrade your current installation instead of reinstalling.
EOABORT
end
def arcanist_already_symlinked?
abort <<-EOABORT if file_exists "/usr/local/bin/arc"
It seem's you already have a piece of software installed called arc in /usr/local/bin. If this is the case you've
either installed arcanist previously or have a conflicting piece of software installed with the same name. You
should either uninstall the conflicting arc software or execute a manual install.
Conflict: /usr/local/bin/arc
EOABORT
end
####################################################################### script
# Do some checks, abort if any failures occur
current_os?
not_root?
git_installed?
user_admin?
arcanist_already_installed?
arcanist_already_symlinked?
ohai "This script will install:"
puts "/usr/local/bin" unless file_exists "/usr/local/bin"
puts "/usr/local/bin/arc"
puts "/usr/local/phabricator/"
puts "/usr/local/phabricator/arcanist/..."
puts "/usr/local/phabricator/libphutil/..."
ohai "The following directories will be made group writable and their group set to #{Tty.underline 39}admin#{Tty.reset}:"
puts "/usr/local/phabricator"
puts "/usr/local/phabricator/arcanist/..."
puts "/usr/local/phabricator/libphutil/..."
if STDIN.tty?
puts
puts "Press enter to continue"
c = getc
# we test for \r and \n because some stuff does \r instead
abort unless c == 13 or c == 10
end
sudo "/bin/mkdir /usr/local/bin" unless file_exists "/usr/local/bin"
if File.directory? "/usr/local"
sudo "/bin/mkdir #{ARCANIST_INSTALL_LOCATION}" unless file_exists ARCANIST_INSTALL_LOCATION
# The reason we do this it to allow upgrading of arcanist through 'arc upgrade' without requiring sudo
sudo "/bin/chmod", "g+rwx", ARCANIST_INSTALL_LOCATION
sudo "/usr/bin/chgrp", "admin", ARCANIST_INSTALL_LOCATION
end
Dir.chdir ARCANIST_INSTALL_LOCATION do
ohai "Downloading and Installing Arcanist..."
system "git clone https://github.com/facebook/arcanist.git"
ohai "Downloading and Installing libphutil..."
system "git clone https://github.com/facebook/libphutil.git"
ohai "Linking /usr/local/phabricator/arcanist/bin/arc to /usr/local/bin/arc..."
sudo "/bin/ln -s #{ARCANIST_INSTALL_LOCATION}/arcanist/bin/arc #{USR_LOCAL_BIN}/arc"
end
warn "/usr/local/bin is not in your PATH. Arcanist will not work unless you place /usr/local/bin in your PATH" unless ENV['PATH'].split(':').include? '/usr/local/bin'
ohai "Caveats"
puts <<-EOS
Arcanist comes with a bash completion script. To include it source the following file in your bash_profile/bashrc file
source #{ARCANIST_INSTALL_LOCATION}/arcanist/resources/shell/bash-completion
EOS
ohai "Installation successful!"
puts "To confirm installation please type:"
puts " arc upgrade"
puts " arc help"
puts "If neither command errors out the install was *truly* successful"