cjdrouteconf 691 B

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