apply_config 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/lua
  2. require("uci")
  3. require("uci.trigger")
  4. function usage()
  5. print("Usage: " .. arg[0] .. " [options]")
  6. print("Options:")
  7. print(" -a: apply the config changes")
  8. print(" -t: show matching UCI triggers")
  9. print(" -s: show information about tasks to be executed")
  10. print(" -r: reset all triggers")
  11. print("")
  12. end
  13. if arg[1] == "-s" then
  14. local triggers = uci.trigger.get_active()
  15. if #triggers > 0 then
  16. print("Tasks:")
  17. for i, a in ipairs(triggers) do
  18. local trigger = a[1]
  19. local sections = a[2]
  20. print(" - " .. uci.trigger.get_description(trigger, sections))
  21. end
  22. else
  23. print "Nothing to do"
  24. end
  25. elseif arg[1] == "-t" then
  26. local triggers = uci.trigger.get_active()
  27. for i, a in ipairs(triggers) do
  28. local trigger = a[1]
  29. local sections = a[2]
  30. if trigger.section_only then
  31. print(trigger.id .. " " .. table.concat(" ", sections))
  32. else
  33. print(trigger.id)
  34. end
  35. end
  36. elseif arg[1] == "-a" then
  37. uci.trigger.run()
  38. elseif arg[1] == "-r" then
  39. uci.trigger.reset_state()
  40. else
  41. usage()
  42. end