Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local files={}
- if not http then
- print("HTTP API is required to update!")
- return
- end
- local args= {...}
- local repo = args[1] or "stary2001/staryos"
- local branch = args[2] or "master"
- local repo = "https://api.bitbucket.org/1.0/repositories/"..repo
- function get(url)
- local page = http.get(url)
- if page then
- local cont = page.readAll()
- page.close()
- return cont
- else
- error("Failed downloading "..url)
- end
- end
- function list(path)
- local url = repo.."/src/"..branch.."/"..path
- local t=json.decode(get(url))
- for k,v in pairs(t.files) do
- files[#files+1] = v.path
- end
- for k,v in pairs(t.directories) do
- list(v)
- end
- end
- function skeleton(path)
- local tmp_path=""
- for comp in string.gmatch(path,"(.-)/") do
- tmp_path=tmp_path.."/"..comp
- if not fs.exists(tmp_path) then fs.makeDir(tmp_path) end
- end
- end
- if not json then
- local url = repo .."/raw/"..branch.."/lib/json"
- local json_api = get(url)
- local f = fs.open("json","w")
- if f then
- f.write(json_api)
- f.close()
- os.loadAPI("json")
- else
- print("Failed opening 'json'")
- return
- end
- end
- list("")
- for k,v in pairs(files) do
- print(v)
- skeleton(v)
- local url = repo.."/raw/"..branch.."/"..v
- local content=get(url)
- local f=fs.open(v,"w")
- f.write(content)
- f.close()
- end
Advertisement
Add Comment
Please, Sign In to add comment