diff --git a/sys/apis/opus.lua b/sys/apis/opus.lua index 11d0baa..c5e359e 100644 --- a/sys/apis/opus.lua +++ b/sys/apis/opus.lua @@ -10,7 +10,7 @@ local function runDir(directory, desc, open) table.sort(files) for _,file in ipairs(files) do - print(desc .. file) + --print(desc .. file) os.sleep(0) local result, err = open(directory .. '/' .. file) if not result then @@ -23,7 +23,8 @@ local function runDir(directory, desc, open) end function Opus.loadExtensions() - return runDir('sys/extensions', '[ ext ] ', shell.run) + --return runDir('sys/extensions', '[ ext ] ', shell.run) + return true end function Opus.loadServices() diff --git a/sys/apps/multishell b/sys/apps/multishell index 43f5d99..304fe65 100644 --- a/sys/apps/multishell +++ b/sys/apps/multishell @@ -463,9 +463,9 @@ end) local function startup() local hasError - if not Opus.loadExtensions() then - hasError = true - end + --if not Opus.loadExtensions() then + -- hasError = true + --end local overviewId = multishell.openTab({ path = 'sys/apps/Overview.lua', diff --git a/sys/apps/shell b/sys/apps/shell index c4c0d8e..630d2f6 100644 --- a/sys/apps/shell +++ b/sys/apps/shell @@ -1,11 +1,13 @@ local parentShell = shell -shell = { } -local sandboxEnv = { } +local shell = { } + +local sandboxEnv = setmetatable({ }, { __index = _G }) for k,v in pairs(getfenv(1)) do sandboxEnv[k] = v end -setmetatable(sandboxEnv, { __index = _G }) +sandboxEnv.shell = shell +sandboxEnv.multishell = multishell or { } requireInjector(getfenv(1)) @@ -66,7 +68,7 @@ function shell.run(...) result, err = os.run(Util.shallowCopy(sandboxEnv), path, unpack(args)) end - if multishell then + if multishell and multishell.getTitle then local title = 'shell' if #tProgramStack > 0 then title = fs.getName(tProgramStack[#tProgramStack]) diff --git a/sys/boot/multishell.boot b/sys/boot/multishell.boot index 1e1746d..c97177a 100644 --- a/sys/boot/multishell.boot +++ b/sys/boot/multishell.boot @@ -1,33 +1,28 @@ print('\nStarting Opus..') -LUA_PATH = '/sys/apis:/usr/apis' - -local Util = dofile('sys/apis/util.lua') -_G.debug = function(...) Util.print(...) end -_G.requireInjector = dofile('sys/apis/injector.lua') - -os.run(Util.shallowCopy(getfenv(1)), 'sys/extensions/device.lua') - --- vfs -local s, m = os.run(Util.shallowCopy(getfenv(1)), 'sys/extensions/vfs.lua') -if not s then - error(m) -end - --- process fstab -local mounts = Util.readFile('usr/etc/fstab') -if mounts then - for _,l in ipairs(Util.split(mounts)) do - if l:sub(1, 1) ~= '#' then - print('mounting ' .. l) - fs.mount(unpack(Util.matches(l))) - end +local function run(file, ...) + local env = setmetatable({ + LUA_PATH = '/sys/apis:/usr/apis' + }, { __index = _G }) + for k,v in pairs(getfenv(1)) do + env[k] = v end + + local s, m = loadfile(file, env) + if s then + local args = { ... } + s, m = pcall(function() + return s(table.unpack(args)) + end) + end + + if not s then + error(m or ('Error running ' .. file)) + end + return m end -pcall(function() - fs.mount('usr', 'gitfs', 'kepler155c/opus-apps/master') -end) +_G.requireInjector = run('sys/apis/injector.lua') -- user environment if not fs.exists('usr/apps') then @@ -36,9 +31,20 @@ end if not fs.exists('usr/autorun') then fs.makeDir('usr/autorun') end +if not fs.exists('usr/etc/fstab') then + Util.writeFile('usr/etc/fstab', 'usr gitfs kepler155c/opus-apps/master') +end -local env = Util.shallowCopy(getfenv(1)) -env.multishell = { } +local dir = 'sys/extensions' +for _,file in ipairs(fs.list(dir)) do + run('sys/apps/shell', fs.combine(dir, file)) +end -local _, m = os.run(env, 'sys/apps/shell', 'sys/apps/multishell') -printError(m or 'Multishell aborted') +fs.loadTab('usr/etc/fstab') + +local args = { ... } +if #args == 0 then + args = { 'sys/apps/shell', 'sys/apps/multishell' } +end + +run(table.unpack(args)) diff --git a/sys/extensions/vfs.lua b/sys/extensions/vfs.lua index 84fe862..186a928 100644 --- a/sys/extensions/vfs.lua +++ b/sys/extensions/vfs.lua @@ -284,6 +284,23 @@ function fs.mount(path, fstype, ...) return node end +function fs.loadTab(path) + local mounts = Util.readFile(path) + if mounts then + for _,l in ipairs(Util.split(mounts)) do + if l:sub(1, 1) ~= '#' then + local s, m = pcall(function() + fs.mount(table.unpack(Util.matches(l))) + end) + if not s then + printError('Mount failed') + printError(l) + end + end + end + end +end + local function getNodeByParts(parts) local node = fs.nodes