-- dl.lua
-- download from git repo
-- usage:
--- dl path/to/file.lua - saves to file.lua
--- dl path/to/file.lua -o - overwrites file.lua
+-- dl repo[:tag] remote/path:local/path[:o] [remote/path:local/path[:o] ...]
-local from, overwrite_flag = table.unpack({...})
-local overwrite = overwrite_flag == "-o"
-
-local download = function(f,t)
- return shell.run("wget "..f.." "..t)
+local args = table.unpack({...})
+local repo = ""
+local tag = ""
+local files = {}
+do
+ local repotag = table.remove(args, 1)
+ repo, tag = string.match(args[1], "^([^:]+):?(.*)$")
+ if tag == "" then tag = "HEAD" end
+ for _, file in pairs(args) do
+ local from, rest = string.match(file, "^/?([^:%s]+):?(.*)$")
+ local to, rest = string.match(rest, "^([^:%s]+):?(.*)$")
+ local overwrite = string.match(rest, "^(o)$") and true or false
+ table.insert(files, 1, { from = from, to = to, overwrite = overwrite })
+ end
end
-if not from then
- print("Nothing to download")
-else
- local url = "https://git.olavbs.no/?p=cc.git;a=blob_plain;f="..from..";hb=HEAD"
- local to = string.match(from, "([^/]-)$")
- if fs.exists(to) and overwrite then
+for _, file in pairs(files) do
+ local url = "https://git.olavbs.no/?p="..repo..".git;a=blob_plain;f="..from..";hb="..tag
+ if fs.exists(file.to) and file.overwrite then
local tmp = textutils.serialize(math.random(100000,999999))
- if download(url,tmp) then
- print("Overwriting "..to)
- fs.delete(to)
- fs.move(tmp,to)
+ local ok = shell.run("wget "..file.from.." "..tmp)
+ if ok then
+ print("Overwriting "..file.to)
+ fs.delete(file.to)
+ fs.move(tmp,file.to)
end
else
- download(url,to)
+ shell.run("wget "..file.from.." "..file.to)
end
end