Advertisement
Guest User

test

a guest
Aug 29th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.65 KB | None | 0 0
  1. local args = { ... }
  2.  
  3. local stStr = "Installing DeltaOS..."
  4. local w,h = term.getSize()
  5. local amd = 0
  6.  
  7.  
  8.  
  9. if fs.getDir(shell.getRunningProgram()) ~= "" and fs.getDir(shell.getRunningProgram()) ~= "rom/programs/http" then
  10.  fs.move(shell.getRunningProgram(), "/")
  11. end
  12.  
  13.  
  14. term.setBackgroundColor(colors.white)
  15. term.setTextColor(colors.black)
  16. term.clear()
  17. term.setCursorPos(w/2-stStr:len()/2, 2)
  18. write(stStr)
  19.  
  20.  
  21.  
  22. --[[ /gitget
  23. GitHub downloading utility for CC.
  24. Developed by apemanzilla.
  25.  
  26. If you want to use this as an automated installer, please see lines 13 and 23.
  27.  
  28. This requires ElvishJerricco's JSON parsing API.
  29. Direct link: http://pastebin.com/raw.php?i=4nRg9CHU
  30. ]]--
  31.  
  32.  
  33.  
  34.  
  35. --Remove the line above this and change the lines below to use automated mode.
  36. local automated = true                                                  -- Don't touch!
  37. local hide_progress = true                                              -- If true, will not list out files as they are downloaded
  38. args[1] = "FlareHAX0R"                                                 -- Github username
  39. args[2] = "DeltaOS-unstable"                                                               -- Github repo name
  40. args[3] = nil                                                                   -- Branch - defaults to "master"
  41. args[4] = "/"                                                                -- Path - defaults to root ("/")
  42. local pre_dl = " "  -- Command(s) to run before download starts.
  43. local post_dl = "os.reboot()"   -- Command(s) to run after download completes.
  44. --Remove the line below this and change the lines below to use automated mode.
  45.  
  46. args[3] = args[3] or "master"
  47. args[4] = args[4] or ""
  48.  
  49. if not automated and #args < 2 then
  50.         print("Usage:\n"..shell.getRunningProgram().." <user> <repo> [branch=master] [path=/]") error()
  51. end
  52.  
  53. local function save(data,file)
  54.         local file = shell.resolve(file)
  55.         if not (fs.exists(string.sub(file,1,#file - #fs.getName(file))) and fs.isDir(string.sub(file,1,#file - #fs.getName(file)))) then
  56.                 if fs.exists(string.sub(file,1,#file - #fs.getName(file))) then fs.delete(string.sub(file,1,#file - #fs.getName(file))) end
  57.                 fs.makeDir(string.sub(file,1,#file - #fs.getName(file)))
  58.         end
  59.         local f = fs.open(file,"w")
  60.         f.write(data)
  61.         f.close()
  62. end
  63.  
  64. local function download(url, file)
  65.         save(http.get(url).readAll(),file)
  66. end
  67.  
  68. if not json then
  69.         --print("Downloading JSON api...\n(Credits to ElvishJerricco!)")
  70.         download("http://pastebin.com/raw.php?i=4nRg9CHU","json")
  71.         os.loadAPI("json")
  72. end
  73.  
  74. if pre_dl then loadstring(pre_dl)() else print("Downloading files from github....") end
  75. local data = json.decode(http.get("https://api.github.com/repos/"..args[1].."/"..args[2].."/git/trees/"..args[3].."?recursive=1").readAll())
  76. if data.message and data.message == "Not found" then error("Invalid repository",2) else
  77.     for k,v in pairs(data.tree) do
  78.         -- Make directories
  79.         if v.type == "tree" then
  80.             fs.makeDir(fs.combine(args[4],v.path))
  81.             if not hide_progress then
  82.                 print(v.path)
  83.             end
  84.         end
  85.     end
  86.     for k,v in pairs(data.tree) do
  87.         -- Download files
  88.         if v.type == "blob" then
  89.             download("https://raw.github.com/"..args[1].."/"..args[2].."/"..args[3].."/"..v.path,fs.combine(args[4],v.path))
  90.             amd = amd+1
  91.    term.setCursorPos(w/2-string.len(tostring(amd))/2, 5)
  92.    term.clearLine()
  93.    term.setCursorPos(w/2-string.len(tostring(amd).." files downloaded")/2, 5)
  94.    write(tostring(amd).." files downloaded")
  95.    if not hide_progress then
  96.                 print(v.path)
  97.             end
  98.         end
  99.     end
  100. end
  101. if post_dl then loadstring(post_dl)() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement