Guest User

install

a guest
Apr 7th, 2014
633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.71 KB | None | 0 0
  1. --[[ /gitget
  2. GitHub downloading utility for CC.
  3. Developed by apemanzilla.
  4.  
  5. If you want to use this as an automated installer, please see lines 13 and 23.
  6.  
  7. This requires ElvishJerricco's JSON parsing API.
  8. Direct link: http://pastebin.com/raw.php?i=4nRg9CHU
  9. ]]--
  10.  
  11. local args = {...}
  12.  
  13. local automated = true                                                  -- Don't touch!
  14. local hide_progress = true                                              -- If true, will not list out files as they are downloaded
  15. args[1] = "GoldProgramming"                                                 -- Github username
  16. args[2] = "GoldSuite"                                                               -- Github repo name
  17. args[3] = "master"                                                                   -- Branch - defaults to "master"
  18. args[4] = ""                                                                   -- Path - defaults to root ("/")
  19. local pre_dl = "print('Starting download...')"  -- Command(s) to run before download starts.
  20. local post_dl = "print('Download complete!')"   -- Command(s) to run after download completes
  21.  
  22. local function save(data,file)
  23.         local file = shell.resolve(file)
  24.         if not (fs.exists(string.sub(file,1,#file - #fs.getName(file))) and fs.isDir(string.sub(file,1,#file - #fs.getName(file)))) then
  25.                 if fs.exists(string.sub(file,1,#file - #fs.getName(file))) then fs.delete(string.sub(file,1,#file - #fs.getName(file))) end
  26.                 fs.makeDir(string.sub(file,1,#file - #fs.getName(file)))
  27.         end
  28.         local f = fs.open(file,"w")
  29.         f.write(data)
  30.         f.close()
  31. end
  32.  
  33. local function download(url, file)
  34.         save(http.get(url).readAll(),file)
  35. end
  36.  
  37. if not json then
  38.         download("http://pastebin.com/raw.php?i=4nRg9CHU","json")
  39.         os.loadAPI("json")
  40. end
  41.  
  42. if pre_dl then loadstring(pre_dl)() else print("Downloading files from github....") end
  43. local data = json.decode(http.get("https://api.github.com/repos/"..args[1].."/"..args[2].."/git/trees/"..args[3].."?recursive=1").readAll())
  44. if data.message and data.message == "Not found" then error("Invalid repository",2) else
  45.     for k,v in pairs(data.tree) do
  46.         -- Make directories
  47.         if v.type == "tree" then
  48.             fs.makeDir(fs.combine(args[4],v.path))
  49.             if not hide_progress then
  50.                 print(v.path)
  51.             end
  52.         end
  53.     end
  54.     for k,v in pairs(data.tree) do
  55.         -- Download files
  56.         if v.type == "blob" then
  57.             download("https://raw.github.com/"..args[1].."/"..args[2].."/"..args[3].."/"..v.path,fs.combine(args[4],v.path))
  58.             if not hide_progress then
  59.                 print(v.path)
  60.             end
  61.         end
  62.     end
  63. end
  64. if post_dl then loadstring(post_dl)() end
  65.  
  66. fs.delete("README.md")
  67. fs.delete("json")
  68. fs.delete("install")
Advertisement
Add Comment
Please, Sign In to add comment