summaryrefslogtreecommitdiffstats
path: root/package/uci/trigger/apply_config
blob: 0d9c6cf15ebba0ab53a75c2e44d202655ee3c4c1 (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/lua
require("uci")
require("uci.trigger")

function usage() 
	print("Usage: " .. arg[0] .. " [options]")
	print("Options:")
	print("    -a: apply the config changes")
	print("    -t: show matching UCI triggers")
	print("    -s: show information about tasks to be executed")
	print("    -r: reset all triggers")
	print("")
end

if arg[1] == "-s" then
	local triggers = uci.trigger.get_active()
	if #triggers > 0 then
		print("Tasks:")
		for i, a in ipairs(triggers) do
			local trigger = a[1]
			local sections = a[2]
			print(" - " .. uci.trigger.get_description(trigger, sections))
		end
	else
		print "Nothing to do"
	end
elseif arg[1] == "-t" then
	local triggers = uci.trigger.get_active()
	for i, a in ipairs(triggers) do
		local trigger = a[1]
		local sections = a[2]
		if trigger.section_only then
			print(trigger.id .. " " .. table.concat(" ", sections))
		else
			print(trigger.id)
		end
	end
elseif arg[1] == "-a" then
	uci.trigger.run()
elseif arg[1] == "-r" then
	uci.trigger.reset_state()
else
	usage()
end