and_cesbo

Astra. Import config to Astra 5

Apr 27th, 2016
804
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.95 KB | None | 0 0
  1. --
  2. -- Installation:
  3. -- 1. Install Astra: https://cesbo.com/astra/quick-start/
  4. -- 2. Save script into /etc/astra/import.lua
  5. --
  6. -- Usage:
  7. -- astra /etc/astra/import.lua file ...
  8. -- Script reads files sequentially and writes it into /tmp/astra-import.conf
  9. -- If file exists script appends new config to it
  10. --
  11.  
  12. output = "/tmp/astra-import.conf"
  13.  
  14. scripts = {}
  15. config = {}
  16. options = {
  17.     ["*"] = function(idx)
  18.         local filename = argv[idx]
  19.         if utils.stat(filename).type == "file" then
  20.             table.insert(scripts, argv[idx])
  21.         end
  22.         return 0
  23.     end,
  24. }
  25.  
  26. function import()
  27.     if #scripts == 0 then
  28.         if #config.dvb_tune == 0 then config.dvb_tune = nil end
  29.         if #config.softcam == 0 then config.softcam = nil end
  30.         if #config.make_stream == 0 then config.make_stream = nil end
  31.  
  32.         json.save(output, config)
  33.  
  34.         log.info("done")
  35.         astra.exit()
  36.         return nil
  37.     end
  38.  
  39.     local s = table.remove(scripts, 1)
  40.     local f = io.open(s, "r")
  41.     local c = f:read("*all")
  42.     f:close()
  43.  
  44.     local r = import_config({ gid = config.gid, data = c })
  45.     if r.error then
  46.         log.error(s .. ": " .. r.error)
  47.         astra.exit()
  48.         return nil
  49.     end
  50.  
  51.     config.gid = r.gid
  52.  
  53.     local function table_merge(key)
  54.         local src = r[key]
  55.         local dst = config[key]
  56.         if src then
  57.             for _,x in ipairs(src) do
  58.                 table.insert(dst, x)
  59.             end
  60.         end
  61.     end
  62.  
  63.     table_merge("dvb_tune")
  64.     table_merge("softcam")
  65.     table_merge("make_stream")
  66.  
  67.     import()
  68. end
  69.  
  70. function main()
  71.     if utils.stat(output).type == "file" then
  72.         config = json.load(output)
  73.     end
  74.  
  75.     if not config.gid then config.gid = 466560 end
  76.     if not config.make_stream then config.make_stream = {} end
  77.     if not config.dvb_tune then config.dvb_tune = {} end
  78.     if not config.softcam then config.softcam = {} end
  79.  
  80.     import()
  81. end
Advertisement
Add Comment
Please, Sign In to add comment