1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-15 05:04:50 +00:00
opus/sys/apis/packages.lua

67 lines
1.4 KiB
Lua
Raw Normal View History

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()
2019-01-18 04:33:19 +00:00
local list = { }
2018-10-21 00:35:48 +00:00
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')
2019-01-18 04:33:19 +00:00
list[dir] = Util.readTable(path)
2018-10-21 00:35:48 +00:00
end
end
2019-01-18 04:33:19 +00:00
return list
2018-10-21 00:35:48 +00:00
end
function Packages:list()
2019-01-18 04:33:19 +00:00
return Util.readTable('usr/config/packages') or { }
2018-10-21 00:35:48 +00:00
end
function Packages:isInstalled(package)
return self:installed()[package]
end
2019-01-09 11:59:19 +00:00
function Packages:downloadList()
local packages = {
[ 'develop-1.8' ] = 'https://pastebin.com/raw/WhEiNGZE',
[ 'master-1.8' ] = 'https://pastebin.com/raw/pexZpAxt',
}
if packages[_G.OPUS_BRANCH] then
Util.download(packages[_G.OPUS_BRANCH], 'usr/config/packages')
end
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
2018-11-23 17:14:47 +00:00
local c = Util.readTable(fname)
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
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