1
0
mirror of https://github.com/kepler155c/opus synced 2024-12-26 00:20:26 +00:00

package management

This commit is contained in:
kepler155c@gmail.com 2018-11-03 18:13:41 -04:00
parent 88f126bf2f
commit c478781cba
10 changed files with 110 additions and 43 deletions

View File

@ -3,11 +3,15 @@ local Util = require('util')
local TREE_URL = 'https://api.github.com/repos/%s/%s/git/trees/%s?recursive=1' local TREE_URL = 'https://api.github.com/repos/%s/%s/git/trees/%s?recursive=1'
local FILE_URL = 'https://raw.githubusercontent.com/%s/%s/%s/%s' local FILE_URL = 'https://raw.githubusercontent.com/%s/%s/%s/%s'
local git = { } local git = { }
function git.list(repository) local os = _G.os
if not _G.GIT then
_G.GIT = { }
end
function git.list(repository, cache)
local t = Util.split(repository, '(.-)/') local t = Util.split(repository, '(.-)/')
local user = t[1] local user = t[1]
@ -15,6 +19,14 @@ function git.list(repository)
local branch = t[3] or 'master' local branch = t[3] or 'master'
local dataUrl = string.format(TREE_URL, user, repo, branch) local dataUrl = string.format(TREE_URL, user, repo, branch)
if _G.GIT[dataUrl] then
_G.GIT[dataUrl].count = _G.GIT[dataUrl].count + 1
else
_G.GIT[dataUrl] = {
count = 1
}
end
local contents = Util.download(dataUrl) local contents = Util.download(dataUrl)
if not contents then if not contents then
@ -22,7 +34,7 @@ function git.list(repository)
end end
local data = json.decode(contents) local data = json.decode(contents)
Util.writeTable('.git/' .. dataUrl, { day = os.day(), data = data })
if data.message and data.message:find("API rate limit exceeded") then if data.message and data.message:find("API rate limit exceeded") then
error("Out of API calls, try again later") error("Out of API calls, try again later")
end end

View File

@ -1,8 +1,7 @@
_G.requireInjector(_ENV)
local Util = require('util') local Util = require('util')
local fs = _G.fs local fs = _G.fs
local textutils = _G.textutils
local PACKAGE_DIR = 'packages' local PACKAGE_DIR = 'packages'
@ -22,11 +21,33 @@ function Packages:installed()
end end
function Packages:list() function Packages:list()
return Util.readTable('sys/packageList.lua') or { } if self.packageList then
return self.packageList
end
self.packageList = Util.readTable('sys/packageList.lua') or { }
return self.packageList
end end
function Packages:isInstalled(package) function Packages:isInstalled(package)
return self:installed()[package] return self:installed()[package]
end end
function Packages:getManifest(package)
-- local fname = 'packages/' .. package .. '/.package'
local fname = 'usr/milo/.package'
if fs.exists(fname) then
return Util.readTable(fname)
end
local list = self:list()
local url = list and list[package]
if url then
local c = Util.httpGet(url) -- will need to call load
if c then
return textutils.unserialize(c)
end
end
end
return Packages return Packages

View File

@ -430,7 +430,7 @@ end
function Util.download(url, filename) function Util.download(url, filename)
local contents, msg = Util.httpGet(url) local contents, msg = Util.httpGet(url)
if not contents then if not contents then
error(string.format('Failed to download %s\n%s', url, msg)) error(string.format('Failed to download %s\n%s', url, msg), 2)
end end
if filename then if filename then

View File

@ -5,6 +5,7 @@ local Config = require('config')
local Event = require('event') local Event = require('event')
local FileUI = require('ui.fileui') local FileUI = require('ui.fileui')
local NFT = require('nft') local NFT = require('nft')
local Packages = require('packages')
local SHA1 = require('sha1') local SHA1 = require('sha1')
local Tween = require('ui.tween') local Tween = require('ui.tween')
local UI = require('ui') local UI = require('ui')
@ -46,13 +47,16 @@ local function loadApplications()
applications = Util.readTable('sys/etc/app.db') applications = Util.readTable('sys/etc/app.db')
if fs.exists('usr/etc/apps') then for dir in pairs(Packages:installed()) do
local dbs = fs.list('usr/etc/apps') local path = fs.combine('packages/' .. dir, 'etc/apps')
if fs.exists(path) then
local dbs = fs.list(path)
for _, db in pairs(dbs) do for _, db in pairs(dbs) do
local apps = Util.readTable('usr/etc/apps/' .. db) or { } local apps = Util.readTable(fs.combine(path, db)) or { }
Util.merge(applications, apps) Util.merge(applications, apps)
end end
end end
end
if fs.exists(REGISTRY_DIR) then if fs.exists(REGISTRY_DIR) then
local files = fs.list(REGISTRY_DIR) local files = fs.list(REGISTRY_DIR)

36
sys/apps/Package.lua Normal file
View File

@ -0,0 +1,36 @@
_G.requireInjector(_ENV)
local Packages = require('packages')
local Util = require('util')
local fs = _G.fs
local args = { ... }
local action = table.remove(args, 1)
local function Syntax(msg)
error(msg)
end
if action == 'list' then
for k in pairs(Packages:list()) do
Util.print('[%s] %s', Packages:isInstalled(k) and 'x' or ' ', k)
end
end
if action == 'install' then
local name = args[1] or Syntax('Invalid package')
if Packages:isInstalled(name) then
error('Package is already installed')
end
local manifest = Packages:getManifest(name) or error('Invalid package')
local packageDir = 'packages/' .. name
local method = args[2] or 'remote'
if method == 'remote' then
Util.writeTable(packageDir .. '/.install', {
mount = string.format('%s gitfs %s', packageDir, manifest.repository),
})
Util.writeTable(fs.combine(packageDir, '.package'), manifest)
print('success')
end
end

View File

@ -1,13 +0,0 @@
_G.requireInjector(_ENV)
local Packages = require('packages')
local Util = require('util')
local args = { ... }
if args[1] == 'list' then
for k,v in pairs(Packages:list()) do
Util.print('[%s] %s', Packages:isInstalled(k) and 'x' or ' ', k)
end
end

View File

@ -568,10 +568,10 @@ local function shellRead(history)
local ie = Input:translate(event, p1, p2, p3) local ie = Input:translate(event, p1, p2, p3)
if ie then if ie then
if ie.code == 'scroll_up' then if ie.code == 'scroll_up' then
terminal.scrollUp() --terminal.scrollUp()
elseif ie.code == 'scroll_down' then elseif ie.code == 'scroll_down' then
terminal.scrollDown() --terminal.scrollDown()
elseif ie.code == 'terminate' then elseif ie.code == 'terminate' then
bExit = true bExit = true

View File

@ -11,10 +11,10 @@ end
if not fs.exists('usr/autorun') then if not fs.exists('usr/autorun') then
fs.makeDir('usr/autorun') fs.makeDir('usr/autorun')
end end
if not fs.exists('usr/config/fstab') then --if not fs.exists('usr/config/fstab') then
Util.writeFile('usr/config/fstab', -- Util.writeFile('usr/config/fstab',
'usr gitfs kepler155c/opus-apps/' .. _G.OPUS_BRANCH) -- 'usr gitfs kepler155c/opus-apps/' .. _G.OPUS_BRANCH)
end --end
if not fs.exists('usr/config/shell') then if not fs.exists('usr/config/shell') then
Util.writeTable('usr/config/shell', { Util.writeTable('usr/config/shell', {

View File

@ -26,11 +26,17 @@ end
-- https://github.com/mpeterv/depgraph/blob/master/src/depgraph/init.lua -- https://github.com/mpeterv/depgraph/blob/master/src/depgraph/init.lua
for name, package in pairs(Packages:installed()) do for name, package in pairs(Packages:installed()) do
if package.mount then local packageDir = fs.combine('packages', name)
fs.mount(table.unpack(Util.matches(package.mount))) debug(fs.combine(packageDir, '.install'))
if fs.exists(fs.combine(packageDir, '.install')) then
local install = Util.readTable(fs.combine(packageDir, '.install'))
if install and install.mount then
debug('mounting: ' .. install.mount)
fs.mount(table.unpack(Util.matches(install.mount)))
end
end end
addPath(appPaths, fs.combine('packages', name)) addPath(appPaths, packageDir)
local apiPath = fs.combine(fs.combine('packages', name), 'apis') local apiPath = fs.combine(fs.combine('packages', name), 'apis')
if fs.exists(apiPath) then if fs.exists(apiPath) then
addPath(luaPaths, apiPath) addPath(luaPaths, apiPath)

View File

@ -1,4 +1,5 @@
{ {
[ 'opus-neural' ] = 'file://packages/opus-neural/.package', [ 'opus-neural' ] = 'file://packages/opus-neural/.package',
[ 'opus-miners' ] = 'file://packages/opus-miners/.package', [ 'opus-miners' ] = 'file://packages/opus-miners/.package',
[ 'opus-milo' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/milo/.package',
} }