apply_config 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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(" -C <trigger> [<section>]: force clear a trigger")
  12. print(" -S <trigger> [<section>]: force set a trigger")
  13. print("")
  14. end
  15. if arg[1] == "-s" then
  16. local triggers = uci.trigger.get_active()
  17. if #triggers > 0 then
  18. print("Tasks:")
  19. for i, a in ipairs(triggers) do
  20. local trigger = a[1]
  21. local sections = a[2]
  22. print(" - " .. uci.trigger.get_description(trigger, sections))
  23. end
  24. else
  25. print "Nothing to do"
  26. end
  27. elseif arg[1] == "-t" then
  28. local triggers = uci.trigger.get_active()
  29. for i, a in ipairs(triggers) do
  30. local trigger = a[1]
  31. local sections = a[2]
  32. if trigger.section_only then
  33. print(trigger.id .. " " .. table.concat(sections, " "))
  34. else
  35. print(trigger.id)
  36. end
  37. end
  38. elseif arg[1] == "-a" then
  39. uci.trigger.run()
  40. elseif arg[1] == "-r" then
  41. uci.trigger.reset_state()
  42. elseif arg[1] == "-S" then
  43. local trigger = arg[2]
  44. local section = arg[3]
  45. uci.trigger.set_active(trigger, section)
  46. elseif arg[1] == "-C" then
  47. local trigger = arg[2]
  48. local section = arg[3]
  49. uci.trigger.clear_active(trigger, section)
  50. else
  51. usage()
  52. end