Advertisement
Aidan428

BigReactor Control Installer

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