opus/sys/boot/opus.boot

78 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
2018-01-21 10:44:13 +00:00
local os = _G.os
2016-12-11 19:24:52 +00:00
2018-01-13 20:17:26 +00:00
local BRANCH = 'develop-1.8'
local GIT_REPO = 'kepler155c/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
sandboxEnv[k] = v
end
2018-01-14 21:44:43 +00:00
sandboxEnv.BRANCH = BRANCH
2018-01-13 20:17:26 +00:00
_G.debug = function() end
2017-09-26 02:49:44 +00:00
local function makeEnv()
2017-09-26 09:34:31 +00:00
local env = setmetatable({ }, { __index = _G })
2017-10-20 08:23:17 +00:00
for k,v in pairs(sandboxEnv) do
2017-10-14 07:41:54 +00:00
env[k] = v
2017-09-25 21:00:02 +00:00
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
local function run(file, ...)
local s, m = loadfile(file, makeEnv())
2017-09-25 21:00:02 +00:00
if s then
2018-01-20 12:18:13 +00:00
return s(...)
2017-09-25 21:00:02 +00:00
end
2017-09-26 19:18:44 +00:00
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, ...)
local url = BASE .. '/' .. file
2017-10-14 07:41:54 +00:00
local u = http.get(url)
if u then
local fn = load(u.readAll(), url, nil, makeEnv())
u.close()
2017-09-26 02:49:44 +00:00
if fn then
return fn(...)
end
end
error('Failed to download ' .. url)
end
2018-01-21 10:44:13 +00:00
function os.getenv(varname)
return sandboxEnv[varname]
end
function os.setenv(varname, value)
sandboxEnv[varname] = value
end
2018-01-20 12:18:13 +00:00
-- Install require shim
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/2.vfs.lua')
2018-01-12 01:53:32 +00:00
2018-01-20 12:18:13 +00:00
-- install file system
fs.mount('', 'gitfs', GIT_REPO)
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-13 20:17:26 +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
fs.restore()
end