1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-17 14:14:50 +00:00
opus/sys/boot/opus.boot

68 lines
1.4 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-03-30 17:12: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
_G.debug = function() end
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/apis/injector.lua') then
2018-01-24 22:39:38 +00:00
_G.requireInjector = run('sys/apis/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
_G.requireInjector = runUrl('sys/apis/injector.lua')
runUrl('sys/extensions/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
2018-01-20 12:18:13 +00:00
local s, m = pcall(run, 'sys/apps/shell', '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