This repository has been archived by the owner on Jul 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.rb
317 lines (273 loc) · 7.72 KB
/
install.rb
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/usr/bin/ruby
# Detecting OS
module OS
def OS.windows?
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
end
def OS.mac?
(/darwin/ =~ RUBY_PLATFORM) != nil
end
def OS.unix?
!OS.windows?
end
def OS.linux?
OS.unix? and not OS.mac?
end
end
# Text output formatting
module Tty
module_function
def blue
bold 34
end
def red
bold 31
end
def reset
escape 0
end
def bold(n = 39)
escape "1;#{n}"
end
def underline
escape "4;39"
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).join(" ")
end
end
# Beautiful printing
def ohai(*args)
puts "#{Tty.blue}==>#{Tty.bold} #{args.shell_s}#{Tty.reset}"
end
# For warning the user
def warn(warning)
puts "#{Tty.red}Warning#{Tty.reset}: #{warning.chomp}"
end
# For running system commands
def system(*args)
abort "Failed during: #{args.shell_s}" unless Kernel.system(*args)
end
# For using sudo
def sudo(*args)
args.unshift("-A") unless ENV["SUDO_ASKPASS"].nil?
ohai "/usr/bin/sudo", *args
system "/usr/bin/sudo", *args
end
def getc
system "/bin/stty raw -echo"
if STDIN.respond_to?(:getbyte)
STDIN.getbyte
else
STDIN.getc
end
ensure
system "/bin/stty -raw echo"
end
# Requires user to hit enter
def wait_for_user
puts
puts "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) || (c == 10)
end
# For finding Atom
def git
@git ||= if ENV["git"] && File.executable?(ENV["git"])
ENV["git"]
elsif Kernel.system "/usr/bin/which -a git"
"git"
else
exe = `xcrun -find git 2>/dev/null`.chomp
exe if $? && $?.success? && !exe.empty? && File.executable?(exe)
end
@git
end
# For finding Atom
def atom
@atom ||= if ENV["atom"] && File.executable?(ENV["atom"])
ENV["atom"]
elsif Kernel.system "/usr/bin/which -a atom"
"atom"
else
exe = `xcrun -find atom 2>/dev/null`.chomp
exe if $? && $?.success? && !exe.empty? && File.executable?(exe)
end
@atom
end
# For finding Homebrew
def brew
@brew ||= if ENV["brew"] && File.executable?(ENV["brew"])
ENV["brew"]
elsif Kernel.system "/usr/bin/which -a brew"
"brew"
else
exe = `xcrun -find brew 2>/dev/null`.chomp
exe if $? && $?.success? && !exe.empty? && File.executable?(exe)
end
@brew
end
# For finding python3
def python3
@python3 ||= if ENV["python3"] && File.executable?(ENV["python3"])
ENV["python3"]
elsif Kernel.system "/usr/bin/which -a python3"
"python3"
else
exe = `xcrun -find python3 2>/dev/null`.chomp
exe if $? && $?.success? && !exe.empty? && File.executable?(exe)
end
@python3
end
# For finding pip3
def pip3
@pip3 ||= if ENV["pip3"] && File.executable?(ENV["pip3"])
ENV["pip3"]
elsif Kernel.system "/usr/bin/which -a pip3"
"pip3"
else
exe = `xcrun -find pip3 2>/dev/null`.chomp
exe if $? && $?.success? && !exe.empty? && File.executable?(exe)
end
@pip3
end
def cloneRobot
system git, "init", "-q"
system git, "config", "remote.origin.url", REPO
system git, "config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*"
system git, "config", "core.autocrlf", "false"
args = git, "fetch", "origin", "master:refs/remotes/origin/master",
"--tags", "--force"
system(*args)
system git, "reset", "--hard", "origin/master"
end
# Invalidate sudo timestamp before exiting (if it wasn't active before).
Kernel.system "/usr/bin/sudo -n -v 2>/dev/null"
at_exit { Kernel.system "/usr/bin/sudo", "-k" } unless $?.success?
Dir.chdir(Dir.home())
if ARGV[0] == "973"
puts "Using 973's 2017-offseason..."
ROBOT_REPOSITORY = File.join(Dir.home(), "/Documents/GitHub/2017-offseason").freeze
REPO = "https://github.com/team973/2017-offseason".freeze
else
warn "No argument supplied/argument not supported, defaulting..."
ROBOT_REPOSITORY = File.join(Dir.home(), "/Documents/GitHub/robotpy-skeleton").freeze
REPO = "https://github.com/team973/robotpy-skeleton".freeze
end
unless ARGV[0] == "travis"
wait_for_user
end
ohai "Creating install directory..."
unless File.exist?(File.join(Dir.home(), "/robotpy-install"))
Dir.mkdir(File.join(Dir.home(), "/robotpy-install"))
end
Dir.chdir(File.join(Dir.home(), "/robotpy-install"))
if OS.mac?
unless brew
ohai "Installing Homebrew..."
system '/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"'
end
unless atom
ohai "Installing Atom for macOS..."
if File.exist?("atom-mac.zip")
puts "Already Downloaded, remove file to redownload."
else
system "/usr/bin/curl -Lo atom-mac.zip https://atom.io/download/mac"
end
system "/usr/bin/unzip -qq atom-mac.zip"
sudo "/bin/cp", "-R", "Atom.app", "/Applications/"
puts "Next step: Open Atom after done and go to Atom>Install Shell Commands"
end
system "/Applications/Atom.app/Contents/Resources/app/apm/node_modules/.bin/apm install $(curl -fsSL https://raw.githubusercontent.com/team973/robotpy-skeleton/master/atompackages)"
elsif OS.linux?
unless atom
ohai "Installing Atom for Debian..."
if File.exist?("atom-amd64.deb")
puts "Already downloaded, remove file to redownload."
else
system "/usr/bin/curl -Lo atom-amd64.deb https://atom.io/download/deb"
end
begin
sudo "/usr/bin/dpkg", "-i", "atom-amd64.deb"
rescue Exception # Shouldn't do this, but too lazy to find actual exception
sudo "/usr/bin/apt", "-f", "-qq", "-y", "install"
end
end
system "/usr/bin/apm install $(curl -fsSL https://raw.githubusercontent.com/team973/robotpy-skeleton/master/atompackages)"
end
ohai "Cloning selected repository..."
unless ARGV[0] == "travis"
unless File.exist?(File.join(Dir.home(), "/Documents/GitHub"))
Dir.mkdir(File.join(Dir.home(), "/Documents/GitHub"))
Dir.chdir(File.join(Dir.home(), "/Documents/GitHub"))
end
unless File.exist?(ROBOT_REPOSITORY)
Dir.mkdir(ROBOT_REPOSITORY)
end
Dir.chdir(ROBOT_REPOSITORY) do
if git
cloneRobot
else
ohai "Must install git first..."
if OS.mac?
system brew, "install", "git"
cloneRobot
elsif OS.linux?
sudo "/usr/bin/apt", "-qq", "install", "-y", "git"
cloneRobot
end
end
end
end
unless python3
ohai "Installing Python3..."
if OS.mac?
if ARGV[0] == "travis"
system "HOMEBREW_NO_AUTO_UPDATE=1 brew install python3" # Takes a long time to update on travis
else
system brew, "install", "python3"
end
elsif OS.linux?
sudo "/usr/bin/apt", "-qq", "install", "-y", "python3", "python3-dev"
end
end
unless pip3
ohai "Installing pip3..."
if OS.mac?
system brew, "install", "python3"
elsif OS.linux?
sudo "/usr/bin/apt", "-qq", "install", "-y", "python3-pip"
end
end
ohai "Installing Python packages...."
begin
system pip3, "-qq", "install","pyfrc", "coverage", "robotpy-installer"
rescue Exception # Shouldn't do this, but too lazy to find actual exception
system pip3, "-qq", "install", "--user" "pyfrc", "coverage", "robotpy-installer"
end
ohai "Dependencies Installed"
ohai "Testing RobotPy..."
if ARGV[0] == "travis"
Dir.chdir(File.join(Dir.home(), "build/Team973/robotpy-skeleton/src/"))
else
if ARGV[0] == "973"
Dir.chdir(File.join(ROBOT_REPOSITORY, "/wood/src/"))
else
Dir.chdir(File.join(ROBOT_REPOSITORY, "/src/"))
end
end
system python3, "robot.py", "test"
ohai "Success! We are done"
ohai "ONLY HIT ENTER IF YOU WANT TO SETUP ROBORIO! Otherwise, hit ^C."
unless ARGV[0] == "travis"
wait_for_user
system '/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/team973/robotpy-skeleton/master/roborio_setup.rb)"'
end