Advertisement
Riewest14

sgit.lua

Jan 29th, 2023
933
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.11 KB | None | 0 0
  1. -- Author: Chase Riewestahl
  2. -- Date: 1/29/2023
  3. -- Description: Downloads sgit.lua from my github repo and pulls in the main branch unless overridden
  4. -- Usage: "sgit OPTIONAL_BRANCH" if no branch is passed defaults to "main"
  5.  
  6. local args = {...}
  7. local githubName = "Riewest"
  8. local repositoryName = "CC_Scripts" -- The repository must be public for this script to work
  9. local branch = args[1] or "main"
  10.  
  11. local filepath = "sgit.lua"
  12.  
  13. local rawHeaders = {
  14.     ["cache-control"] = "max-age=1",
  15. }                
  16. local rawUrl = string.format("https://raw.githubusercontent.com/%s/%s/%s/%s", githubName, repositoryName, branch, filepath)
  17. print("Attempting Download of: " .. rawUrl)
  18. local rawRequest = http.get(rawUrl, rawHeaders)
  19. if rawRequest then
  20.     local content = rawRequest.readAll() -- Read all lines in the lua file
  21.  
  22.     local scriptFile = fs.open(filepath, "w")
  23.  
  24.     scriptFile.write(content)
  25.  
  26.     scriptFile.close()
  27.  
  28.     print("File: " .. filepath .. " downloaded successfully")
  29. else
  30.     print("File: " .. filepath .. " not found")
  31. end
  32.  
  33.  
  34. local setup_command = "sgit " .. branch
  35. shell.run(setup_command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement