--
-- Installation:
-- 1. Install Astra: https://cesbo.com/astra/quick-start/
-- 2. Save script into /etc/astra/import.lua
--
-- Usage:
-- astra /etc/astra/import.lua file ...
-- Script reads files sequentially and writes it into /tmp/astra-import.conf
-- If file exists script appends new config to it
--
output = "/tmp/astra-import.conf"
scripts = {}
config = {}
options = {
["*"] = function(idx)
local filename = argv[idx]
if utils.stat(filename).type == "file" then
table.insert(scripts, argv[idx])
end
return 0
end,
}
function import()
if #scripts == 0 then
if #config.dvb_tune == 0 then config.dvb_tune = nil end
if #config.softcam == 0 then config.softcam = nil end
if #config.make_stream == 0 then config.make_stream = nil end
json.save(output, config)
log.info("done")
astra.exit()
return nil
end
local s = table.remove(scripts, 1)
local f = io.open(s, "r")
local c = f:read("*all")
f:close()
local r = import_config({ gid = config.gid, data = c })
if r.error then
log.error(s .. ": " .. r.error)
astra.exit()
return nil
end
config.gid = r.gid
local function table_merge(key)
local src = r[key]
local dst = config[key]
if src then
for _,x in ipairs(src) do
table.insert(dst, x)
end
end
end
table_merge("dvb_tune")
table_merge("softcam")
table_merge("make_stream")
import()
end
function main()
if utils.stat(output).type == "file" then
config = json.load(output)
end
if not config.gid then config.gid = 466560 end
if not config.make_stream then config.make_stream = {} end
if not config.dvb_tune then config.dvb_tune = {} end
if not config.softcam then config.softcam = {} end
import()
end
Comments