SuicidalSTDz

Foo

Mar 14th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 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. --Remove the line above this and change the lines below to use automated mode.
  14. local automated = true -- Don't touch!
  15. local hide_progress = true -- If true, will not list out files as they are downloaded
  16. args[1] = "SuicidalSTDZ" -- Github username
  17. args[2] = "EnderAPI" -- Github repo name
  18. args[3] = "master" -- Branch - defaults to "master"
  19. args[4] = "/EnderAPI/"..args[3].."/" -- Path - defaults to root ("/")
  20. local pre_dl = "print('Downloading Ender API...')" -- Command(s) to run before download starts.
  21. local post_dl = "print('Downloaded Core Files...')"
  22. --local post_dl = "dofile('/EnderAPI/"..args[3].."/install')" -- Command(s) to run after download completes.
  23. --Remove the line below this and change the lines below to use automated mode.
  24.  
  25.  
  26. args[3] = args[3] or "master"
  27. args[4] = args[4] or ""
  28.  
  29. if not automated and #args < 2 then
  30. print("Usage:\n"..shell.getRunningProgram().." <user> <repo> [branch=master] [path=/]") error()
  31. end
  32.  
  33. local function save(data,file)
  34. local file = shell.resolve(file)
  35. if not (fs.exists(string.sub(file,1,#file - #fs.getName(file))) and fs.isDir(string.sub(file,1,#file - #fs.getName(file)))) then
  36. if fs.exists(string.sub(file,1,#file - #fs.getName(file))) then fs.delete(string.sub(file,1,#file - #fs.getName(file))) end
  37. fs.makeDir(string.sub(file,1,#file - #fs.getName(file)))
  38. end
  39. local f = fs.open(file,"w")
  40. f.write(data)
  41. f.close()
  42. end
  43.  
  44. local function download(url, file)
  45. save(http.get(url).readAll(),file)
  46. end
  47.  
  48. local function pullDir(tbl)
  49. for k,v in pairs(tbl) do
  50. if v.type == "dir" then
  51. if not hide_progress then print(""..v.path.."/") end
  52. pullDir(json.decode(http.get(v._links.self).readAll()))
  53. else
  54. if v.path ~= "readme.md" then
  55. if not hide_progress then print(""..v.path) end
  56. download("https://raw.github.com/"..args[1].."/"..args[2].."/"..args[3].."/"..v.path,fs.combine(args[4],v.path))
  57. end
  58. end
  59. end
  60. end
  61.  
  62. if not json then
  63. print("Downloading JSON api...\n(Credits to ElvishJerricco!)")
  64. download("http://pastebin.com/raw.php?i=4nRg9CHU","json")
  65. os.loadAPI("json")
  66. end
  67.  
  68. --[[
  69. EnderAPI Update and Loading Script
  70. ]]
  71.  
  72. local function loadAPIs( bShow )
  73. if bShow then
  74. print( "Loading APIs.." )
  75. end
  76. local tAPIs = {
  77. TextAPI = { success = os.loadAPI( "/EnderAPI/master/apis/text" ) },
  78. NumberAPI = { success = os.loadAPI( "/EnderAPI/master/apis/number" ) },
  79. ColorAPI = { success = os.loadAPI( "/EnderAPI/master/apis/color" ) },
  80. ColourAPI = { success = os.loadAPI( "/EnderAPI/master/apis/colour" ) },
  81. PastebinAPI = { success = os.loadAPI( "/EnderAPI/master/apis/pastebin" ) },
  82. MessageBoxAPI = { success = os.loadAPI( "/EnderAPI/master/apis/messageBox" ) }
  83. }
  84. for k, v in pairs( tAPIs ) do
  85. if not v.success then
  86. if bShow then
  87. printError( "Failed to load " .. tostring( k ) )
  88. end
  89. else
  90. if bShow then
  91. term.setTextColour( colours.lime )
  92. print( "Loaded " .. tostring( k ) )
  93. end
  94. end
  95. end
  96. if bShow then
  97. term.setTextColour( colours.white )
  98. end
  99. end
  100.  
  101. local function update()
  102. if pre_dl then loadstring(pre_dl)() else print("Downloading files from github....") end
  103. pullDir(json.decode(http.get("https://api.github.com/repos/"..args[1].."/"..args[2].."/contents/?ref="..args[3]).readAll()))
  104. if post_dl then loadstring(post_dl)() end
  105. end
  106.  
  107. --# Main Script
  108. if fs.exists( "/EnderAPI/master/config" ) then
  109. os.loadAPI( "/EnderAPI/master/config" )
  110. local bShow = config.returnVars().showUpdateStatus
  111. if config.returnVars().shouldAutoUpdate then
  112. if bShow then
  113. write( "Checking for updates\n" )
  114. end
  115. end
  116.  
  117. --# Check for any available updates, if showAutoUpdate is true
  118. if config.returnVars().shouldAutoUpdate then
  119. update()
  120. end
  121. else
  122. --# EnderAPI is not installed, download necessary files
  123. update()
  124. end
  125.  
  126. --# Load EnderAPI
  127. os.loadAPI( "/EnderAPI/master/config" )
  128. loadAPIs( config.returnVars().showUpdateStatus )
Advertisement
Add Comment
Please, Sign In to add comment