summaryrefslogtreecommitdiffstats
path: root/cjdns/files/cjdrouteconf
blob: fa5e0735d0ca681a8fab57c12ff7930fddd53217 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env lua

dkjson = require("dkjson")
cjdns = require("cjdns")
require("cjdns/uci")

function help()
  print("JSON interface to /etc/config/cjdns\n\nExamples: \
    cjdrouteconf get > /tmp/etc/cjdroute.conf \
    cat /tmp/etc/cjdroute.conf | cjdrouteconf set \
    uci changes \
    cjdrouteconf get | cjdroute")
end

if arg[1] == "get" then
  local json = dkjson.encode(cjdns.uci.get(), { indent = true })
  print(json)
elseif arg[1] == "set" then
  local json = io.stdin:read("*a")
  local obj, pos, err = dkjson.decode(json, 1, nil)

  if obj then
    cjdns.uci.set(obj)
  else
    print("dkjson: " .. err .. " (try cjdroute --cleanconf)")
    os.exit(1)
  end
else
  help()
end