added remove and dir functionality to pkg

This commit is contained in:
Izaya 2017-09-23 18:22:15 +10:00
parent 237b1c5e09
commit 55eb012e16

View File

@ -1,10 +1,14 @@
local tA = {...} local tA = {...}
local rf = tA[1] local rf = tA[2]
local wget = wget or loadfile("/boot/exec/wget.lua") local wget = wget or loadfile("/boot/exec/wget.lua")
if not wget then if not wget then
print("wget is required to run this program") print("wget is required to run this program")
elseif rf and pcall(fs.exists,rf) then elseif rf and pcall(fs.exists,rf) then
local pref = tA[2] or "/boot/" local pref = tA[3] or "/boot/"
local mode = "install"
if tA[1]:sub(1,1) == "r" then
mode = "remove"
end
local files = {} local files = {}
local lrf = "/tmp/rf.txt" local lrf = "/tmp/rf.txt"
@ -32,6 +36,10 @@ elseif rf and pcall(fs.exists,rf) then
local function dl(p,u) local function dl(p,u)
if u:sub(1,8) == "https://" or u:sub(1,7) == "http://" then if u:sub(1,8) == "https://" or u:sub(1,7) == "http://" then
wget(u,pref..p) wget(u,pref..p)
elseif u == "dir" then
fs.mkdir(pref..p)
else
fs.cp(u,pref..p)
end end
end end
@ -45,13 +53,21 @@ elseif rf and pcall(fs.exists,rf) then
if not f then return false, "no recipe" end if not f then return false, "no recipe" end
files=precipe(f:read("*a")) files=precipe(f:read("*a"))
f:close() f:close()
local count = 1
local total = #files local total = #files
print(mode.." the following files to "..pref.."?")
for k,v in ipairs(files) do io.write(v[2].." ") end
io.write("\n[yN] ")
local c = io.read():lower():sub(1,1)
if c ~= "y" then return false, "aborted" end
for k,v in ipairs(files) do for k,v in ipairs(files) do
print(tostring(count).."/"..tostring(total)..": "..pref..v[2]) print(tostring(k).."/"..tostring(total)..": "..pref..v[2])
dl(v[2],v[1]) if mode == "install" then
count=count+1 dl(v[2],v[1])
elseif mode == "remove" then
fs.rm(pref..v[2])
end
end end
end end