2018-10-21 00:35:48 +00:00
|
|
|
local Util = require('util')
|
|
|
|
|
2018-11-21 17:10:20 +00:00
|
|
|
local fs = _G.fs
|
2018-11-03 22:13:41 +00:00
|
|
|
local textutils = _G.textutils
|
2018-10-21 00:35:48 +00:00
|
|
|
|
|
|
|
local PACKAGE_DIR = 'packages'
|
|
|
|
|
|
|
|
local Packages = { }
|
|
|
|
|
|
|
|
function Packages:installed()
|
|
|
|
self.cache = { }
|
|
|
|
|
|
|
|
if fs.exists(PACKAGE_DIR) then
|
|
|
|
for _, dir in pairs(fs.list(PACKAGE_DIR)) do
|
|
|
|
local path = fs.combine(fs.combine(PACKAGE_DIR, dir), '.package')
|
|
|
|
self.cache[dir] = Util.readTable(path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return self.cache
|
|
|
|
end
|
|
|
|
|
|
|
|
function Packages:list()
|
2018-11-03 22:13:41 +00:00
|
|
|
if self.packageList then
|
|
|
|
return self.packageList
|
|
|
|
end
|
2018-11-21 17:10:20 +00:00
|
|
|
self.packageList = Util.readTable('usr/config/packages') or { }
|
2018-11-03 22:13:41 +00:00
|
|
|
|
|
|
|
return self.packageList
|
2018-10-21 00:35:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Packages:isInstalled(package)
|
|
|
|
return self:installed()[package]
|
|
|
|
end
|
|
|
|
|
2018-11-03 22:13:41 +00:00
|
|
|
function Packages:getManifest(package)
|
2018-11-04 18:00:37 +00:00
|
|
|
local fname = 'packages/' .. package .. '/.package'
|
2018-11-03 22:13:41 +00:00
|
|
|
if fs.exists(fname) then
|
|
|
|
return Util.readTable(fname)
|
|
|
|
end
|
|
|
|
local list = self:list()
|
|
|
|
local url = list and list[package]
|
|
|
|
|
|
|
|
if url then
|
2018-11-21 17:10:20 +00:00
|
|
|
local c = Util.httpGet(url)
|
2018-11-03 22:13:41 +00:00
|
|
|
if c then
|
2018-11-21 17:10:20 +00:00
|
|
|
c = textutils.unserialize(c)
|
|
|
|
if c then
|
|
|
|
c.repository = c.repository:gsub('{{OPUS_BRANCH}}', _G.OPUS_BRANCH)
|
|
|
|
return c
|
|
|
|
end
|
2018-11-03 22:13:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-21 00:35:48 +00:00
|
|
|
return Packages
|