make pkgman remove system packages
This commit is contained in:
parent
9983acb267
commit
21f40b3f3c
@ -1,10 +1,13 @@
|
|||||||
local serial = require "serialization"
|
local serial = require "serialization"
|
||||||
local dl = require "download"
|
local dl = require "download"
|
||||||
|
local mtar = require "libmtar"
|
||||||
local pkg = {}
|
local pkg = {}
|
||||||
pkg.cfgPath = "/boot/cfg/pkg"
|
pkg.cfgPath = "/boot/cfg/pkg"
|
||||||
pkg.sourcePath = pkg.cfgPath .. "/sources.cfg"
|
pkg.sourcePath = pkg.cfgPath .. "/sources.cfg"
|
||||||
pkg.installedPath = pkg.cfgPath .. "/installed.cfg"
|
pkg.installedPath = pkg.cfgPath .. "/installed.cfg"
|
||||||
require("pkgfs")
|
local w, lz16 = pcall(require,"liblz16")
|
||||||
|
if not w then lz16 = nil end
|
||||||
|
require "pkgfs"
|
||||||
|
|
||||||
local function getSources()
|
local function getSources()
|
||||||
local f = io.open(pkg.sourcePath,"rb")
|
local f = io.open(pkg.sourcePath,"rb")
|
||||||
@ -54,6 +57,31 @@ end
|
|||||||
local function deactivatePackage(path)
|
local function deactivatePackage(path)
|
||||||
require("pkgfs").remove(path)
|
require("pkgfs").remove(path)
|
||||||
end
|
end
|
||||||
|
local function fnormalize(s)
|
||||||
|
return table.concat(fs.segments(s),"/")
|
||||||
|
end
|
||||||
|
local function installSystemPackage(path,comp)
|
||||||
|
local f
|
||||||
|
if comp and lz16 then
|
||||||
|
f = lz16.open(path,"rb")
|
||||||
|
else
|
||||||
|
f = io.open(path,"rb")
|
||||||
|
end
|
||||||
|
for fname, read, size in mtar.iter(f) do
|
||||||
|
local opath = "/boot/"..fnormalize(fname)
|
||||||
|
print(opath..": "..tostring(size))
|
||||||
|
fs.makeDirectory(opath:match("(.+)/[^/]+"))
|
||||||
|
local of = io.open(opath,"wb")
|
||||||
|
if not of then error("unable to open "..opath.." for writing") end
|
||||||
|
local tmp
|
||||||
|
repeat
|
||||||
|
tmp = read(2048) or ""
|
||||||
|
of:write(tmp)
|
||||||
|
until not tmp or tmp:len() < 1
|
||||||
|
of:close()
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
function pkg.addRepo(name,path,cache) -- string string boolean -- boolean -- Adds a repository, referred to as *name*, to the list of package sources, with the remote path *path*. If *cache* is set, keep a local copy of the repository index.
|
function pkg.addRepo(name,path,cache) -- string string boolean -- boolean -- Adds a repository, referred to as *name*, to the list of package sources, with the remote path *path*. If *cache* is set, keep a local copy of the repository index.
|
||||||
local sources = getSources()
|
local sources = getSources()
|
||||||
@ -76,7 +104,7 @@ function pkg.update() -- Re-download cached repository indexes.
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function pkg.list(filter) -- string -- -- Print a list of available packages matching *filter*.
|
function pkg.list(filter,installed) -- string boolean -- -- Print a list of available packages matching *filter*, optionally filtering to only installed packages if *installed* is set.
|
||||||
filter = filter or ""
|
filter = filter or ""
|
||||||
local pkglist = {}
|
local pkglist = {}
|
||||||
for repo,_ in pairs(getSources()) do
|
for repo,_ in pairs(getSources()) do
|
||||||
@ -88,7 +116,8 @@ function pkg.list(filter) -- string -- -- Print a list of available packages mat
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
for k,v in pairs(pkglist) do
|
for k,v in pairs(pkglist) do
|
||||||
print(string.format("%s/%s\n %s",v.repo,k,v.description))
|
if v.system then io.write("\27[31m") end
|
||||||
|
print(string.format("%s/%s: %s\27[0m\n %s\n Authors: %s",v.repo,k,v.name,v.description,v.authors))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -104,25 +133,30 @@ function pkg.getMeta(pkgname) -- string -- table -- Returns the metadata for a t
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function pkg.get(pkgname,auto) -- string boolean -- boolean -- Downloads and mounts a package, identified as *pkgname*, onto the pkgfs.
|
function pkg.get(pkgname,auto) -- string boolean -- boolean -- Downloads and mounts a package, identified as *pkgname,* onto the pkgfs. Setting *auto* will flag the package as automatically installed; this is used for dependencies.
|
||||||
local pkginfo = pkg.getMeta(pkgname)
|
local pkginfo = pkg.getMeta(pkgname)
|
||||||
if not pkginfo then error("unable to locate package "..pkgname) end
|
if not pkginfo then error("unable to locate package "..pkgname) end
|
||||||
pkginfo.manual = not auto
|
pkginfo.manual = not auto
|
||||||
fs.makeDirectory("/boot/pkg")
|
fs.makeDirectory("/boot/pkg")
|
||||||
for k,v in ipairs(pkginfo.dependencies or {}) do
|
for k,v in ipairs(pkginfo.dependencies or {}) do
|
||||||
if not getInstalled()[v] then
|
if not getInstalled()[v] then
|
||||||
pkg.get(v)
|
pkg.get(v,true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
dl(pkginfo.repository.path.."/"..pkginfo.filename,"/boot/pkg/"..pkginfo.filename)
|
dl(pkginfo.repository.path.."/"..pkginfo.filename,"/boot/pkg/"..pkginfo.filename)
|
||||||
local installed = getInstalled()
|
local installed = getInstalled()
|
||||||
installed[pkgname] = pkginfo
|
installed[pkgname] = pkginfo
|
||||||
saveInstalled(installed)
|
saveInstalled(installed)
|
||||||
|
if pkginfo.system then
|
||||||
|
local rv = installSystemPackage("/boot/pkg/"..pkginfo.filename,pkginfo.compressed)
|
||||||
|
fs.remove("/boot/pkg/"..pkginfo.filename)
|
||||||
|
return rv
|
||||||
|
end
|
||||||
pcall(activatePackage,"/boot/pkg/"..pkginfo.filename,pkginfo.compressed)
|
pcall(activatePackage,"/boot/pkg/"..pkginfo.filename,pkginfo.compressed)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function pkg.upgrade(force) -- boolean -- boolean -- Upgrades all packages on the system to the current version stored in the relevant repository. If *force* is set, re-download all packages.
|
function pkg.upgrade(force) -- boolean -- -- Upgrades all packages on the system to the current version stored in the relevant repository. If *force* is set, re-download all packages.
|
||||||
pkg.update()
|
pkg.update()
|
||||||
fs.makeDirectory("/boot/pkg")
|
fs.makeDirectory("/boot/pkg")
|
||||||
local installed = getInstalled()
|
local installed = getInstalled()
|
||||||
@ -130,13 +164,10 @@ function pkg.upgrade(force) -- boolean -- boolean -- Upgrades all packages on th
|
|||||||
for pkgname,pkginfo in pairs(getRepoMeta(repo)) do
|
for pkgname,pkginfo in pairs(getRepoMeta(repo)) do
|
||||||
if installed[pkgname] and pkginfo.version ~= installed[pkgname].version or force then
|
if installed[pkgname] and pkginfo.version ~= installed[pkgname].version or force then
|
||||||
pkg.remove(pkgname)
|
pkg.remove(pkgname)
|
||||||
dl(info.path.."/"..pkginfo.filename,"/boot/pkg/"..pkginfo.filename)
|
pkg.get(pkgname,pkginfo.auto)
|
||||||
installed[pkgname] = pkg
|
|
||||||
pcall(activatePackage,"/boot/pkg/"..pkginfo.filename,pkginfo.compressed)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
saveInstalled(installed)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function pkg.remove(pkgname) -- string -- boolean -- Remove the package *pkgname* from the pkgfs and package directory.
|
function pkg.remove(pkgname) -- string -- boolean -- Remove the package *pkgname* from the pkgfs and package directory.
|
||||||
@ -145,6 +176,11 @@ function pkg.remove(pkgname) -- string -- boolean -- Remove the package *pkgname
|
|||||||
if not pkginfo then return true end
|
if not pkginfo then return true end
|
||||||
pcall(deactivatePackage,"/boot/pkg/"..pkginfo.filename)
|
pcall(deactivatePackage,"/boot/pkg/"..pkginfo.filename)
|
||||||
fs.remove("/boot/pkg/"..pkginfo.filename)
|
fs.remove("/boot/pkg/"..pkginfo.filename)
|
||||||
|
if pkginfo.system then
|
||||||
|
for k,v in pairs(pkginfo.files) do
|
||||||
|
fs.remove(v)
|
||||||
|
end
|
||||||
|
end
|
||||||
installed[pkgname] = nil
|
installed[pkgname] = nil
|
||||||
saveInstalled(installed)
|
saveInstalled(installed)
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user