Evdev

dev_installer

Jul 16th, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -----BigReactor Control Installer
  2. -----by jaranvil aka jared314
  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 = "p4zeq7Ma"
  13. reactor_control_pastebin = "RCPEHmxs"
  14. turbine_control_pastebin = "5B8h94V4"
  15.  
  16. reactor_startup = "cZUH7y6k"
  17. turbine_startup = "h0jmye6t"
  18.  
  19. reactor_update_check = "MkF2QQjH"
  20. turbine_update_check = "QP3qrzNu"
  21.  
  22. dev_installer = "mCPQQ3Ge"
  23. dev_reactor_control_pastebin = "eYwBw9a3"
  24. dev_turbine_control_pastebin = "kJHeCx0Q"
  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(10, 19, "by jaranvil aka jared314", colors.white, colors.blue)
  58. end
  59.  
  60. --basic popup screen with title bar and exit button
  61. function popup_screen(y, title, height)
  62.  
  63.  
  64.   draw_line_term(4, y, 22, colors.blue)
  65.   draw_line_term(25, y, 1, colors.red)
  66.  
  67.   for counter = y+1, height+y do
  68.     draw_line_term(4, counter, 22, colors.white)
  69.   end
  70.  
  71.   draw_text_term(25, y, "X", colors.white, colors.red)
  72.   draw_text_term(5, y, title, colors.white, colors.blue)
  73. end
  74.  
  75. function load_config()
  76.   sr = fs.open("config.txt", "r")
  77.     version = tonumber(sr.readLine())
  78.     auto_string = sr.readLine()
  79.     on = tonumber(sr.readLine())
  80.     off = tonumber(sr.readLine())
  81.     auto_rods = sr.readLine()
  82.     auto_rf = tonumber(sr.readLine())
  83.     auto_fuel_temp = tonumber(sr.readLine())
  84.     auto_case_temp = tonumber(sr.readLine())
  85.     control_rf = sr.readLine()
  86.     control_fuel_temp = sr.readLine()
  87.     control_case_temp = sr.readLine()
  88.   sr.close()
  89. end
  90. --------------------------------------------------------------
  91.  
  92.  
  93.  
  94. function install(program, pastebin)
  95.   term.clear()
  96.   menu_bars()
  97.  
  98.   draw_text_term(1, 3, "Installing "..program.."...", colors.yellow, colors.black)
  99.   term.setCursorPos(1,5)
  100.   term.setTextColor(colors.white)
  101.   sleep(0.5)
  102.  
  103.   -----------------Install control program---------------
  104.  
  105.  
  106.   --delete any old backups
  107.   if fs.exists(program.."_old") then
  108.     fs.delete(program.."_old")
  109.   end
  110.  
  111.   --remove old configs
  112.   if fs.exists("config.txt") then
  113.     fs.delete("config.txt")
  114.   end
  115.  
  116.   --backup current program
  117.   if fs.exists(program) then
  118.     fs.copy(program, program.."_old")
  119.     fs.delete(program)
  120.   end
  121.  
  122.   --remove program and fetch new copy
  123.  
  124.   shell.run("pastebin get "..pastebin.." "..program)
  125.  
  126.   sleep(0.5)
  127.  
  128.   ------------------Install startup script-------------
  129.  
  130.   term.setCursorPos(1,8)
  131.  
  132.   --delete any old backups
  133.   if fs.exists("startup_old") then
  134.     fs.delete("startup_old")
  135.   end
  136.  
  137.   --backup current program
  138.   if fs.exists("startup") then
  139.     fs.copy("startup", "startup_old")
  140.     fs.delete("startup")
  141.   end
  142.  
  143.  
  144.   if program == "reactor_control" then
  145.     shell.run("pastebin get "..reactor_startup.." startup")
  146.   else if program == "turbine_control" then
  147.     shell.run("pastebin get "..turbine_startup.." startup")
  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. function reactorSearch()
  173.    local names = peripheral.getNames()
  174.    local i, name
  175.    for i, name in pairs(names) do
  176.       if peripheral.getType(name) == "BigReactors-Reactor" then
  177.          return peripheral.wrap(name)
  178.       else
  179.          --return null
  180.       end
  181.    end
  182. end
  183.  
  184. function turbineSearch()
  185.    local names = peripheral.getNames()
  186.    local i, name
  187.    for i, name in pairs(names) do
  188.       if peripheral.getType(name) == "BigReactors-Turbine" then
  189.          return peripheral.wrap(name)
  190.       else
  191.          --return null
  192.       end
  193.    end
  194. end
  195.  
  196. function selectProgram()
  197.   term.clear()
  198.   menu_bars()
  199.   draw_text_term(1, 3, "Select Program", colors.yellow, colors.black)
  200.   draw_text_term(3, 5, "1 - Reactor Control v"..current_version, colors.lime, colors.black)
  201.   draw_text_term(3, 6, "2 - Turbine Control v"..current_turbine_version, colors.lime, colors.black)
  202.   draw_text_term(1, 8, "Enter number:", colors.yellow, colors.black)
  203.  
  204.   term.setCursorPos(1,9)
  205.   term.setTextColor(colors.white)
  206.   input = read()
  207.  
  208.   if input == "1" then
  209.     install("reactor_control", reactor_control_pastebin)
  210.   else if input == "2" then
  211.     install("turbine_control", turbine_control_pastebin)
  212.   else if input == "dev1" then
  213.     install("reactor_control", dev_reactor_control_pastebin)
  214.   else if input == "dev2" then
  215.     install("turbine_control", dev_turbine_control_pastebin)
  216.   else
  217.     draw_text_term(1, 12, "please enter a '1' or '2'.", colors.red, colors.black)
  218.     sleep(1)
  219.     start()
  220.   end
  221.   end
  222.   end
  223.   end
  224. end
  225.  
  226. function load()
  227. draw_text_term(1, 1, "Loading...", colors.blue, colors.black)
  228. term.setTextColor(colors.white)
  229.   sleep(0.5)
  230.   term.setCursorPos(1, 3)
  231.   shell.run("pastebin get MkF2QQjH programs.txt")
  232.   sr = fs.open("programs.txt", "r")
  233.   current_version = tonumber(sr.readLine())
  234.   sr.close()
  235.   fs.delete("programs.txt")
  236.   sleep(0.5)
  237.   term.setCursorPos(1, 5)
  238.   shell.run("pastebin get QP3qrzNu versions.txt")
  239.   sr = fs.open("versions.txt", "r")
  240.   current_turbine_version = tonumber(sr.readLine())
  241.   sr.close()
  242.   fs.delete("versions.txt")
  243.   sleep(0.5)
  244.   draw_text_term(1, 7, "Looking for current installations...", colors.white, colors.black)
  245.   sleep(0.5)
  246. end
  247.  
  248. function start()
  249.   load()
  250.   term.clear()
  251.   menu_bars()
  252.  
  253.   if fs.exists("config.txt") then
  254.  
  255.     load_config()
  256.  
  257.     if fs.exists("reactor_control") then
  258.       draw_text_term(2, 3, "Currently Installed:", colors.white, colors.black)
  259.       draw_text_term(2, 4, "Reactor Control V"..version, colors.lime, colors.black)
  260.       draw_text_term(2, 6, "Current Release:", colors.white, colors.black)
  261.       draw_text_term(2, 7, "Reactor Control V"..current_version, colors.lime, colors.black)
  262.       draw_text_term(1, 9, "Do you want to update this program? (y/n)", colors.white, colors.black)
  263.       draw_text_term(1, 10, "This will delete the current program and any saved settings", colors.gray, colors.black)
  264.       term.setCursorPos(1,12)
  265.       term.setTextColor(colors.white)
  266.       input = read()
  267.       if input == "y" then
  268.         install("reactor_control", reactor_control_pastebin)
  269.       else if input == "n" then
  270.         selectProgram()
  271.       else
  272.         draw_text_term(1, 12, "please enter 'y' or 'n'.", colors.red, colors.black)
  273.         sleep(1)
  274.         start()
  275.       end
  276.       end
  277.      
  278.     else if fs.exists("turbine_control") then
  279.       draw_text_term(2, 3, "Currently Installed:", colors.white, colors.black)
  280.       draw_text_term(2, 4, "Turbine Control V"..version, colors.lime, colors.black)
  281.       draw_text_term(2, 6, "Current Release:", colors.white, colors.black)
  282.       draw_text_term(2, 7, "Turbine Control V"..current_turbine_version, colors.lime, colors.black)
  283.       draw_text_term(1, 9, "Do you want to update this program? (y/n)", colors.white, colors.black)
  284.       draw_text_term(1, 11, "This will delete the current program and any saved settings", colors.gray, colors.black)
  285.       term.setCursorPos(1,12)
  286.       term.setTextColor(colors.white)
  287.       input = read()
  288.       if input == "y" then
  289.         install("turbine_control", turbine_control_pastebin)
  290.       else if input == "n" then
  291.         selectProgram()
  292.       else
  293.         draw_text_term(1, 10, "please enter 'y' or 'n'.", colors.red, colors.black)
  294.         sleep(1)
  295.         start()
  296.       end
  297.       end
  298.    
  299.     end
  300.     end
  301.   end
  302.  
  303.   selectProgram()
  304.  
  305.  
  306. end
  307.  
  308. start()
Add Comment
Please, Sign In to add comment