View difference between Paste ID: nZyvmpYN and p4zeq7Ma
SHOW: | | - or go back to the newest paste.
1
-----BigReactor Control Installer
2
-----by jaranvil aka jared314
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"
13
reactor_control_pastebin = "RCPEHmxs"
14
turbine_control_pastebin = "5B8h94V4"
15
16
reactor_startup = "cZUH7y6k"
17
turbine_startup = "h0jmye6t"
18
19
reactor_update_check = "MkF2QQjH"
20
turbine_update_check = "QP3qrzNu"
21
22
dev_installer = "mCPQQ3Ge"
23
dev_reactor_control_pastebin = "eYwBw9a3"
24
dev_turbine_control_pastebin = "kJHeCx0Q"
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)
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
141
-- http://pastebin.com/gTEBHv3D
142
function reactorSearch()
143
   local names = peripheral.getNames()
144
   local i, name
145
   for i, name in pairs(names) do
146
      if peripheral.getType(name) == "BigReactors-Reactor" then
147
         return peripheral.wrap(name)
148
      else
149
         --return null
150
      end
151
   end
152
end
153
154
function turbineSearch()
155
   local names = peripheral.getNames()
156
   local i, name
157
   for i, name in pairs(names) do
158
      if peripheral.getType(name) == "BigReactors-Turbine" then
159
         return peripheral.wrap(name)
160
      else
161
         --return null
162
      end
163
   end
164
end
165
166
function selectProgram()
167
  term.clear()
168
  menu_bars()
169
  draw_text_term(1, 4, "What would you like to install or update?", colors.yellow, colors.black)
170
  draw_text_term(3, 6, "1 - Reactor Control", colors.white, colors.black)
171
  draw_text_term(3, 7, "2 - Turbine Control", colors.white, colors.black)
172
  draw_text_term(1, 9, "Enter 1 or 2:", colors.yellow, colors.black)
173
174
  term.setCursorPos(1,10)
175
  term.setTextColor(colors.white)
176
  input = read()
177
178
  if input == "1" then
179
    install("reactor_control", reactor_control_pastebin)
180
  else if input == "2" then
181
    install("turbine_control", turbine_control_pastebin)
182
  else if input == "dev1" then
183
    install("reactor_control", dev_reactor_control_pastebin)
184
  else if input == "dev2" then
185
    install("turbine_control", dev_turbine_control_pastebin)
186
  else
187
    draw_text_term(1, 12, "please enter a '1' or '2'.", colors.red, colors.black)
188
    sleep(1)
189
    start()
190
  end
191
  end
192
  end
193
  end
194
end
195
196
function start()
197
  term.clear()
198
  menu_bars()
199
  
200
  if fs.exists("config.txt") then
201
  
202
    if fs.exists("reactor_control") then
203
      draw_text_term(2, 3, "Current Program:", colors.white, colors.black)
204
      draw_text_term(2, 4, "Reactor Control", colors.lime, colors.black)
205
      draw_text_term(1, 6, "Do you want to update this program? (y/n)", colors.white, colors.black)
206
      draw_text_term(1, 7, "This will delete the current program and any saved settings", colors.gray, colors.black)
207
      term.setCursorPos(1,9)
208
      term.setTextColor(colors.white)
209
      input = read()
210
      if input == "y" then
211
        install("reactor_control", reactor_control_pastebin)
212
      else if input == "n" then
213
        selectProgram()
214
      else
215
        draw_text_term(1, 10, "please enter 'y' or 'n'.", colors.red, colors.black)
216
        sleep(1)
217
        start()
218
      end
219
      end
220
      
221
    else if fs.exists("turbine_control") then
222
      draw_text_term(2, 3, "Current Program:", colors.white, colors.black)
223
      draw_text_term(2, 4, "Turbine Control", colors.lime, colors.black)
224
      draw_text_term(1, 6, "Do you want to update this program? (y/n)", colors.white, colors.black)
225
      draw_text_term(1, 7, "This will delete the current program and any saved settings", colors.gray, colors.black)
226
      term.setCursorPos(1,9)
227
      term.setTextColor(colors.white)
228
      input = read()
229
      if input == "y" then
230
        install("turbine_control", turbine_control_pastebin)
231
      else if input == "n" then
232
        selectProgram()
233
      else
234
        draw_text_term(1, 10, "please enter 'y' or 'n'.", colors.red, colors.black)
235
        sleep(1)
236
        start()
237
      end
238
      end
239
    
240
    end
241
    end
242
  end
243
  
244
  selectProgram()
245
 
246
247
end
248
249
start()