mirror of
				https://github.com/kepler155c/opus
				synced 2025-10-30 23:23:03 +00:00 
			
		
		
		
	better startup
This commit is contained in:
		| @@ -10,7 +10,7 @@ local function runDir(directory, desc, open) | |||||||
|   table.sort(files) |   table.sort(files) | ||||||
|  |  | ||||||
|   for _,file in ipairs(files) do |   for _,file in ipairs(files) do | ||||||
|     print(desc .. file) |     --print(desc .. file) | ||||||
|     os.sleep(0) |     os.sleep(0) | ||||||
|     local result, err = open(directory .. '/' .. file) |     local result, err = open(directory .. '/' .. file) | ||||||
|     if not result then |     if not result then | ||||||
| @@ -23,7 +23,8 @@ local function runDir(directory, desc, open) | |||||||
| end | end | ||||||
|  |  | ||||||
| function Opus.loadExtensions() | function Opus.loadExtensions() | ||||||
|   return runDir('sys/extensions', '[ ext ] ', shell.run) |   --return runDir('sys/extensions', '[ ext ] ', shell.run) | ||||||
|  |   return true | ||||||
| end | end | ||||||
|  |  | ||||||
| function Opus.loadServices() | function Opus.loadServices() | ||||||
|   | |||||||
| @@ -463,9 +463,9 @@ end) | |||||||
| local function startup() | local function startup() | ||||||
|   local hasError |   local hasError | ||||||
|  |  | ||||||
|   if not Opus.loadExtensions() then |   --if not Opus.loadExtensions() then | ||||||
|     hasError = true |   --  hasError = true | ||||||
|   end |   --end | ||||||
|  |  | ||||||
|   local overviewId = multishell.openTab({ |   local overviewId = multishell.openTab({ | ||||||
|     path = 'sys/apps/Overview.lua', |     path = 'sys/apps/Overview.lua', | ||||||
|   | |||||||
| @@ -1,11 +1,13 @@ | |||||||
| local parentShell = shell | local parentShell = shell | ||||||
|  |  | ||||||
| shell = { } | local shell = { } | ||||||
| local sandboxEnv = { } |  | ||||||
|  | local sandboxEnv = setmetatable({ }, { __index = _G }) | ||||||
| for k,v in pairs(getfenv(1)) do | for k,v in pairs(getfenv(1)) do | ||||||
|   sandboxEnv[k] = v  |   sandboxEnv[k] = v  | ||||||
| end | end | ||||||
| setmetatable(sandboxEnv, { __index = _G }) | sandboxEnv.shell = shell | ||||||
|  | sandboxEnv.multishell = multishell or { } | ||||||
|  |  | ||||||
| requireInjector(getfenv(1)) | requireInjector(getfenv(1)) | ||||||
|  |  | ||||||
| @@ -66,7 +68,7 @@ function shell.run(...) | |||||||
|       result, err = os.run(Util.shallowCopy(sandboxEnv), path, unpack(args)) |       result, err = os.run(Util.shallowCopy(sandboxEnv), path, unpack(args)) | ||||||
|     end |     end | ||||||
|  |  | ||||||
|     if multishell then |     if multishell and multishell.getTitle then | ||||||
|       local title = 'shell' |       local title = 'shell' | ||||||
|       if #tProgramStack > 0 then |       if #tProgramStack > 0 then | ||||||
|         title = fs.getName(tProgramStack[#tProgramStack]) |         title = fs.getName(tProgramStack[#tProgramStack]) | ||||||
|   | |||||||
| @@ -1,33 +1,28 @@ | |||||||
| print('\nStarting Opus..') | print('\nStarting Opus..') | ||||||
|  |  | ||||||
| LUA_PATH = '/sys/apis:/usr/apis' | local function run(file, ...) | ||||||
|  |   local env = setmetatable({ | ||||||
| local Util = dofile('sys/apis/util.lua') |     LUA_PATH = '/sys/apis:/usr/apis' | ||||||
| _G.debug = function(...) Util.print(...) end |   }, { __index = _G }) | ||||||
| _G.requireInjector = dofile('sys/apis/injector.lua') |   for k,v in pairs(getfenv(1)) do | ||||||
|  |     env[k] = v  | ||||||
| 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 |  | ||||||
|   end |   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 | end | ||||||
|  |  | ||||||
| pcall(function() | _G.requireInjector = run('sys/apis/injector.lua') | ||||||
|   fs.mount('usr', 'gitfs', 'kepler155c/opus-apps/master') |  | ||||||
| end) |  | ||||||
|  |  | ||||||
| -- user environment | -- user environment | ||||||
| if not fs.exists('usr/apps') then | if not fs.exists('usr/apps') then | ||||||
| @@ -36,9 +31,20 @@ end | |||||||
| if not fs.exists('usr/autorun') then | if not fs.exists('usr/autorun') then | ||||||
|   fs.makeDir('usr/autorun') |   fs.makeDir('usr/autorun') | ||||||
| end | 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)) | local dir = 'sys/extensions' | ||||||
| env.multishell = { } | 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') | fs.loadTab('usr/etc/fstab') | ||||||
| printError(m or 'Multishell aborted') |  | ||||||
|  | local args = { ... } | ||||||
|  | if #args == 0 then | ||||||
|  |   args = { 'sys/apps/shell', 'sys/apps/multishell' } | ||||||
|  | end | ||||||
|  |  | ||||||
|  | run(table.unpack(args)) | ||||||
|   | |||||||
| @@ -284,6 +284,23 @@ function fs.mount(path, fstype, ...) | |||||||
|   return node |   return node | ||||||
| end | 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 function getNodeByParts(parts) | ||||||
|   local node = fs.nodes |   local node = fs.nodes | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 kepler155c@gmail.com
					kepler155c@gmail.com