added remove and dir functionality to pkg

This commit is contained in:
Izaya 2017-09-23 18:22:15 +10:00 committed by Izaya
parent 31309f3d2d
commit d63163df70
1 changed files with 22 additions and 6 deletions

View File

@ -1,10 +1,14 @@
local tA = {...}
local rf = tA[1]
local rf = tA[2]
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 pref = tA[3] or "/boot/"
local mode = "install"
if tA[1]:sub(1,1) == "r" then
mode = "remove"
end
local files = {}
local lrf = "/tmp/rf.txt"
@ -32,6 +36,10 @@ elseif rf and pcall(fs.exists,rf) then
local function dl(p,u)
if u:sub(1,8) == "https://" or u:sub(1,7) == "http://" then
wget(u,pref..p)
elseif u == "dir" then
fs.mkdir(pref..p)
else
fs.cp(u,pref..p)
end
end
@ -45,13 +53,21 @@ elseif rf and pcall(fs.exists,rf) then
if not f then return false, "no recipe" end
files=precipe(f:read("*a"))
f:close()
local count = 1
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
print(tostring(count).."/"..tostring(total)..": "..pref..v[2])
dl(v[2],v[1])
count=count+1
print(tostring(k).."/"..tostring(total)..": "..pref..v[2])
if mode == "install" then
dl(v[2],v[1])
elseif mode == "remove" then
fs.rm(pref..v[2])
end
end
end