mirror of
https://github.com/kepler155c/opus
synced 2024-12-24 15:40:26 +00:00
package management
This commit is contained in:
parent
88f126bf2f
commit
c478781cba
@ -3,11 +3,15 @@ local Util = require('util')
|
||||
|
||||
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 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 user = t[1]
|
||||
@ -15,6 +19,14 @@ function git.list(repository)
|
||||
local branch = t[3] or 'master'
|
||||
|
||||
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)
|
||||
|
||||
if not contents then
|
||||
@ -22,7 +34,7 @@ function git.list(repository)
|
||||
end
|
||||
|
||||
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
|
||||
error("Out of API calls, try again later")
|
||||
end
|
||||
|
@ -1,8 +1,7 @@
|
||||
_G.requireInjector(_ENV)
|
||||
|
||||
local Util = require('util')
|
||||
|
||||
local fs = _G.fs
|
||||
local textutils = _G.textutils
|
||||
|
||||
local PACKAGE_DIR = 'packages'
|
||||
|
||||
@ -22,11 +21,33 @@ function Packages:installed()
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
function Packages:isInstalled(package)
|
||||
return self:installed()[package]
|
||||
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
|
||||
|
@ -430,7 +430,7 @@ end
|
||||
function Util.download(url, filename)
|
||||
local contents, msg = Util.httpGet(url)
|
||||
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
|
||||
|
||||
if filename then
|
||||
|
@ -1,14 +1,15 @@
|
||||
_G.requireInjector(_ENV)
|
||||
|
||||
local class = require('class')
|
||||
local Config = require('config')
|
||||
local Event = require('event')
|
||||
local FileUI = require('ui.fileui')
|
||||
local NFT = require('nft')
|
||||
local SHA1 = require('sha1')
|
||||
local Tween = require('ui.tween')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
local class = require('class')
|
||||
local Config = require('config')
|
||||
local Event = require('event')
|
||||
local FileUI = require('ui.fileui')
|
||||
local NFT = require('nft')
|
||||
local Packages = require('packages')
|
||||
local SHA1 = require('sha1')
|
||||
local Tween = require('ui.tween')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
local colors = _G.colors
|
||||
local fs = _G.fs
|
||||
@ -46,11 +47,14 @@ local function loadApplications()
|
||||
|
||||
applications = Util.readTable('sys/etc/app.db')
|
||||
|
||||
if fs.exists('usr/etc/apps') then
|
||||
local dbs = fs.list('usr/etc/apps')
|
||||
for _, db in pairs(dbs) do
|
||||
local apps = Util.readTable('usr/etc/apps/' .. db) or { }
|
||||
Util.merge(applications, apps)
|
||||
for dir in pairs(Packages:installed()) do
|
||||
local path = fs.combine('packages/' .. dir, 'etc/apps')
|
||||
if fs.exists(path) then
|
||||
local dbs = fs.list(path)
|
||||
for _, db in pairs(dbs) do
|
||||
local apps = Util.readTable(fs.combine(path, db)) or { }
|
||||
Util.merge(applications, apps)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
36
sys/apps/Package.lua
Normal file
36
sys/apps/Package.lua
Normal 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
|
@ -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
|
||||
|
@ -568,10 +568,10 @@ local function shellRead(history)
|
||||
local ie = Input:translate(event, p1, p2, p3)
|
||||
if ie then
|
||||
if ie.code == 'scroll_up' then
|
||||
terminal.scrollUp()
|
||||
--terminal.scrollUp()
|
||||
|
||||
elseif ie.code == 'scroll_down' then
|
||||
terminal.scrollDown()
|
||||
--terminal.scrollDown()
|
||||
|
||||
elseif ie.code == 'terminate' then
|
||||
bExit = true
|
||||
|
@ -11,10 +11,10 @@ end
|
||||
if not fs.exists('usr/autorun') then
|
||||
fs.makeDir('usr/autorun')
|
||||
end
|
||||
if not fs.exists('usr/config/fstab') then
|
||||
Util.writeFile('usr/config/fstab',
|
||||
'usr gitfs kepler155c/opus-apps/' .. _G.OPUS_BRANCH)
|
||||
end
|
||||
--if not fs.exists('usr/config/fstab') then
|
||||
-- Util.writeFile('usr/config/fstab',
|
||||
-- 'usr gitfs kepler155c/opus-apps/' .. _G.OPUS_BRANCH)
|
||||
--end
|
||||
|
||||
if not fs.exists('usr/config/shell') then
|
||||
Util.writeTable('usr/config/shell', {
|
||||
|
@ -26,11 +26,17 @@ end
|
||||
-- https://github.com/mpeterv/depgraph/blob/master/src/depgraph/init.lua
|
||||
|
||||
for name, package in pairs(Packages:installed()) do
|
||||
if package.mount then
|
||||
fs.mount(table.unpack(Util.matches(package.mount)))
|
||||
local packageDir = fs.combine('packages', name)
|
||||
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
|
||||
|
||||
addPath(appPaths, fs.combine('packages', name))
|
||||
addPath(appPaths, packageDir)
|
||||
local apiPath = fs.combine(fs.combine('packages', name), 'apis')
|
||||
if fs.exists(apiPath) then
|
||||
addPath(luaPaths, apiPath)
|
||||
|
@ -1,4 +1,5 @@
|
||||
{
|
||||
[ 'opus-neural' ] = 'file://packages/opus-neural/.package',
|
||||
[ 'opus-miners' ] = 'file://packages/opus-miners/.package',
|
||||
[ 'opus-milo' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/milo/.package',
|
||||
}
|
Loading…
Reference in New Issue
Block a user