Advertisement
Techtronic

Untitled

Mar 29th, 2015
319
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 mondify this code
  5. -----------------------------------------------
  6.  
  7.  
  8. --Run this program to install 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. term.clear()
  28. -------------------FORMATTING-------------------------------
  29.  
  30. function draw_text_term(x, y, text, text_color, bg_color)
  31.     term.setTextColor(text_color)
  32.     term.setBackgroundColor(bg_color)
  33.     term.setCursorPos(x,y)
  34.     write(text)
  35. end
  36.  
  37. function draw_line_term(x, y, length, color)
  38.         term.setBackgroundColor(color)
  39.         term.setCursorPos(x,y)
  40.         term.write(string.rep(" ", length))
  41. end
  42.  
  43. function progress_bar_term(x, y, length, minVal, maxVal, bar_color, bg_color)
  44.     draw_line_term(x, y, length, bg_color) --backgoround bar
  45.     local barSize = math.floor((minVal/maxVal) * length)
  46.     draw_line_term(x, y, barSize, bar_color)    --progress so far
  47. end
  48.  
  49. function menu_bars()
  50.  
  51.     draw_line_term(1, 1, 55, colors.blue)
  52.     draw_text_term(10, 1, "BigReactors Control Installer", colors.white, colors.blue)
  53.    
  54.     draw_line_term(1, 19, 55, colors.blue)
  55.     draw_text_term(10, 19, "by jaranvil aka jared314", colors.white, colors.blue)
  56. end
  57.  
  58. --------------------------------------------------------------
  59.  
  60.  
  61.  
  62. function install(program, pastebin)
  63.     term.clear()
  64.     menu_bars()
  65.  
  66.     draw_text_term(1, 3, "Installing "..program.."...", colors.yellow, colors.black)
  67.     term.setCursorPos(1,5)
  68.     term.setTextColor(colors.white)
  69.     sleep(0.5)
  70.  
  71.     -----------------Install control program---------------
  72.  
  73.  
  74.     --delete any old backups
  75.     if fs.exists(program.."_old") then
  76.         fs.delete(program.."_old")
  77.     end
  78.  
  79.     --backup current program
  80.     if fs.exists(program) then
  81.         fs.copy(program, program.."_old")
  82.         fs.delete(program)
  83.     end
  84.  
  85.     --remove program and fetch new copy
  86.    
  87.     shell.run("pastebin get "..pastebin.." "..program)
  88.  
  89.     sleep(0.5)
  90.  
  91.     ------------------Install startup script-------------
  92.  
  93.     term.setCursorPos(1,8)
  94.  
  95.     --delete any old backups
  96.     if fs.exists("startup_old") then
  97.         fs.delete("startup_old")
  98.     end
  99.  
  100.     --backup current program
  101.     if fs.exists("startup") then
  102.         fs.copy("startup", "startup_old")
  103.         fs.delete("startup")
  104.     end
  105.    
  106.  
  107.     if program == "reactor_control" then
  108.         shell.run("pastebin get "..reactor_startup.." startup")
  109.     else if program == "turbine_control" then
  110.         shell.run("pastebin get "..turbine_startup.." startup")
  111.     end
  112.     end
  113.  
  114.     if fs.exists(program) then
  115.         draw_text_term(1, 11, "Success!", colors.lime, colors.black)
  116.         draw_text_term(1, 12, "Press Enter to reboot...", colors.gray, colors.black)
  117.         wait = read()
  118.         shell.run("reboot")
  119.     else
  120.         draw_text_term(1, 11, "Error installing file.", colors.red, colors.black)
  121.         sleep(0.1)
  122.         draw_text_term(1, 12, "Restoring old file...", colors.gray, colors.black)
  123.         sleep(0.1)
  124.         fs.copy(program.."_old", program)
  125.         fs.delete(program.."_old")
  126.  
  127.         draw_text_term(1, 14, "Press Enter to continue...", colors.gray, colors.black)
  128.         wait = read()
  129.         start()
  130.     end
  131. end
  132.  
  133.  
  134. ---------------------------------------------------------------
  135.  
  136. function start()
  137.     term.clear()
  138.     menu_bars()
  139.  
  140.     draw_text_term(1, 4, "What would you like to install or update?", colors.yellow, colors.black)
  141.     draw_text_term(3, 6, "1 - Reactor Control", colors.white, colors.black)
  142.     draw_text_term(3, 7, "2 - Turbine Control", colors.white, colors.black)
  143.     draw_text_term(1, 9, "Enter 1 or 2:", colors.yellow, colors.black)
  144.  
  145.     term.setCursorPos(1,10)
  146.     term.setTextColor(colors.white)
  147.     input = read()
  148.  
  149.     if input == "1" then
  150.         install("reactor_control", reactor_control_pastebin)
  151.     else if input == "2" then
  152.         install("turbine_control", turbine_control_pastebin)
  153.     else if input == "dev1" then
  154.         install("reactor_control", dev_reactor_control_pastebin)
  155.     else if input == "dev2" then
  156.         install("turbine_control", dev_turbine_control_pastebin)
  157.     else
  158.         draw_text_term(1, 12, "please enter a '1' or '2'.", colors.red, colors.black)
  159.         sleep(1)
  160.         start()
  161.     end
  162.     end
  163.     end
  164.     end
  165.  
  166. end
  167.  
  168. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement