From: Olav Bakke Svendsen Date: Tue, 17 Oct 2023 21:48:18 +0000 (+0200) Subject: Download multiple files from custom repo:tag X-Git-Tag: stable-steam~7 X-Git-Url: http://git.olavbs.no/?a=commitdiff_plain;h=e5546e20871664e5124ca1af5fa39764159ddba2;p=cc.git Download multiple files from custom repo:tag --- diff --git a/common/dl.lua b/common/dl.lua index 53d5359..5eb2e81 100644 --- a/common/dl.lua +++ b/common/dl.lua @@ -1,29 +1,35 @@ -- 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