opus/sys/boot/multishell.boot

125 lines
2.8 KiB
Plaintext
Raw Normal View History

2017-09-26 02:49:44 +00:00
-- Loads the Opus environment regardless if the file system is local or not
2016-12-11 19:24:52 +00:00
2017-09-26 02:49:44 +00:00
local w, h = term.getSize()
2017-09-26 05:40:02 +00:00
local str = 'Loading Opus...'
2017-09-26 02:49:44 +00:00
term.setTextColor(colors.white)
2017-09-26 03:18:36 +00:00
if term.isColor() then
term.setBackgroundColor(colors.cyan)
2017-09-26 05:40:02 +00:00
term.clear()
local opus = {
'9999900',
'999907000',
'9900770b00 4444',
'99077777444444444',
'907777744444444444',
'90000777444444444',
'070000111744444',
'777770000',
'7777000000',
'70700000000',
'077000000000',
}
for k,line in ipairs(opus) do
term.setCursorPos((w - 18) / 2, k + (h - #opus) / 2)
term.blit(string.rep(' ', #line), string.rep('a', #line), line)
end
2017-09-26 03:18:36 +00:00
end
2017-09-26 05:40:02 +00:00
term.setCursorPos((w - #str) / 2, h)
2017-09-26 02:49:44 +00:00
term.write(str)
2017-09-26 05:40:02 +00:00
term.setCursorPos(w, h)
2017-09-26 02:49:44 +00:00
local GIT_REPO = 'kepler155c/opus/develop'
local BASE = 'https://raw.githubusercontent.com/' .. GIT_REPO
local function makeEnv()
2017-09-25 21:00:02 +00:00
local env = setmetatable({
LUA_PATH = '/sys/apis:/usr/apis'
}, { __index = _G })
for k,v in pairs(getfenv(1)) do
env[k] = v
end
2017-09-26 02:49:44 +00:00
return env
end
2016-12-11 19:24:52 +00:00
2017-09-26 02:49:44 +00:00
-- os.run doesn't provide return values :(
local function run(file, ...)
local s, m = loadfile(file, makeEnv())
2017-09-25 21:00:02 +00:00
if s then
local args = { ... }
s, m = pcall(function()
return s(table.unpack(args))
end)
end
2016-12-11 19:24:52 +00:00
2017-09-25 21:00:02 +00:00
if not s then
2017-09-26 05:40:02 +00:00
-- term.setBackgroundColor(colors.black)
-- term.clear()
2017-09-25 21:07:18 +00:00
printError('Error loading ' .. file)
error(m)
2016-12-11 19:24:52 +00:00
end
2017-09-25 21:00:02 +00:00
return m
2016-12-11 19:24:52 +00:00
end
2017-09-26 02:49:44 +00:00
local function runUrl(file, ...)
local url = BASE .. '/' .. file
local h = http.get(url)
if h then
local fn, m = load(h.readAll(), url, nil, makeEnv())
h.close()
if fn then
return fn(...)
end
end
2017-09-26 05:40:02 +00:00
-- term.setBackgroundColor(colors.black)
-- term.clear()
2017-09-26 02:49:44 +00:00
error('Failed to download ' .. url)
end
2017-09-25 21:14:08 +00:00
shell.setPath('usr/apps:sys/apps:' .. shell.path())
2017-09-15 05:08:04 +00:00
2017-09-26 02:49:44 +00:00
if fs.exists('sys/apis/injector.lua') then
_G.requireInjector = run('sys/apis/injector.lua')
else
-- not local, run the file system directly from git
_G.requireInjector = runUrl('/sys/apis/injector.lua')
runUrl('/sys/extensions/vfs.lua')
-- install file system
fs.mount('', 'gitfs', GIT_REPO)
end
2017-05-20 22:27:26 +00:00
-- 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
2017-09-25 21:00:02 +00:00
if not fs.exists('usr/etc/fstab') then
2017-09-25 21:02:28 +00:00
local file = io.open('usr/etc/fstab', "w")
file:write('usr gitfs kepler155c/opus-apps/master')
file:close()
2017-09-25 21:00:02 +00:00
end
2017-09-26 02:49:44 +00:00
-- extensions
2017-09-25 21:00:02 +00:00
local dir = 'sys/extensions'
for _,file in ipairs(fs.list(dir)) do
run('sys/apps/shell', fs.combine(dir, file))
end
2017-05-20 22:27:26 +00:00
2017-09-26 02:49:44 +00:00
-- install user file systems
2017-09-25 21:00:02 +00:00
fs.loadTab('usr/etc/fstab')
local args = { ... }
2017-09-26 02:49:44 +00:00
if args[1] then
term.setBackgroundColor(colors.black)
term.clear()
term.setCursorPos(1, 1)
end
2017-09-25 21:10:24 +00:00
args[1] = args[1] or 'sys/apps/multishell'
run('sys/apps/shell', table.unpack(args))
2017-09-26 02:49:44 +00:00
fs.restore()