Merged revisions 115884 via svnmerge from
[asterisk-bristuff.git] / utils / build-extensions-conf.lua
bloba3f159def9450fa497bcf2056e7c06c587183e0b
1 #!/usr/bin/env lua
2 --[[
4 This utility can be used to generate an extensions.conf file to match an
5 existing extensions.lua file. As an argument it takes the patch of the
6 extensions.lua file to read from, otherwise it uses
7 /etc/asterisk/extensions.lua.
9 This script can also be used to automatically include extensions.lua in
10 extensions.conf via a #exec as well.
12 #exec /usr/bin/build-extensions-conf.lua -c
14 --]]
16 usage = [[
18 Usage:
19 ]] .. arg[0] .. [[ [options] [extensions.lua path]
21 This utility can generate an extensions.conf file with all of the contexts in
22 your extensions.lua file defined as including the Lua switch. This is useful
23 if you want to use your extensions.lua file exclusively. By using this utility
24 you dont't have to create each extension in extensions.conf manually.
26 The resulting extensions.conf file is printed to standard output.
28 --contexts-only, -c Don't print the [global] or [general] sections. This
29 is useful for including the generated file into an
30 existing extensions.conf via #include or #exec.
32 --help, -h Print this message.
36 extensions_file = "/etc/asterisk/extensions.lua"
38 options = {}
40 for k, v in ipairs(arg) do
41 if v:sub(1, 1) == "-" then
42 if v == "-h" or v == "--help" then
43 print("match")
44 options["help"] = true
45 elseif v == "-c" or v == "--contexts-only" then
46 options["contexts-only"] = true
47 end
48 else
49 options["extensions-file"] = v
50 end
51 end
53 if options["help"] then
54 io.stderr:write(usage)
55 os.exit(0)
56 end
58 if options["extensions-file"] then
59 extensions_file = options["extensions-file"]
60 end
62 result, error_message = pcall(dofile, extensions_file)
64 if not result then
65 io.stderr:write(error_message .. "\n")
66 os.exit(1)
67 end
69 if not extensions then
70 io.stderr:write("Error: extensions table not found in '" .. extensions_file .. "'\n")
71 os.exit(1)
72 end
74 if not options["contexts-only"] then
75 io.stdout:write("[general]\n\n[globals]\n\n")
76 end
78 for context, extens in pairs(extensions) do
79 io.stdout:write("[" .. tostring(context) .. "]\nswitch => Lua\n\n")
80 end