better startup

This commit is contained in:
kepler155c@gmail.com 2017-09-25 17:00:02 -04:00
parent 3c2892074a
commit f325550de2
5 changed files with 64 additions and 38 deletions

View File

@ -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()

View File

@ -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',

View File

@ -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])

View File

@ -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))

View File

@ -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