Advertisement
FNCxPro

DeltaOS-unstable installer for fork

Nov 9th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 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.  
  14. --Remove the line above this and change the lines below to use automated mode.
  15. local automated = true -- Don't touch!
  16. local hide_progress = true -- If true, will not list out files as they are downloaded
  17. args[1] = "FNCxPro" -- Github username
  18. args[2] = "deltaOS-unstable" -- Github repo name
  19. args[3] = nil -- Branch - defaults to "master"
  20. args[4] = nil -- Path - defaults to root ("/")
  21. local pre_dl = "print('Starting download...')" -- Command(s) to run before download starts.
  22. local post_dl = "os.reboot()" -- Command(s) to run after download completes.
  23. --Remove the line below this and change the lines below to use automated mode.
  24.  
  25. args[3] = args[3] or "master"
  26. args[4] = args[4] or ""
  27.  
  28. if not automated and #args < 2 then
  29. print("Usage:\n"..shell.getRunningProgram().." <user> <repo> [branch=master] [path=/]") error()
  30. end
  31.  
  32. local function save(data,file)
  33. local file = shell.resolve(file)
  34. if not (fs.exists(string.sub(file,1,#file - #fs.getName(file))) and fs.isDir(string.sub(file,1,#file - #fs.getName(file)))) then
  35. if fs.exists(string.sub(file,1,#file - #fs.getName(file))) then fs.delete(string.sub(file,1,#file - #fs.getName(file))) end
  36. fs.makeDir(string.sub(file,1,#file - #fs.getName(file)))
  37. end
  38. local f = fs.open(file,"w")
  39. f.write(data)
  40. f.close()
  41. end
  42.  
  43. local function download(url, file)
  44. save(http.get(url).readAll(),file)
  45. end
  46.  
  47. if not json then
  48. --print("Downloading JSON api...\n(Credits to ElvishJerricco!)")
  49. download("http://pastebin.com/raw.php?i=4nRg9CHU","json")
  50. os.loadAPI("json")
  51. end
  52.  
  53. if pre_dl then loadstring(pre_dl)() else print("Downloading files from github....") end
  54. local data = json.decode(http.get("https://api.github.com/repos/"..args[1].."/"..args[2].."/git/trees/"..args[3].."?recursive=1").readAll())
  55. if data.message and data.message == "Not found" then error("Invalid repository",2) else
  56. for k,v in pairs(data.tree) do
  57. -- Make directories
  58. if v.type == "tree" then
  59. fs.makeDir(fs.combine(args[4],v.path))
  60. if not hide_progress then
  61. print(v.path)
  62. end
  63. end
  64. end
  65. for k,v in pairs(data.tree) do
  66. -- Download files
  67. if v.type == "blob" then
  68. download("https://raw.github.com/"..args[1].."/"..args[2].."/"..args[3].."/"..v.path,fs.combine(args[4],v.path))
  69. if not hide_progress then
  70. print(v.path)
  71. end
  72. end
  73. end
  74. end
  75. if post_dl then loadstring(post_dl)() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement