Advertisement
Corbinhol

Fusion Reactor Setup

Mar 10th, 2023 (edited)
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.45 KB | None | 0 0
  1. -- pastebin get fFxDjyhu Setup.lua && Setup -f -r -p -s
  2.  
  3. --Importing various APIs
  4. local filesystem = require("filesystem");
  5. local component = require("component");
  6. local term = require("term");
  7. local shell = require("shell");
  8. local computer = require("computer");
  9. local version = "0.2";
  10.  
  11. --Iterating Through startup parameters
  12. local args = {...};
  13.  
  14. local uninstall = false;
  15. local forceInstall = false;
  16. local repair = false;
  17. local pastebin = false;
  18. local stayOn = false;
  19.  
  20. for i,arg in ipairs(args) do
  21.     if arg == "-u" then uninstall = true; end
  22.     if arg == "-f" then forceInstall = true; end
  23.     if arg == "-r" then repair = true; end
  24.     if arg == "-p" then pastebin = true; end
  25.     if arg == "-s" then stayOn = true; end
  26. end
  27.  
  28. local function pastebinInstall() --Alternative Install through pastebin instead of github
  29.     print("Starting Install...");
  30.     shell.execute("mkdir /home/FusionController")
  31.     shell.execute("pastebin get wJCXfem8 /bin/controller.lua"); --Download Controller
  32.     shell.execute("pastebin get KAR6jmr8 /home/FusionController/API.lua"); --Download Controller API
  33. end
  34.  
  35. local function run_uninstall() --Uninstall the program.
  36.     print("Uninstalling Reactor Controller...");
  37.     os.sleep(1);
  38.     filesystem.remove("/bin/controller.lua");
  39.     filesystem.remove("/home/FusionController/");
  40. end
  41.  
  42. term.clear();
  43. print(string.rep("═", 80));
  44. if uninstall then --If uninstall parameter is detected, only uninstall.
  45.     run_uninstall()
  46.     shell.execute("rm Setup.lua");
  47.     print("Finished Uninstalling. Press any key to restart.");
  48.     io.read(); --Wait for keyboard input
  49.     computer.shutdown(true);
  50. else
  51.     if component.isAvailable("nc_fusion_reactor") or forceInstall then --Check if fusion reactor is connected to computer, or if force install is enabled.
  52.         print("Starting Reactor Controller Setup | " .. version);
  53.         if filesystem.exists("/bin/controller.lua") then --Check if program already exists on computer.
  54.             if repair == false then --If repair is enabled, skip asking and uninstall, else ask if they want to uninstall.
  55.                 print("Detected controller already on system...");
  56.                 print("Would you like to uninstall the Controller first? [Y/n]");
  57.                 local answer = io.read();
  58.             else
  59.                 answer = "Y"
  60.             end
  61.             if answer == "n" or answer == "N" then --If they do not want to re-install, then close setup.
  62.                 print("Closing Setup...");
  63.                 os.sleep(1);
  64.                 term.clear();
  65.                 os.exit();
  66.             else
  67.                 run_uninstall();
  68.             end
  69.         end
  70.         if pastebin then --if pastebin parameter, then install through pastebin.
  71.             if not forceInstall then
  72.                 print("[WARNING] Pastebin parameter detected. Using pastebin is not the recommended form, since pastes aren't permanent. Would you like to continue [Y/n]");
  73.                 local pastebinAnswer = io.read();
  74.             else
  75.                 local pastebinAnswer = "y";
  76.             end
  77.             if pastebinAnswer == "n" or pastebinAnswer == "N" then
  78.                 print("Closing Setup...");
  79.                 os.sleep(1);
  80.                 term.clear();
  81.                 os.exit();
  82.             end
  83.             pastebinInstall();
  84.         else --if not pastebin install, install through github.
  85.             print("Starting Install...");
  86.             shell.execute("mkdir /home/FusionController")
  87.             print("Downloading Controller...");
  88.             shell.execute("wget https://raw.githubusercontent.com/Corbinhol/Nuclear-Crafter-fusion-reactor-controller/main/Controller.lua /bin/controller.lua -Q");
  89.             print("Downloading API...")
  90.             shell.execute("wget https://raw.githubusercontent.com/Corbinhol/Nuclear-Crafter-fusion-reactor-controller/main/Api.lua /home/FusionController/Api.lua -Q");
  91.         end
  92.         shell.execute("rm Setup.lua"); --remove setup after install (github only.)
  93.         if stayOn then
  94.             print("Closing Setup");
  95.         else
  96.             print("Finished Installing. Press any key to restart.");
  97.             io.read();
  98.             computer.shutdown(true); --Restart computer afterwards.
  99.         end
  100.     else --If Fusion Reactor doesn't exist, then don't run installer (unless force parameter is used)
  101.         print("Error: No fusion reactor found, [Use -f to force install without it]");
  102.         os.exit();
  103.     end
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement