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
/
Copy pathroborio_setup.rb
152 lines (124 loc) · 3.23 KB
/
roborio_setup.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
#!/usr/bin/ruby
puts "Enter your robot's number: "
INPUT = gets
TEAM_NUMBER = INPUT.chomp
ROBOT_LOCATION = File.join("roborio-", TEAM_NUMBER, "-frc.local")
# 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
def ohai(*args)
puts "#{Tty.blue}==>#{Tty.bold} #{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.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
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 robotpy-installer
def robotpy_installer
@robotpy_installer ||= if ENV["robotpy-installer"] && File.executable?(ENV["robotpy-installer"])
ENV["robotpy-installer"]
elsif Kernel.system "/usr/bin/which -a robotpy-installer"
"robotpy-installer"
else
exe = `xcrun -find robotpy-installer 2>/dev/null`.chomp
exe if $? && $?.success? && !exe.empty? && File.executable?(exe)
end
@robotpy_installer
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
# 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?
ohai "Unplug ethernet if plugged in!"
wait_for_user
ohai "Grabbing dependencies..."
if !robotpy_installer
system pip3, "-qq", "install", "robotpy-installer"
end
ohai "Downloading RobotPy for RoboRio..."
system robotpy_installer, "download-robotpy"
ohai "Downloading cscore, ctre..."
system robotpy_installer, "download-opkg", "python36-robotpy-cscore", "python36-robotpy-ctre"
puts "Plug in ethernet now!"
wait_for_user
ohai "Installing RobotPy for RoboRio..."
system File.join(robotpy_installer, "install-robotpy", "--robot ", ROBOT_LOCATION)
ohai "Installing cscore, ctre..."
system File.join(robotpy_installer, "install-opkg", "--robot ", ROBOT_LOCATION, " python36-robotpy-cscore", "python36-robotpy-ctre")
ohai "Success! You may unplug ethernet now."