Advertisement
Sparkybearbomb

Bigreactors monitor Installer

Mar 16th, 2016 (edited)
1,684
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.67 KB | None | 0 0
  1. -----BigReactor Control Installer
  2. -----By SparkyBearBomb
  3. -----Original by jaranvil aka jared314
  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 = "ELJptBRk"
  14. reactor_control_pastebin = "acdYR7c2"
  15. legacy_reactor_control_pastebin = "JA3EMG5k"
  16. turbine_control_pastebin = "5B8h94V4"
  17. beta_reactor_control_pastebin = "4waV2EZN"
  18.  
  19. reactor_control_updater = "Vk0t2i9L"
  20.  
  21. reactor_startup = "GS6skfs8"
  22. legacy_reactor_startup = "aSBDbNWs"
  23. beta_reactor_startup = "nzk1F6zL"
  24. turbine_startup = "v1n8TPXg"
  25.  
  26. reactor_update_check = "KWdzfSbG"
  27. turbine_update_check = "QP3qrzNu"
  28.  
  29. dev_installer = "mCPQQ3Ge"
  30. dev_reactor_control_pastebin = "eYwBw9a3"
  31. dev_turbine_control_pastebin = "kJHeCx0Q"
  32. ---------------------------------------------
  33.  
  34. local reactor
  35. local turbine
  36. term.clear()
  37. -------------------FORMATTING-------------------------------
  38.  
  39. function draw_text_term(x, y, text, text_color, bg_color)
  40.   term.setTextColor(text_color)
  41.   term.setBackgroundColor(bg_color)
  42.   term.setCursorPos(x,y)
  43.   write(text)
  44. end
  45.  
  46. function draw_line_term(x, y, length, color)
  47.     term.setBackgroundColor(color)
  48.     term.setCursorPos(x,y)
  49.     term.write(string.rep(" ", length))
  50. end
  51.  
  52. function progress_bar_term(x, y, length, minVal, maxVal, bar_color, bg_color)
  53.   draw_line_term(x, y, length, bg_color) --backgoround bar
  54.   local barSize = math.floor((minVal/maxVal) * length)
  55.   draw_line_term(x, y, barSize, bar_color)  --progress so far
  56. end
  57.  
  58. function menu_bars()
  59.  
  60.   draw_line_term(1, 1, 55, colors.blue)
  61.   draw_text_term(10, 1, "BigReactors Control Installer", colors.white, colors.blue)
  62.  
  63.   draw_line_term(1, 19, 55, colors.blue)
  64.   draw_text_term(10, 19, "by SparkyBearBomb", colors.white, colors.blue)
  65. end
  66.  
  67. --------------------------------------------------------------
  68.  
  69.  
  70.  
  71. function install(program, pastebin)
  72.   term.clear()
  73.   menu_bars()
  74.  
  75.   draw_text_term(1, 3, "Installing "..program.."...", colors.yellow, colors.black)
  76.   term.setCursorPos(1,5)
  77.   term.setTextColor(colors.white)
  78.   sleep(0.5)
  79.  
  80.   -----------------Install control program---------------
  81.  
  82.  
  83.   --delete any old backups
  84.   if fs.exists(program.."_old") then
  85.     fs.delete(program.."_old")
  86.   end
  87.  
  88.   --remove old configs
  89.   if fs.exists("config.txt") then
  90.     fs.delete("config.txt")
  91.   end
  92.  
  93.  
  94.   --remove old update checker
  95.   if fs.exists("reactor_control_updater") then
  96.     fs.delete("reactor_control_updater")
  97.   end
  98.  
  99.   --install new update checker
  100.   if program == "reactor_control" then
  101.     shell.run("pastebin get "..reactor_control_updater.." reactor_control_updater")
  102.   else if program == "legacy_reactor_control" then
  103.     shell.run("pastebin get "..reactor_control_updater.." reactor_control_updater")
  104.   else if program == "beta_reactor_control" then
  105.     shell.run("pastebin get "..reactor_control_updater.." reactor_control_updater")
  106.   end
  107.   end
  108.   end
  109.  
  110.   --backup current program
  111.   if fs.exists(program) then
  112.     fs.copy(program, program.."_old")
  113.     fs.delete(program)
  114.   end
  115.  
  116.   --remove program and fetch new copy
  117.  
  118.   shell.run("pastebin get "..pastebin.." "..program)
  119.  
  120.   sleep(0.5)
  121.  
  122.   ------------------Install startup script-------------
  123.  
  124.   term.setCursorPos(1,8)
  125.  
  126.   --delete any old backups
  127.   if fs.exists("startup_old") then
  128.     fs.delete("startup_old")
  129.   end
  130.  
  131.   --backup current program
  132.   if fs.exists("startup") then
  133.     fs.copy("startup", "startup_old")
  134.     fs.delete("startup")
  135.   end
  136.  
  137.  
  138.   if program == "reactor_control" then
  139.     shell.run("pastebin get "..reactor_startup.." startup")
  140.   else if program == "legacy_reactor_control" then
  141.     shell.run("pastebin get "..legacy_reactor_startup.." startup")
  142.   else if program == "beta_reactor_control" then
  143.     shell.run("pastebin get "..beta_reactor_startup.." startup")
  144.   else if program == "turbine_control" then
  145.     shell.run("pastebin get "..turbine_startup.." startup")
  146.   end
  147.   end
  148.   end
  149.   end
  150.  
  151.   if fs.exists(program) then
  152.     draw_text_term(1, 11, "Success!", colors.lime, colors.black)
  153.     draw_text_term(1, 12, "Press Enter to reboot...", colors.gray, colors.black)
  154.     wait = read()
  155.     shell.run("reboot")
  156.   else
  157.     draw_text_term(1, 11, "Error installing file.", colors.red, colors.black)
  158.     sleep(0.1)
  159.     draw_text_term(1, 12, "Restoring old file...", colors.gray, colors.black)
  160.     sleep(0.1)
  161.     fs.copy(program.."_old", program)
  162.     fs.delete(program.."_old")
  163.  
  164.     draw_text_term(1, 14, "Press Enter to continue...", colors.gray, colors.black)
  165.     wait = read()
  166.     start()
  167.   end
  168. end
  169.  
  170. -- peripheral searching thanks to /u/kla_sch
  171. -- http://pastebin.com/gTEBHv3D
  172.  
  173. function reactorSearch()
  174.    local names = peripheral.getNames()
  175.    local i, name
  176.    for i, name in pairs(names) do
  177.       if peripheral.getType(name) == "bigger-reactor" then
  178.          return peripheral.wrap(name)
  179.       else
  180.          --return null
  181.       end
  182.    end
  183. end
  184.  
  185. function legacyreactorSearch()
  186.    local names = peripheral.getNames()
  187.    local i, name
  188.    for i, name in pairs(names) do
  189.       if peripheral.getType(name) == "BigReactors-Reactor" then
  190.          return peripheral.wrap(name)
  191.       else
  192.          --return null
  193.       end
  194.    end
  195. end
  196.  
  197. function betareactorSearch()
  198.     local names = peripheral.getNames()
  199.     local i, name
  200.     for i, name in pairs(names) do
  201.        if peripheral.getType(name) == "BiggerReactors_Reactor" then
  202.           return peripheral.wrap(name)
  203.        else
  204.           --return null
  205.        end
  206.     end
  207.  end
  208.  
  209. function turbineSearch()
  210.    local names = peripheral.getNames()
  211.    local i, name
  212.    for i, name in pairs(names) do
  213.       if peripheral.getType(name) == "BigReactors-Turbine" then
  214.          return peripheral.wrap(name)
  215.       else
  216.          --return null
  217.       end
  218.    end
  219. end
  220.  
  221. function selectProgram()
  222.   term.clear()
  223.   menu_bars()
  224.   draw_text_term(1, 4, "What would you like to install or update?", colors.yellow, colors.black)
  225.   draw_text_term(3, 6, "1 - Reactor Control - Ver 1.16.4", colors.white, colors.black)
  226.   draw_text_term(3, 7, "2 - Reactor Control - Legacy Ver 1.7.10", colors.white, colors.black)
  227.   draw_text_term(3, 8, "3 - Reactor Control - Beta 1.16.5 - ATM6", colors.white, colors.black)
  228.   draw_text_term(3, 9, "4 - Turbine Control - Legacy", colors.white, colors.black)
  229.   draw_text_term(1, 11, "Enter 1 - 3:", colors.yellow, colors.black)
  230.  
  231.   term.setCursorPos(1,12)
  232.   term.setTextColor(colors.white)
  233.   input = read()
  234.  
  235.   if input == "1" then
  236.     install("reactor_control", reactor_control_pastebin)
  237.   else if input == "2" then
  238.     install("legacy_reactor_control", legacy_reactor_control_pastebin)
  239.   else if input == "3" then
  240.     install("beta_reactor_control", beta_reactor_control_pastebin)
  241.   else if input == "4" then
  242.     install("turbine_control", turbine_control_pastebin)
  243.   else if input == "dev1" then
  244.     install("reactor_control", dev_reactor_control_pastebin)
  245.   else if input == "dev2" then
  246.     install("turbine_control", dev_turbine_control_pastebin)
  247.   else
  248.     draw_text_term(1, 12, "please enter a 1 - 4.", colors.red, colors.black)
  249.     sleep(1)
  250.     start()
  251.   end
  252.   end
  253.   end
  254.   end
  255.   end
  256.   end
  257. end
  258.  
  259. function start()
  260.   term.clear()
  261.   menu_bars()
  262.  
  263.   if fs.exists("config.txt") then
  264.  
  265.     if fs.exists("reactor_control") then
  266.       draw_text_term(2, 3, "Current Program:", colors.white, colors.black)
  267.       draw_text_term(2, 4, "Reactor Control", colors.lime, colors.black)
  268.       draw_text_term(1, 6, "Do you want to update this program? (y/n)", colors.white, colors.black)
  269.       draw_text_term(1, 7, "This will delete the current program and any saved settings", colors.gray,      colors.black)
  270.       term.setCursorPos(1,9)
  271.       term.setTextColor(colors.white)
  272.       input = read()
  273.       if input == "y" then
  274.         install("reactor_control", reactor_control_pastebin)
  275.       else if input == "n" then
  276.         selectProgram()
  277.       else
  278.         draw_text_term(1, 10, "please enter 'y' or 'n'.", colors.red, colors.black)
  279.         sleep(1)
  280.         start()
  281.       end
  282.       end
  283.  
  284.     else if fs.exists("legacy_reactor_control") then
  285.       draw_text_term(2, 3, "Current Program:", colors.white, colors.black)
  286.       draw_text_term(2, 4, "Legacy Reactor Control", colors.lime, colors.black)
  287.       draw_text_term(1, 6, "Do you want to update this program? (y/n)", colors.white, colors.black)
  288.       draw_text_term(1, 7, "This will delete the current program and any saved settings", colors.gray,      colors.black)
  289.       term.setCursorPos(1,9)
  290.       term.setTextColor(colors.white)
  291.       input = read()
  292.       if input == "y" then
  293.         install("legacy_reactor_control", legacy_reactor_control_pastebin)
  294.       else if input == "n" then
  295.         selectProgram()
  296.       else
  297.         draw_text_term(1, 10, "please enter 'y' or 'n'.", colors.red, colors.black)
  298.         sleep(1)
  299.         start()
  300.       end
  301.       end
  302.  
  303.  
  304.     else if fs.exists("beta_reactor_control") then
  305.         draw_text_term(2, 3, "Current Program:", colors.white, colors.black)
  306.         draw_text_term(2, 4, "Beta Reactor Control", colors.lime, colors.black)
  307.         draw_text_term(1, 6, "Do you want to update this program? (y/n)", colors.white, colors.black)
  308.         draw_text_term(1, 7, "This will delete the current program and any saved settings", colors.gray,        colors.black)
  309.         term.setCursorPos(1,9)
  310.         term.setTextColor(colors.white)
  311.         input = read()
  312.         if input == "y" then
  313.           install("beta_reactor_control", beta_reactor_control_pastebin)
  314.         else if input == "n" then
  315.           selectProgram()
  316.         else
  317.           draw_text_term(1, 10, "please enter 'y' or 'n'.", colors.red, colors.black)
  318.           sleep(1)
  319.           start()
  320.         end
  321.         end
  322.      
  323.     else if fs.exists("turbine_control") then
  324.       draw_text_term(2, 3, "Current Program:", colors.white, colors.black)
  325.       draw_text_term(2, 4, "Turbine Control", colors.lime, colors.black)
  326.       draw_text_term(1, 6, "Do you want to update this program? (y/n)", colors.white, colors.black)
  327.       draw_text_term(1, 7, "This will delete the current program and any saved settings", colors.gray, colors.black)
  328.       term.setCursorPos(1,9)
  329.       term.setTextColor(colors.white)
  330.       input = read()
  331.       if input == "y" then
  332.         install("turbine_control", turbine_control_pastebin)
  333.       else if input == "n" then
  334.         selectProgram()
  335.       else
  336.         draw_text_term(1, 10, "please enter 'y' or 'n'.", colors.red, colors.black)
  337.         sleep(1)
  338.         start()
  339.       end
  340.       end
  341.    
  342.     end
  343.     end
  344.     end
  345.     end
  346.   end
  347.  
  348.   selectProgram()
  349.  
  350.  
  351. end
  352.  
  353. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement