Advertisement
MavricMC

gitGet-github raw downloader

Mar 5th, 2023 (edited)
1,305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.38 KB | None | 0 0
  1. --gitGet-github raw downloader--
  2.  
  3. --Made by Mavric on youtube--
  4.  
  5. --functions--
  6. --downloads a github raw--
  7. function gitGet(args)
  8.     --check that a git raw path was entered--
  9.     if args[2] == nil then
  10.         error("args[2]: must enter git raw path (the part after https://raw.githubusercontent.com/)")
  11.     --check that a path was entered--
  12.     elseif args[3] == nil then
  13.         error("args[3]: must enter path")
  14.     --check the path doesnt already exist--
  15.     elseif fs.exists(args[3]) then
  16.         error("args[3]: path already exists")
  17.     end
  18.  
  19.     --make the http get--
  20.     local download = http.get("https://raw.githubusercontent.com/".. args[2])
  21.  
  22.     --open the file and empty contents--
  23.     local file = fs.open(args[3], "w")
  24.  
  25.     --write text to file--
  26.     while true do
  27.         local text = download.readLine()
  28.    
  29.         if text == nil then
  30.             file.close()
  31.             return true
  32.         end
  33.         file.writeLine(text)
  34.     end
  35. end
  36.  
  37. --installs a group of files from a github raw list--
  38. function gitInstall(args)
  39.     --default version is main (latest)--
  40.     local version = "main"
  41.    
  42.     --check that a git repo path was entered--
  43.     if args[2] == nil then
  44.         error("args[2]: must enter get repo path (the part after https://github.com/ but just the username and repo name)")
  45.     --if version give replace default--
  46.     elseif args[3] ~= nil then
  47.         version = args[3]
  48.     end
  49.    
  50.     --http the install list--
  51.     local list = http.get("https://raw.githubusercontent.com/".. args[2].. "/".. version.. "/install.txt")
  52.    
  53.     --make dir to put files--
  54.     local dir = list.readLine()
  55.    
  56.     --check the dir doesnt already exist--
  57.     if fs.isDir(dir) == true then
  58.         error("dir already exists")
  59.     else
  60.         fs.makeDir(dir)
  61.     end
  62.    
  63.     --download each file--
  64.     while true do
  65.         local text = list.readLine()
  66.         local text2 = list.readLine()
  67.        
  68.         if text == nil or text2 == nil or text == "" or text2 == "" then
  69.             break
  70.         end
  71.         local args2 = {"get", text, (text2)}
  72.         printError(args2[2])
  73.         print(args2[3])
  74.         gitGet(args2)
  75.     end
  76. end
  77.  
  78. --main code--
  79. --run gitGet or gitInstall based on arg[1]--
  80. if arg[1] == "get" then
  81.     gitGet(arg)
  82. elseif arg[1] == "install" then
  83.     gitInstall(arg)
  84. else
  85.     error("args[1]: must enter get or install")
  86. end
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement