opus/sys/boot/opus.boot

77 lines
1.6 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
2017-10-14 07:41:54 +00:00
local fs = _G.fs
local http = _G.http
2016-12-11 19:24:52 +00:00
2018-12-08 19:10:46 +00:00
_G.OPUS_BRANCH = 'develop-1.8'
2018-01-26 11:37:49 +00:00
local GIT_REPO = 'kepler155c/opus/' .. _G.OPUS_BRANCH
2017-09-26 02:49:44 +00:00
local BASE = 'https://raw.githubusercontent.com/' .. GIT_REPO
2017-10-20 08:23:17 +00:00
local sandboxEnv = setmetatable({ }, { __index = _G })
for k,v in pairs(_ENV) do
2018-01-24 22:39:38 +00:00
sandboxEnv[k] = v
2017-10-20 08:23:17 +00:00
end
2018-01-13 20:17:26 +00:00
2019-05-03 19:30:09 +00:00
_G._syslog = function() end
2018-01-13 20:17:26 +00:00
2017-09-26 02:49:44 +00:00
local function makeEnv()
2018-01-24 22:39:38 +00:00
local env = setmetatable({ }, { __index = _G })
for k,v in pairs(sandboxEnv) do
env[k] = v
end
return env
2017-09-26 02:49:44 +00:00
end
2016-12-11 19:24:52 +00:00
2017-09-26 02:49:44 +00:00
local function run(file, ...)
2018-01-24 22:39:38 +00:00
local s, m = loadfile(file, makeEnv())
if s then
return s(...)
end
error('Error loading ' .. file .. '\n' .. m)
2016-12-11 19:24:52 +00:00
end
2017-09-26 02:49:44 +00:00
local function runUrl(file, ...)
2018-01-24 22:39:38 +00:00
local url = BASE .. '/' .. file
2017-09-26 02:49:44 +00:00
2018-01-24 22:39:38 +00:00
local u = http.get(url)
if u then
local fn = load(u.readAll(), url, nil, makeEnv())
u.close()
if fn then
return fn(...)
end
end
error('Failed to download ' .. url)
2017-09-26 02:49:44 +00:00
end
2018-01-20 12:18:13 +00:00
-- Install require shim
if fs.exists('sys/modules/opus/injector.lua') then
_G.requireInjector = run('sys/modules/opus/injector.lua')
2018-01-20 12:18:13 +00:00
else
2018-01-24 22:39:38 +00:00
-- not local, run the file system directly from git
2019-02-07 08:10:05 +00:00
if package and package.path then
package.path = package.path .. ';' .. BASE .. '/sys/modules/opus'
2019-02-07 08:10:05 +00:00
else
sandboxEnv.package = {
path = BASE .. '/sys/modules/opus'
2019-02-07 08:10:05 +00:00
}
end
_G.requireInjector = runUrl('sys/modules/opus/injector.lua')
2019-02-07 08:10:05 +00:00
runUrl('sys/init/2.vfs.lua')
2018-01-12 01:53:32 +00:00
2018-01-24 22:39:38 +00:00
-- install file system
fs.mount('', 'gitfs', GIT_REPO)
2018-01-20 12:18:13 +00:00
end
2017-05-20 22:27:26 +00:00
2019-02-12 22:03:50 +00:00
local s, m = pcall(run, 'sys/apps/shell.lua', 'sys/kernel.lua', ...)
2018-01-12 01:53:32 +00:00
if not s then
2018-01-24 22:39:38 +00:00
print('\nError loading Opus OS\n')
_G.printError(m .. '\n')
2018-01-12 01:53:32 +00:00
end
2017-09-26 02:49:44 +00:00
2018-01-13 20:17:26 +00:00
if fs.restore then
2018-01-24 22:39:38 +00:00
fs.restore()
2018-01-13 20:17:26 +00:00
end