SHOW:
|
|
- or go back to the newest paste.
1 | -----BigReactor Control Installer | |
2 | - | -----by jaranvil aka jared314 |
2 | + | -----by costantino03 |
3 | ||
4 | -----feel free to use and/or modify this code | |
5 | ----------------------------------------------- | |
6 | ||
7 | ||
8 | --Run this program to install or update either reactor or turbine control programs. | |
9 | ||
10 | ||
11 | -----------------PASTEBINs-------------------------- | |
12 | - | installer = "p4zeq7Ma" |
12 | + | installer = "Xr3K0mdN" |
13 | - | reactor_control_pastebin = "RCPEHmxs" |
13 | + | reactor_control_pastebin = "5PhmpU70" |
14 | - | turbine_control_pastebin = "5B8h94V4" |
14 | + | turbine_control_pastebin = "GxWEDb85" |
15 | ||
16 | - | reactor_startup = "cZUH7y6k" |
16 | + | reactor_startup = "zVe8Wr4g" |
17 | - | turbine_startup = "h0jmye6t" |
17 | + | turbine_startup = "Krb6varn" |
18 | ||
19 | - | reactor_update_check = "MkF2QQjH" |
19 | + | reactor_update_check = "Mwni28F4" |
20 | - | turbine_update_check = "QP3qrzNu" |
20 | + | turbine_update_check = "fxSWTtxK" |
21 | ||
22 | - | dev_installer = "mCPQQ3Ge" |
22 | + | dev_installer = "Xr3K0mdN" |
23 | - | dev_reactor_control_pastebin = "eYwBw9a3" |
23 | + | dev_reactor_control_pastebin = "SN6VcANf" |
24 | - | dev_turbine_control_pastebin = "kJHeCx0Q" |
24 | + | dev_turbine_control_pastebin = "GxWEDb85" |
25 | --------------------------------------------- | |
26 | ||
27 | local reactor | |
28 | local turbine | |
29 | term.clear() | |
30 | -------------------FORMATTING------------------------------- | |
31 | ||
32 | function draw_text_term(x, y, text, text_color, bg_color) | |
33 | term.setTextColor(text_color) | |
34 | term.setBackgroundColor(bg_color) | |
35 | term.setCursorPos(x,y) | |
36 | write(text) | |
37 | end | |
38 | ||
39 | function draw_line_term(x, y, length, color) | |
40 | term.setBackgroundColor(color) | |
41 | term.setCursorPos(x,y) | |
42 | term.write(string.rep(" ", length)) | |
43 | end | |
44 | ||
45 | function progress_bar_term(x, y, length, minVal, maxVal, bar_color, bg_color) | |
46 | draw_line_term(x, y, length, bg_color) --backgoround bar | |
47 | local barSize = math.floor((minVal/maxVal) * length) | |
48 | draw_line_term(x, y, barSize, bar_color) --progress so far | |
49 | end | |
50 | ||
51 | function menu_bars() | |
52 | ||
53 | draw_line_term(1, 1, 55, colors.blue) | |
54 | draw_text_term(10, 1, "BigReactors Control Installer", colors.white, colors.blue) | |
55 | ||
56 | draw_line_term(1, 19, 55, colors.blue) | |
57 | - | draw_text_term(10, 19, "by jaranvil aka jared314", colors.white, colors.blue) |
57 | + | draw_text_term(10, 19, "by costantino03", colors.white, colors.blue) |
58 | end | |
59 | ||
60 | -------------------------------------------------------------- | |
61 | ||
62 | ||
63 | ||
64 | function install(program, pastebin) | |
65 | term.clear() | |
66 | menu_bars() | |
67 | ||
68 | draw_text_term(1, 3, "Installing "..program.."...", colors.yellow, colors.black) | |
69 | term.setCursorPos(1,5) | |
70 | term.setTextColor(colors.white) | |
71 | sleep(0.5) | |
72 | ||
73 | -----------------Install control program--------------- | |
74 | ||
75 | ||
76 | --delete any old backups | |
77 | if fs.exists(program.."_old") then | |
78 | fs.delete(program.."_old") | |
79 | end | |
80 | ||
81 | --remove old configs | |
82 | if fs.exists("config.txt") then | |
83 | fs.delete("config.txt") | |
84 | end | |
85 | ||
86 | --backup current program | |
87 | if fs.exists(program) then | |
88 | fs.copy(program, program.."_old") | |
89 | fs.delete(program) | |
90 | end | |
91 | ||
92 | --remove program and fetch new copy | |
93 | ||
94 | shell.run("pastebin get "..pastebin.." "..program) | |
95 | ||
96 | sleep(0.5) | |
97 | ||
98 | ------------------Install startup script------------- | |
99 | ||
100 | term.setCursorPos(1,8) | |
101 | ||
102 | --delete any old backups | |
103 | if fs.exists("startup_old") then | |
104 | fs.delete("startup_old") | |
105 | end | |
106 | ||
107 | --backup current program | |
108 | if fs.exists("startup") then | |
109 | fs.copy("startup", "startup_old") | |
110 | fs.delete("startup") | |
111 | end | |
112 | ||
113 | ||
114 | if program == "reactor_control" then | |
115 | shell.run("pastebin get "..reactor_startup.." startup") | |
116 | else if program == "turbine_control" then | |
117 | shell.run("pastebin get "..turbine_startup.." startup") | |
118 | end | |
119 | end | |
120 | ||
121 | if fs.exists(program) then | |
122 | draw_text_term(1, 11, "Success!", colors.lime, colors.black) | |
123 | draw_text_term(1, 12, "Press Enter to reboot...", colors.gray, colors.black) | |
124 | wait = read() | |
125 | shell.run("reboot") | |
126 | else | |
127 | draw_text_term(1, 11, "Error installing file.", colors.red, colors.black) | |
128 | sleep(0.1) | |
129 | draw_text_term(1, 12, "Restoring old file...", colors.gray, colors.black) | |
130 | sleep(0.1) | |
131 | fs.copy(program.."_old", program) | |
132 | fs.delete(program.."_old") | |
133 | ||
134 | draw_text_term(1, 14, "Press Enter to continue...", colors.gray, colors.black) | |
135 | wait = read() | |
136 | start() | |
137 | end | |
138 | end | |
139 | ||
140 | - | -- peripheral searching thanks to /u/kla_sch |
140 | + | -- |
141 | - | -- http://pastebin.com/gTEBHv3D |
141 | + | |
142 | local names = peripheral.getNames() | |
143 | local i, name | |
144 | for i, name in pairs(names) do | |
145 | if peripheral.getType(name) == "BigReactors-Reactor" then | |
146 | return peripheral.wrap(name) | |
147 | else | |
148 | --return null | |
149 | end | |
150 | end | |
151 | end | |
152 | ||
153 | function turbineSearch() | |
154 | local names = peripheral.getNames() | |
155 | local i, name | |
156 | for i, name in pairs(names) do | |
157 | if peripheral.getType(name) == "BigReactors-Turbine" then | |
158 | return peripheral.wrap(name) | |
159 | else | |
160 | --return null | |
161 | end | |
162 | end | |
163 | end | |
164 | ||
165 | function selectProgram() | |
166 | term.clear() | |
167 | menu_bars() | |
168 | draw_text_term(1, 4, "What would you like to install or update?", colors.yellow, colors.black) | |
169 | draw_text_term(3, 6, "1 - Reactor Control", colors.white, colors.black) | |
170 | draw_text_term(3, 7, "2 - Turbine Control", colors.white, colors.black) | |
171 | draw_text_term(1, 9, "Enter 1 or 2:", colors.yellow, colors.black) | |
172 | ||
173 | term.setCursorPos(1,10) | |
174 | term.setTextColor(colors.white) | |
175 | input = read() | |
176 | ||
177 | if input == "1" then | |
178 | install("reactor_control", reactor_control_pastebin) | |
179 | else if input == "2" then | |
180 | install("turbine_control", turbine_control_pastebin) | |
181 | else if input == "3" then | |
182 | - | else if input == "dev1" then |
182 | + | |
183 | else if input == "dev2" then | |
184 | install("turbine_control", dev_turbine_control_pastebin) | |
185 | else | |
186 | draw_text_term(1, 12, "please enter a '1' or '2'.", colors.red, colors.black) | |
187 | sleep(1) | |
188 | start() | |
189 | end | |
190 | end | |
191 | end | |
192 | end | |
193 | end | |
194 | ||
195 | function start() | |
196 | term.clear() | |
197 | menu_bars() | |
198 | ||
199 | if fs.exists("config.txt") then | |
200 | ||
201 | if fs.exists("reactor_control") then | |
202 | draw_text_term(2, 3, "Current Program:", colors.white, colors.black) | |
203 | draw_text_term(2, 4, "Reactor Control", colors.lime, colors.black) | |
204 | draw_text_term(1, 6, "Do you want to update this program? (y/n)", colors.white, colors.black) | |
205 | draw_text_term(1, 7, "This will delete the current program and any saved settings", colors.gray, colors.black) | |
206 | term.setCursorPos(1,9) | |
207 | term.setTextColor(colors.white) | |
208 | input = read() | |
209 | if input == "y" then | |
210 | install("reactor_control", reactor_control_pastebin) | |
211 | else if input == "n" then | |
212 | selectProgram() | |
213 | else | |
214 | draw_text_term(1, 10, "please enter 'y' or 'n'.", colors.red, colors.black) | |
215 | sleep(1) | |
216 | start() | |
217 | end | |
218 | end | |
219 | ||
220 | else if fs.exists("turbine_control") then | |
221 | draw_text_term(2, 3, "Current Program:", colors.white, colors.black) | |
222 | draw_text_term(2, 4, "Turbine Control", colors.lime, colors.black) | |
223 | draw_text_term(1, 6, "Do you want to update this program? (y/n)", colors.white, colors.black) | |
224 | draw_text_term(1, 7, "This will delete the current program and any saved settings", colors.gray, colors.black) | |
225 | term.setCursorPos(1,9) | |
226 | term.setTextColor(colors.white) | |
227 | input = read() | |
228 | if input == "y" then | |
229 | install("turbine_control", turbine_control_pastebin) | |
230 | else if input == "n" then | |
231 | selectProgram() | |
232 | else | |
233 | draw_text_term(1, 10, "please enter 'y' or 'n'.", colors.red, colors.black) | |
234 | sleep(1) | |
235 | start() | |
236 | end | |
237 | end | |
238 | ||
239 | end | |
240 | end | |
241 | end | |
242 | ||
243 | selectProgram() | |
244 | ||
245 | ||
246 | end | |
247 | ||
248 | start() |