2020-05-18 01:36:33 +00:00
|
|
|
local fs = _G.fs
|
|
|
|
local os = _G.os
|
2019-07-01 21:22:19 +00:00
|
|
|
|
|
|
|
fs.loadTab('sys/etc/fstab')
|
2020-05-18 01:36:33 +00:00
|
|
|
|
|
|
|
-- add some Lua compatibility functions
|
|
|
|
function os.remove(a)
|
|
|
|
if fs.exists(a) then
|
2020-05-19 23:09:10 +00:00
|
|
|
local s = pcall(fs.delete, a)
|
|
|
|
return s and true or nil, a .. ': Unable to remove file'
|
2020-05-18 01:36:33 +00:00
|
|
|
end
|
|
|
|
return nil, a .. ': No such file or directory'
|
|
|
|
end
|
|
|
|
|
|
|
|
os.execute = function(cmd)
|
2020-05-19 23:09:10 +00:00
|
|
|
local env = _G.getfenv(2)
|
|
|
|
if not cmd then
|
|
|
|
return env.shell and 1 or 0
|
|
|
|
end
|
|
|
|
|
|
|
|
if not env.shell then
|
|
|
|
return 0
|
|
|
|
end
|
2020-05-18 01:36:33 +00:00
|
|
|
|
2020-05-19 23:09:10 +00:00
|
|
|
local s, m = env.shell.run('sys/apps/shell.lua ' .. cmd)
|
2020-05-18 01:36:33 +00:00
|
|
|
|
2020-05-19 23:09:10 +00:00
|
|
|
if not s then
|
|
|
|
return 1, m
|
|
|
|
end
|
2020-05-18 01:36:33 +00:00
|
|
|
|
2020-05-19 23:09:10 +00:00
|
|
|
return 0
|
2020-05-18 01:36:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
os.tmpname = function()
|
2020-05-19 23:09:10 +00:00
|
|
|
local fname
|
|
|
|
repeat
|
|
|
|
fname = 'tmp/a' .. math.random(1, 32768)
|
|
|
|
until not fs.exists(fname)
|
2020-05-18 01:36:33 +00:00
|
|
|
|
2020-05-19 23:09:10 +00:00
|
|
|
return fname
|
2020-05-18 01:36:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- non-standard - will raise error instead
|
|
|
|
os.exit = function(code)
|
2020-05-26 03:48:37 +00:00
|
|
|
error(code or 0)
|
2020-06-01 22:53:01 +00:00
|
|
|
end
|