Stary2001

install

Jan 1st, 2013
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.33 KB | None | 0 0
  1. local files={}
  2.  
  3. if not http then
  4.   print("HTTP API is required to update!")
  5.   return
  6. end
  7.  
  8. local args= {...}
  9. local repo = args[1] or "stary2001/staryos"
  10. local branch = args[2] or "master"
  11. local repo = "https://api.bitbucket.org/1.0/repositories/"..repo
  12.  
  13. function get(url)
  14.     local page = http.get(url)
  15. if page then
  16.    local cont = page.readAll()
  17.       page.close()
  18.       return cont
  19.   else
  20.     error("Failed downloading "..url)
  21.   end
  22. end
  23.  
  24. function list(path)
  25.   local url = repo.."/src/"..branch.."/"..path
  26.   local t=json.decode(get(url))
  27.  
  28.   for k,v in pairs(t.files) do
  29.     files[#files+1] = v.path
  30.   end
  31.   for k,v in pairs(t.directories) do
  32.     list(v)
  33.   end
  34. end
  35.  
  36. function skeleton(path)
  37.   local tmp_path=""
  38.    for comp in string.gmatch(path,"(.-)/") do
  39.     tmp_path=tmp_path.."/"..comp
  40.     if not fs.exists(tmp_path) then fs.makeDir(tmp_path) end
  41.   end
  42. end
  43.  
  44. if not json then
  45.   local url = repo .."/raw/"..branch.."/lib/json"
  46.   local json_api = get(url)
  47.   local f = fs.open("json","w")
  48.   if f then
  49.     f.write(json_api)
  50.     f.close()
  51.     os.loadAPI("json")
  52.   else
  53.     print("Failed opening 'json'")
  54.     return
  55.   end
  56. end
  57.  
  58. list("")
  59.  
  60. for k,v in pairs(files) do
  61.     print(v)
  62.     skeleton(v)
  63.     local url = repo.."/raw/"..branch.."/"..v
  64.     local content=get(url)
  65.     local f=fs.open(v,"w")
  66.     f.write(content)
  67.     f.close()
  68. end
Advertisement
Add Comment
Please, Sign In to add comment