Advertisement
eliminat

Big Reactors Control Installer

Mar 13th, 2015
719
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. -----BigReactor Control Installer
  2. -----by jaranvil aka jared314
  3.  
  4. -----Original at http://pastebin.com/p4zeq7Ma
  5.  
  6. -----feel free to use and/or mondify this code
  7. -----------------------------------------------
  8.  
  9.  
  10. --Run this program to install either reactor or turbine control programs.
  11.  
  12.  
  13. -----------------PASTEBINs--------------------------
  14. installer = "p4zeq7Ma"
  15. reactor_control_pastebin = "RCPEHmxs"
  16. turbine_control_pastebin = "5B8h94V4"
  17.  
  18. reactor_startup = "cZUH7y6k"
  19. turbine_startup = "h0jmye6t"
  20.  
  21. reactor_update_check = "MkF2QQjH"
  22. turbine_update_check = "QP3qrzNu"
  23.  
  24. dev_installer = "mCPQQ3Ge"
  25. dev_reactor_control_pastebin = "eYwBw9a3"
  26. dev_turbine_control_pastebin = "kJHeCx0Q"
  27. ---------------------------------------------
  28.  
  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. --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.  
  136. ---------------------------------------------------------------
  137.  
  138. function start()
  139. term.clear()
  140. menu_bars()
  141.  
  142. draw_text_term(1, 4, "What would you like to install or update?", colors.yellow, colors.black)
  143. draw_text_term(3, 6, "1 - Reactor Control", colors.white, colors.black)
  144. draw_text_term(3, 7, "2 - Turbine Control", colors.white, colors.black)
  145. draw_text_term(1, 9, "Enter 1 or 2:", colors.yellow, colors.black)
  146.  
  147. term.setCursorPos(1,10)
  148. term.setTextColor(colors.white)
  149. input = read()
  150.  
  151. if input == "1" then
  152. install("reactor_control", reactor_control_pastebin)
  153. else if input == "2" then
  154. install("turbine_control", turbine_control_pastebin)
  155. else if input == "dev1" then
  156. install("reactor_control", dev_reactor_control_pastebin)
  157. else if input == "dev2" then
  158. install("turbine_control", dev_turbine_control_pastebin)
  159. else
  160. draw_text_term(1, 12, "please enter a '1' or '2'.", colors.red, colors.black)
  161. sleep(1)
  162. start()
  163. end
  164. end
  165. end
  166. end
  167.  
  168. end
  169.  
  170. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement