mirror of
https://github.com/kepler155c/opus
synced 2025-10-22 19:27:42 +00:00
package manager
This commit is contained in:
@@ -82,7 +82,7 @@ local function loadApplications()
|
||||
end
|
||||
end
|
||||
|
||||
return true -- Util.startsWidth(a.run, 'http') or shell.resolveProgram(a.run)
|
||||
return true -- Util.startsWith(a.run, 'http') or shell.resolveProgram(a.run)
|
||||
end)
|
||||
end
|
||||
|
||||
|
@@ -1,9 +1,11 @@
|
||||
_G.requireInjector(_ENV)
|
||||
|
||||
local Git = require('git')
|
||||
local Packages = require('packages')
|
||||
local Util = require('util')
|
||||
|
||||
local fs = _G.fs
|
||||
local fs = _G.fs
|
||||
local term = _G.term
|
||||
|
||||
local args = { ... }
|
||||
local action = table.remove(args, 1)
|
||||
@@ -16,6 +18,47 @@ if action == 'list' then
|
||||
for k in pairs(Packages:list()) do
|
||||
Util.print('[%s] %s', Packages:isInstalled(k) and 'x' or ' ', k)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local function progress(max)
|
||||
-- modified from: https://pastebin.com/W5ZkVYSi (apemanzilla)
|
||||
local _, y = term.getCursorPos()
|
||||
local wide, _ = term.getSize()
|
||||
term.setCursorPos(1, y)
|
||||
term.write("[")
|
||||
term.setCursorPos(wide - 6, y)
|
||||
term.write("]")
|
||||
local done = 0
|
||||
return function()
|
||||
done = done + 1
|
||||
local value = done / max
|
||||
term.setCursorPos(2,y)
|
||||
term.write(("="):rep(math.floor(value * (wide - 8))))
|
||||
local percent = math.floor(value * 100) .. "%"
|
||||
term.setCursorPos(wide - percent:len(),y)
|
||||
term.write(percent)
|
||||
end
|
||||
end
|
||||
|
||||
local function install(name)
|
||||
local manifest = Packages:getManifest(name) or error('Invalid package')
|
||||
local packageDir = fs.combine('packages', name)
|
||||
local method = args[2] or 'local'
|
||||
if method == 'remote' then
|
||||
Util.writeTable(packageDir .. '/.install', {
|
||||
mount = string.format('%s gitfs %s', packageDir, manifest.repository),
|
||||
})
|
||||
Util.writeTable(fs.combine(packageDir, '.package'), manifest)
|
||||
else
|
||||
local list = Git.list(manifest.repository)
|
||||
local showProgress = progress(Util.size(list))
|
||||
for path, entry in pairs(list) do
|
||||
Util.download(entry.url, fs.combine(packageDir, path))
|
||||
showProgress()
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if action == 'install' then
|
||||
@@ -23,14 +66,30 @@ if action == 'install' then
|
||||
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
|
||||
install(name)
|
||||
print('installation complete')
|
||||
return
|
||||
end
|
||||
|
||||
if action == 'update' then
|
||||
local name = args[1] or Syntax('Invalid package')
|
||||
if not Packages:isInstalled(name) then
|
||||
error('Package is not installed')
|
||||
end
|
||||
install(name)
|
||||
print('update complete')
|
||||
return
|
||||
end
|
||||
|
||||
if action == 'uninstall' then
|
||||
local name = args[1] or Syntax('Invalid package')
|
||||
if not Packages:isInstalled(name) then
|
||||
error('Package is not installed')
|
||||
end
|
||||
local packageDir = fs.combine('packages', name)
|
||||
fs.delete(packageDir)
|
||||
print('removed: ' .. packageDir)
|
||||
return
|
||||
end
|
||||
|
||||
error('Syntax: Package [list | install [name] ... | update [name] | uninstall [name]')
|
||||
|
Reference in New Issue
Block a user