OC-PsychOS/exec/pkg.lua

58 lines
1.2 KiB
Lua

local tA = {...}
local rf = tA[1]
local wget = wget or loadfile("/boot/exec/wget.lua")
if not wget then
print("wget is required to run this program")
elseif rf and pcall(fs.exists,rf) then
local pref = tA[2] or "/boot/"
local files = {}
local lrf = "/tmp/rf.txt"
local function precipe(s)
local t = {}
for line in s:gmatch("[^\n\r]+") do
t[#t+1] = {line:match("(.+)[ \t](.+)")}
local S = t[#t][1]
t[#t][1] = ""
for c in S:gmatch(".") do
if (string.byte(c) > 31 and string.byte(c) < 127) then
t[#t][1] = t[#t][1]..c
end
local S = t[#t][2]
t[#t][2] = ""
for c in S:gmatch(".") do
if (string.byte(c) > 31 and string.byte(c) < 127) then
t[#t][2] = t[#t][2]..c
end
end
end
end
return t
end
local function dl(p,u)
if u:sub(1,8) == "https://" or u:sub(1,7) == "http://" then
wget(u,pref..p)
end
end
if rf:sub(1,8) == "https://" or rf:sub(1,7) == "http://" then
wget(rf,"/tmp/rf.txt")
else
lrf = rf
end
local f=io.open(lrf)
if not f then return false, "no recipe" end
files=precipe(f:read("*a"))
f:close()
local count = 1
local total = #files
for k,v in ipairs(files) do
print(tostring(count).."/"..tostring(total)..": "..pref..v[2])
dl(v[2],v[1])
count=count+1
end
end