Advertisement
ee_ingo

BigReactors Installer

Feb 22nd, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.10 KB | None | 0 0
  1. -----BigReactor Control Installer
  2. -----by jaranvil aka jared314 fix for myFTB by ee_ingo
  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 = "VHJv0kbL"
  13. reactor_control_pastebin = "sTQCiyCL"
  14. turbine_control_pastebin = "nvjJLfYk"
  15.  
  16. reactor_startup = "3WCSApHD"
  17. turbine_startup = "LTtEXQE9"
  18.  
  19. reactor_update_check = "ASHccTUi"
  20. turbine_update_check = "HtnUAecG"
  21.  
  22. dev_installer = "VHJv0kbL"
  23. dev_reactor_control_pastebin = "YXYEpBbV"
  24. dev_turbine_control_pastebin = "nvjJLfYk"
  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(1, 19, "by jaranvil aka jared314 fix for myFTB by ee_ingo", 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(3, 8, "3 - 2 or more Reactor Control", colors.white, colors.black)
  173.   draw_text_term(1, 9, "Enter 1, 2 or 3:", 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 == "3" 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' '2' 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.  
  251.     start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement