Advertisement
Xelostar

StorageSystemServerInstaller

Jan 8th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.67 KB | None | 0 0
  1.  
  2. print("This is the installer for Xelo's storage system.")
  3. if (fs.exists("/storage")) then
  4.     error("The path /storage is already in use. Please rename or remove this folder to continue the installation.")
  5. end
  6. if (fs.exists("/startup") or fs.exists("/startup.lua")) then
  7.     error("The filename startup.lua is already used. Please rename or remove this file to continue the installation.")
  8. end
  9. print("Please enter the installer code:")
  10. term.write("> ")
  11. local code = read()
  12.  
  13. print("Verifying code...")
  14. local baseURL = "http://bambootown.online:25556"
  15. local verifyPage = http.get(baseURL .. "/verifyCode/" .. code)
  16. assert(verifyPage, "Failed to reach the webserver!")
  17. local verifyRaw = verifyPage.readAll()
  18. verifyPage.close()
  19. assert(verifyRaw == "true", "Invalid code entered!")
  20.  
  21. print("Succesfully verified code!")
  22.  
  23. local codeFile = fs.open("/storage/code.txt", "w")
  24. codeFile.write(code)
  25. codeFile.close()
  26.  
  27. local mainPage = http.get(baseURL .. "/filesServer.txt")
  28. assert(mainPage, "Failed to reach the webserver!")
  29. local filesRaw = mainPage.readAll()
  30. mainPage.close()
  31.  
  32. print("Files to read:\n" .. filesRaw)
  33.  
  34. fs.makeDir("/storage")
  35.  
  36. print("Installing...")
  37. for name in filesRaw:gmatch("[^%s]+") do
  38.     local page = http.get(baseURL .. "/getServer/" .. code .. "/" .. name)
  39.     assert(page, "Failed to reach the webserver!")
  40.     local fileRaw = page.readAll()
  41.     page.close()
  42.  
  43.     local file = fs.open("/storage/" .. name, "w")
  44.     file.write(fileRaw)
  45.     file.close()
  46. end
  47.  
  48. local startupFile = fs.open("/startup.lua", "w")
  49. startupFile.write("shell.run(\"/storage/storage.lua\")")
  50. startupFile.close()
  51.  
  52. print("Success: downloaded all files!")
  53.  
  54. print("Rebooting...")
  55. sleep(3)
  56. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement