diff --git a/sys/apis/git.lua b/sys/apis/git.lua index 67f27b3..ca4a870 100644 --- a/sys/apis/git.lua +++ b/sys/apis/git.lua @@ -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 diff --git a/sys/apis/packages.lua b/sys/apis/packages.lua index c3b4473..7fdc982 100644 --- a/sys/apis/packages.lua +++ b/sys/apis/packages.lua @@ -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 diff --git a/sys/apis/util.lua b/sys/apis/util.lua index 41a3f1c..9fe0111 100644 --- a/sys/apis/util.lua +++ b/sys/apis/util.lua @@ -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 diff --git a/sys/apps/Overview.lua b/sys/apps/Overview.lua index 0b95299..30fb9fd 100644 --- a/sys/apps/Overview.lua +++ b/sys/apps/Overview.lua @@ -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 diff --git a/sys/apps/Package.lua b/sys/apps/Package.lua new file mode 100644 index 0000000..48b87f9 --- /dev/null +++ b/sys/apps/Package.lua @@ -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 diff --git a/sys/apps/Packages.lua b/sys/apps/Packages.lua deleted file mode 100644 index 14e5c5b..0000000 --- a/sys/apps/Packages.lua +++ /dev/null @@ -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 - diff --git a/sys/apps/shell b/sys/apps/shell index 6aaaed7..31ce233 100644 --- a/sys/apps/shell +++ b/sys/apps/shell @@ -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 diff --git a/sys/extensions/4.user.lua b/sys/extensions/4.user.lua index 7688c4c..e7dfa61 100644 --- a/sys/extensions/4.user.lua +++ b/sys/extensions/4.user.lua @@ -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', { diff --git a/sys/extensions/6.packages.lua b/sys/extensions/6.packages.lua index 3f46c7e..458be13 100644 --- a/sys/extensions/6.packages.lua +++ b/sys/extensions/6.packages.lua @@ -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) diff --git a/sys/packageList.lua b/sys/packageList.lua index 622f2c1..07c0821 100644 --- a/sys/packageList.lua +++ b/sys/packageList.lua @@ -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', } \ No newline at end of file