fix a typo in apply_config -t
[openwrt/svn-archive/archive.git] / package / uci / trigger / apply_config
1 #!/usr/bin/lua
2 require("uci")
3 require("uci.trigger")
4
5 function usage()
6 print("Usage: " .. arg[0] .. " [options]")
7 print("Options:")
8 print(" -a: apply the config changes")
9 print(" -t: show matching UCI triggers")
10 print(" -s: show information about tasks to be executed")
11 print(" -r: reset all triggers")
12 print(" -C <trigger> [<section>]: force clear a trigger")
13 print(" -S <trigger> [<section>]: force set a trigger")
14 print("")
15 end
16
17 if arg[1] == "-s" then
18 local triggers = uci.trigger.get_active()
19 if #triggers > 0 then
20 print("Tasks:")
21 for i, a in ipairs(triggers) do
22 local trigger = a[1]
23 local sections = a[2]
24 print(" - " .. uci.trigger.get_description(trigger, sections))
25 end
26 else
27 print "Nothing to do"
28 end
29 elseif arg[1] == "-t" then
30 local triggers = uci.trigger.get_active()
31 for i, a in ipairs(triggers) do
32 local trigger = a[1]
33 local sections = a[2]
34 if trigger.section_only then
35 print(trigger.id .. " " .. table.concat(sections, " "))
36 else
37 print(trigger.id)
38 end
39 end
40 elseif arg[1] == "-a" then
41 uci.trigger.run()
42 elseif arg[1] == "-r" then
43 uci.trigger.reset_state()
44 elseif arg[1] == "-S" then
45 local trigger = arg[2]
46 local section = arg[3]
47 uci.trigger.set_active(trigger, section)
48 elseif arg[1] == "-C" then
49 local trigger = arg[2]
50 local section = arg[3]
51 uci.trigger.clear_active(trigger, section)
52 else
53 usage()
54 end