Add support for miniupnpd and cjdns
[librecmc/package-feed.git] / net / cjdns / files / cjdrouteconf
1 #!/usr/bin/env lua
2
3 dkjson = require("dkjson")
4 cjdns = require("cjdns")
5 require("cjdns/uci")
6
7 function help()
8   print("JSON interface to /etc/config/cjdns\n\nExamples: \
9     cjdrouteconf get > /tmp/etc/cjdroute.conf \
10     cat /tmp/etc/cjdroute.conf | cjdrouteconf set \
11     uci changes \
12     cjdrouteconf get | cjdroute")
13 end
14
15 if arg[1] == "get" then
16   local json = dkjson.encode(cjdns.uci.get(), { indent = true })
17   print(json)
18 elseif arg[1] == "set" then
19   local json = io.stdin:read("*a")
20   local obj, pos, err = dkjson.decode(json, 1, nil)
21
22   if obj then
23     cjdns.uci.set(obj)
24   else
25     print("dkjson: " .. err .. " (try cjdroute --cleanconf)")
26     os.exit(1)
27   end
28 else
29   help()
30 end