added package manager, probably useful for something, not sure what

This commit is contained in:
v 2020-12-28 16:01:41 +00:00
parent 1bebaa0f40
commit d46df8884b
3 changed files with 140 additions and 0 deletions

26
pkgm/bin/pkgm.lua Normal file
View File

@ -0,0 +1,26 @@
local args={...}
local pkg=dofile("/lib/pkgm.lua")
if args[1]=="i" and args[2]~=nil then
local deps=pkg.dependencies(args[2])
if not deps then
print("Already up to date, æpioform.")
return
end
print("To be installed or updated:\n")
print(table.concat(deps," "))
print("\nPress the any key to continue.")
os.pullEvent("char")
pkg.pkginstmulti(deps)
print("Done!")
elseif args[1]=="rm" and args[2]~=nil then
table.remove(args,1)
print("If this breaks things, you're completely responsible.")
print("Press the any key to continue.")
os.pullEvent("char")
for i,v in ipairs(args) do
pkg.pkguinst(v)
end
print("Done.")
else
print("usage:\ni <package>\nupd <package>\nrm <packages>")
end

99
pkgm/lib/pkgm.lua Normal file
View File

@ -0,0 +1,99 @@
local mfs=dofile("/lib/mfs.lua")
local pkg_url="https://git.osmarks.tk/heavpoot/packages1/raw/branch/master/"
local res={}
local cache={}
function res.set_pkg_url(x)
pkg_url=x
end
function res.get_pkg_url()
return pkg_url
end
function hget(x)
local f=http.get(x)
if not f then return nil end
local i=f.readAll()
f.close()
return i
end
function res.pkgmeta(p)
local mt=hget(pkg_url..p.."/pkgmeta.ltn")
if not mt then error("Package "..p.." does not have a pkgmeta.ltn!") end
return textutils.unserialize(mt)
end
function res.pkginst(p)
mt=res.pkgmeta(p)
local packinfo=mfs.load(".packinfo")
if not packinfo[p] then packinfo[p]={} end
packinfo[p].version=mt.version or "0.1.0"
mfs.save(".packinfo",packinfo)
if mt.files then
for i,thing in pairs(mt.files) do
mfs.mmkdir("/"..i)
for _,v in pairs(thing) do
mfs.write("/"..i.."/"..v,hget(pkg_url..p.."/"..i.."/"..v))
end
end
end
end
function res.pkguinst(p)
mt=res.pkgmeta(p)
local packinfo=mfs.load(".packinfo")
if not packinfo[p] then return end
packinfo[p]=nil
mfs.save(".packinfo",packinfo)
if mt.files then
for i,thing in pairs(mt.files) do
for _,v in pairs(thing) do
fs.delete("/"..i.."/"..v)
end
end
end
end
function res.pkginstmulti(pkgs)
local tmp={}
for i=1,#pkgs do
tmp[i]=function() res.pkginst(pkgs[i]) end
end
parallel.waitForAll(unpack(tmp))
end
function res.dependencies(p,toplvl,x)
toplvl=toplvl or true
if toplvl then
cache.vi=mfs.load(".packinfo")
end
x=x or {}
if x[p]~=nil then return end
local mt=res.pkgmeta(p)
if cache.vi[p] then
if mt.version==cache.vi[p].version then
x[p]=0
return
end
end
x[p]=1
for _,v in pairs(mt.dependencies)do
if type(v)=="string" then
res.dependencies(v,false,x)
else
res.dependencies(v.name,false,x)
end
end
if toplvl then
local res={}
for i,v in pairs(x) do
if v==1 then
res[#res+1]=i
end
end
return res
end
end
return res

15
pkgm/pkgmeta.ltn Normal file
View File

@ -0,0 +1,15 @@
{
["version"] = "0.1.0",
["dependencies"] = {
"mfs",
},
["description"] = "Package manager. For managing packages, bee incursions and other apionic systems.",
["files"] = {
["bin"] = {
"pkgm.lua"
},
["lib"] = {
"pkgm.lua"
},
}
}