Corbinhol

Installer

Jul 22nd, 2024 (edited)
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.72 KB | None | 0 0
  1. local filesystem = require("filesystem");
  2. local component = require("component");
  3. local computer = require("computer");
  4. local internet = require("internet")
  5.  
  6. local args = {...};
  7.  
  8. --Yeah...I admit...I took this directly from the opencomputers pastebin program.
  9. function install(pasteId, filename)
  10.     local f, reason = io.open(filename, "w")
  11.     if not f then
  12.       print("Failed opening file for writing: " .. reason)
  13.       return
  14.     end
  15.  
  16.     local url = "https://pastebin.com/raw/" .. pasteId
  17.     local result, response = pcall(internet.request, url)
  18.     if result then
  19.       for chunk in response do
  20.         -- string.gsub(chunk, "\r\n", "\n")
  21.         f:write(chunk)
  22.       end
  23.       f:close()
  24.     else
  25.       f:close()
  26.       fs.remove(filename)
  27.       print("HTTP request failed: " .. response)
  28.     end
  29. end
  30.  
  31. if not component.isAvailable("internet") then
  32.   print("Error! No internet card found. This program needs an internet card to update/install the program.");
  33.   os.exit();
  34. end
  35.  
  36. if args[1] == "-d" then
  37.   install("iFrWyDs9", "/usr/CM_Automator/installer.lua");
  38.   os.execute("/usr/CM_Automator/installer.lua");
  39.   os.exit();
  40. end
  41.  
  42. --Check if internet component exists. If not then abort as update cannot proceed.
  43.  
  44. --Install Script
  45. print("Starting install script.");
  46. --First thing it does is check if the directory exists, if not then it creates it. If that fails for whatever reason
  47. --Then it aborts.
  48. if not filesystem.isDirectory("/usr/CM_Automator") then
  49.     print("Directory could not be located. Creating.");
  50.     local success = filesystem.makeDirectory("/usr/CM_Automator");
  51.     if success then
  52.         print("Directory created successfully!");
  53.     else
  54.         print("Error! Could not create directory. Aborting.");
  55.         os.exit();
  56.     end
  57.     success = nil;
  58. else
  59.     print("Directory already exists. Presumed to be update or repair.");  
  60. end
  61.  
  62.  
  63.  
  64.  
  65. print("Installing Main Script...");
  66. install("5tKHxEdJ", "/usr/CM_Automator/main.lua");
  67. -- os.execute("pastebin get -f 5tKHxEdJ /usr/CM_Automator/main.lua");
  68. print("Installing Console Library...");
  69. install("epQvyACM", "/usr/CM_Automator/console.lua");
  70. -- os.execute("pastebin get -f Xwy0069d /usr/CM_Automator/console.lua");
  71. print("Installing Starter Wrapper...");
  72. install("1Yp5ys95", "/bin/cmauto.lua");
  73. -- os.execute("pastebin get -f 1Yp5ys95 /bin/cmauto.lua");
  74. print("Installing Networking Library...");
  75. install("aDDLpZ7q", "/usr/CM_Automator/network.lua");
  76. print("Installing startup script");
  77. install("YqChNPaJ", "/autorun.lua");
  78. install("iFrWyDs9", "/usr/CM_Automator/installer.lua");
  79. -- os.execute("pastebin get -f aDDLpZ7q /usr/CM_Automator/network.lua");
  80. print("Finished Setup. Restarting in 1 second");
  81. os.sleep(1);
  82. computer.shutdown(true);
  83.  
Advertisement
Add Comment
Please, Sign In to add comment