1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-10 18:59:55 +00:00

transition to kernel

This commit is contained in:
kepler155c@gmail.com 2018-01-14 16:44:43 -05:00
parent 9de9452dd3
commit 30dd2a2b16
7 changed files with 113 additions and 111 deletions

View File

@ -3,8 +3,6 @@ _G.requireInjector()
local Event = require('event') local Event = require('event')
local Util = require('util') local Util = require('util')
_G.network = { }
local device = _G.device local device = _G.device
local fs = _G.fs local fs = _G.fs
local network = _G.network local network = _G.network

View File

@ -3,7 +3,6 @@ local colors = _G.colors
local fs = _G.fs local fs = _G.fs
local http = _G.http local http = _G.http
local os = _G.os local os = _G.os
local shell = _ENV.shell
local term = _G.term local term = _G.term
local window = _G.window local window = _G.window
@ -16,6 +15,8 @@ for k,v in pairs(_ENV) do
sandboxEnv[k] = v sandboxEnv[k] = v
end end
sandboxEnv.multishell = { } sandboxEnv.multishell = { }
sandboxEnv.BRANCH = BRANCH
sandboxEnv.LUA_PATH = 'sys/apis:usr/apis'
_G.debug = function() end _G.debug = function() end
@ -64,24 +65,6 @@ local function splash()
return splashWindow return splashWindow
end end
local function setLabel()
-- Default label
if not os.getComputerLabel() then
showStatus('Setting computer label')
local id = os.getComputerID()
if _G.turtle then
os.setComputerLabel('turtle_' .. id)
elseif _G.pocket then
os.setComputerLabel('pocket_' .. id)
elseif _G.commands then
os.setComputerLabel('command_' .. id)
else
os.setComputerLabel('computer_' .. id)
end
end
end
local function makeEnv() local function makeEnv()
local env = setmetatable({ }, { __index = _G }) local env = setmetatable({ }, { __index = _G })
for k,v in pairs(sandboxEnv) do for k,v in pairs(sandboxEnv) do
@ -115,62 +98,6 @@ local function runUrl(file, ...)
error('Failed to download ' .. url) error('Failed to download ' .. url)
end end
local function createUserEnvironment(Util)
showStatus('Creating user environment')
if not fs.exists('usr/apps') then
fs.makeDir('usr/apps')
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/' .. BRANCH)
end
end
local function createShellEnvironment(Util)
showStatus('Creating shell environment')
if not fs.exists('usr/config/shell') then
Util.writeTable('usr/config/shell', {
aliases = shell.aliases(),
path = 'usr/apps:sys/apps:' .. shell.path(),
lua_path = '/sys/apis:/usr/apis',
})
end
local config = Util.readTable('usr/config/shell')
if config.aliases then
for k in pairs(shell.aliases()) do
shell.clearAlias(k)
end
for k,v in pairs(config.aliases) do
shell.setAlias(k, v)
end
end
shell.setPath(config.path)
sandboxEnv.LUA_PATH = config.lua_path
end
local function loadExtensions()
local dir = 'sys/extensions'
local files = fs.list(dir)
table.sort(files)
for _,file in ipairs(files) do
showStatus('Loading ' .. file)
local s, m = kernel.run({
title = file:match('%d.(%S+).lua'),
hidden = true,
path = 'sys/apps/shell',
args = { fs.combine(dir, file) },
terminal = kernelWindow,
})
if not s then
error(m)
end
end
end
local args = { ... } local args = { ... }
@ -184,39 +111,32 @@ local s, m = pcall(function()
else else
-- not local, run the file system directly from git -- not local, run the file system directly from git
_G.requireInjector = runUrl('sys/apis/injector.lua') _G.requireInjector = runUrl('sys/apis/injector.lua')
runUrl('sys/extensions/vfs.lua') runUrl('sys/extensions/2.vfs.lua')
-- install file system -- install file system
fs.mount('', 'gitfs', GIT_REPO) fs.mount('', 'gitfs', GIT_REPO)
end end
_G.requireInjector() showStatus('Starting kernel')
local Util = require('util') run('sys/apps/shell', 'sys/kernel.lua', args[1] and 6 or 7)
setLabel()
createUserEnvironment(Util)
createShellEnvironment(Util)
showStatus('Reticulating splines')
Util.run(makeEnv(), 'sys/kernel.lua')
loadExtensions()
showStatus('Mounting file systems')
fs.loadTab('usr/etc/fstab')
splashWindow.setVisible(false)
if args[1] then if args[1] then
kernelWindow.setVisible(true) local s, m = kernel.run({
kernelWindow.setVisible(false) title = 'startup',
path = 'sys/apps/shell',
args = args,
haltOnExit = true,
})
if s then
kernel.raise(s.uid)
else
error(m)
end
end end
term.redirect(terminal) splashWindow.setVisible(false)
kernelWindow.setVisible(true)
_G.kernel.run({ _G.kernel.start()
path = 'sys/apps/shell',
args = args[1] and args or { 'sys/apps/multishell' },
})
end) end)
if not s then if not s then
@ -224,10 +144,7 @@ if not s then
kernelWindow.setVisible(true) kernelWindow.setVisible(true)
print('\nError loading Opus OS\n') print('\nError loading Opus OS\n')
_G.printError(m .. '\n') _G.printError(m .. '\n')
else term.redirect(terminal)
if _G.kernel.routines[1] then
_G.kernel.start()
end
end end
if fs.restore then if fs.restore then

View File

@ -1,11 +1,21 @@
local kernel = _G.kernel local kernel = _G.kernel
_G.network = { }
local function startNetwork()
kernel.run({
title = 'Net daemon',
path = 'sys/apps/netdaemon.lua',
hidden = true,
})
end
kernel.hook('device_attach', function(_, eventData) kernel.hook('device_attach', function(_, eventData)
if eventData[1] == 'wireless_modem' then if eventData[1] == 'wireless_modem' then
kernel.run({ startNetwork()
title = 'Net daemon',
path = 'sys/extensions/netdaemon.lua',
hidden = true,
})
end end
end) end)
if _G.device.wireless_modem then
startNetwork()
end

View File

@ -0,0 +1,15 @@
-- Default label
if not os.getComputerLabel() then
showStatus('Setting computer label')
local id = os.getComputerID()
if _G.turtle then
os.setComputerLabel('turtle_' .. id)
elseif _G.pocket then
os.setComputerLabel('pocket_' .. id)
elseif _G.commands then
os.setComputerLabel('command_' .. id)
else
os.setComputerLabel('computer_' .. id)
end
end

38
sys/extensions/4.user.lua Normal file
View File

@ -0,0 +1,38 @@
_G.requireInjector()
local Util = require('util')
local fs = _G.fs
local shell = _ENV.shell
if not fs.exists('usr/apps') then
fs.makeDir('usr/apps')
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/' .. _ENV.BRANCH)
end
if not fs.exists('usr/config/shell') then
Util.writeTable('usr/config/shell', {
aliases = shell.aliases(),
path = 'usr/apps:sys/apps:' .. shell.path(),
lua_path = 'sys/apis:usr/apis',
})
end
local config = Util.readTable('usr/config/shell')
if config.aliases then
for k in pairs(shell.aliases()) do
shell.clearAlias(k)
end
for k,v in pairs(config.aliases) do
shell.setAlias(k, v)
end
end
shell.setPath(config.path)
--sandboxEnv.LUA_PATH = config.lua_path
fs.loadTab('usr/etc/fstab')

View File

@ -14,7 +14,7 @@ local shell = _ENV.shell
local term = _G.term local term = _G.term
local window = _G.window local window = _G.window
local parentTerm = kernel.terminal.parent -- term.current() local parentTerm = _G.device.terminal -- term.current()
local w,h = parentTerm.getSize() local w,h = parentTerm.getSize()
local overviewId local overviewId
local tabsDirty = false local tabsDirty = false
@ -378,6 +378,7 @@ end
overviewId = multishell.openTab({ overviewId = multishell.openTab({
path = 'sys/apps/Overview.lua', path = 'sys/apps/Overview.lua',
isOverview = true, isOverview = true,
focusd = true,
}) })
kernel.find(overviewId).title = '+' kernel.find(overviewId).title = '+'

View File

@ -15,6 +15,7 @@ _G.kernel = {
window = _G.term.current(), window = _G.term.current(),
} }
local fs = _G.fs
local kernel = _G.kernel local kernel = _G.kernel
local os = _G.os local os = _G.os
local term = _G.term local term = _G.term
@ -86,6 +87,9 @@ function Routine:resume(event, ...)
if #kernel.routines > 0 then if #kernel.routines > 0 then
os.queueEvent('kernel_focus', kernel.routines[1].uid) os.queueEvent('kernel_focus', kernel.routines[1].uid)
end end
if self.haltOnExit then
kernel.halt()
end
end end
return ok, result return ok, result
end end
@ -229,3 +233,22 @@ function kernel.start()
end end
term.redirect(kernel.terminal) term.redirect(kernel.terminal)
end end
local function loadExtensions(runLevel)
local dir = 'sys/extensions'
local files = fs.list(dir)
table.sort(files)
for _,file in ipairs(files) do
local level, name = file:match('(%d).(%S+).lua')
--print(name)
if tonumber(level) <= runLevel then
local s, m = shell.run(fs.combine(dir, file))
if not s then
error(m)
end
end
end
end
local args = { ... }
loadExtensions(args[1] and tonumber(args[1]) or 7)