Root/package/uci/trigger/apply_config

1#!/usr/bin/lua
2require("uci")
3require("uci.trigger")
4
5function 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("")
15end
16
17if 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
29elseif 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
40elseif arg[1] == "-a" then
41    uci.trigger.run()
42elseif arg[1] == "-r" then
43    uci.trigger.reset_state()
44elseif arg[1] == "-S" then
45    local trigger = arg[2]
46    local section = arg[3]
47    uci.trigger.set_active(trigger, section)
48elseif arg[1] == "-C" then
49    local trigger = arg[2]
50    local section = arg[3]
51    uci.trigger.clear_active(trigger, section)
52else
53    usage()
54end
55

Archive Download this file



interactive