Advertisement
Temar

Untitled

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