1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-10 10:49:55 +00:00
opus/sys/apps/autorun.lua

71 lines
1.4 KiB
Lua
Raw Normal View History

local Packages = require('opus.packages')
2019-03-27 19:21:31 +00:00
local colors = _G.colors
local fs = _G.fs
local keys = _G.keys
local multishell = _ENV.multishell
local os = _G.os
local shell = _ENV.shell
local term = _G.term
local success = true
local function runDir(directory)
2019-06-18 19:19:24 +00:00
if not fs.exists(directory) then
return true
end
2019-03-27 19:21:31 +00:00
2019-06-18 19:19:24 +00:00
local files = fs.list(directory)
table.sort(files)
2019-03-27 19:21:31 +00:00
2019-06-18 19:19:24 +00:00
for _,file in ipairs(files) do
os.sleep(0)
local result, err = shell.run(directory .. '/' .. file)
2019-03-27 19:21:31 +00:00
2019-06-18 19:19:24 +00:00
if result then
if term.isColor() then
term.setTextColor(colors.green)
end
term.write('[PASS] ')
term.setTextColor(colors.white)
term.write(fs.combine(directory, file))
print()
else
if term.isColor() then
term.setTextColor(colors.red)
end
term.write('[FAIL] ')
term.setTextColor(colors.white)
term.write(fs.combine(directory, file))
if err then
_G.printError('\n' .. err)
end
print()
success = false
end
end
2019-03-27 19:21:31 +00:00
end
runDir('sys/autorun')
for name in pairs(Packages:installed()) do
2019-06-18 19:19:24 +00:00
local packageDir = 'packages/' .. name .. '/autorun'
runDir(packageDir)
2019-03-27 19:21:31 +00:00
end
runDir('usr/autorun')
if not success then
2019-06-18 19:19:24 +00:00
if multishell then
multishell.setFocus(multishell.getCurrent())
end
_G.printError('A startup program has errored')
print('Press enter to continue')
2019-03-27 19:21:31 +00:00
2019-06-18 19:19:24 +00:00
while true do
local e, code = os.pullEventRaw('key')
if e == 'terminate' or e == 'key' and code == keys.enter then
break
end
end
2019-03-27 19:21:31 +00:00
end