aboutsummaryrefslogtreecommitdiffstats
path: root/lease-script
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2021-07-08 16:05:11 +0200
committerGravatar Christian Hesse <mail@eworm.de>2021-07-08 21:03:31 +0200
commit6bf8cd5fac77aa5db804c3180777d495b5d2ed26 (patch)
treed4103c94dd6428613d09089af7c7f0fa7f3c1477 /lease-script
parent623fd707c4e9340af35ad11ad09e3a87413423f6 (diff)
lease-script: implement script order
The order may be important: `collect-wireless-mac` can add a dns name in notification, thus `dhcp-to-dns` should run first.
Diffstat (limited to 'lease-script')
-rw-r--r--lease-script24
1 files changed, 19 insertions, 5 deletions
diff --git a/lease-script b/lease-script
index 780d122..97d5372 100644
--- a/lease-script
+++ b/lease-script
@@ -12,6 +12,7 @@
:global IfThenElse;
:global LogPrintExit2;
+:global ParseKeyValueStore;
:if ([ :typeof $leaseActIP ] = "nothing" || \
[ :typeof $leaseActMAC ] = "nothing" || \
@@ -21,18 +22,31 @@
}
:local State ([ $IfThenElse ($leaseBound = 0) "de" "" ] . "assign");
+:local RunOrder [ :toarray "" ];
$LogPrintExit2 debug $0 ("DHCP Server " . $leaseServerName . " " . \
$State . "ed lease " . $leaseActIP . " to " . $leaseActMAC) false;
-:foreach Script in=[ / system script find where source~("\n# provides: lease-script, " . $State . "\n") ] do={
- :local ScriptName [ / system script get $Script name ];
- :if ([ :len [ / system script job find where script=$ScriptName ] ] < 2) do={
+:foreach Script in=[ / system script find where source~("\n# provides: lease-script, ") ] do={
+ :local Name [ / system script get $Script name ];
+ :local Store [ / system script get $Script source ];
+
+ :set Store [ :pick $Store ([ :find $Store "\n# provides: lease-script, " ] + 27) [ :len $Store ] ];
+ :set Store [ :pick $Store 0 [ :find $Store "\n" ] ];
+ :set Store [ $ParseKeyValueStore $Store ];
+
+ :if (($Store->$State) = true) do={
+ :set ($RunOrder->($Store->"order")) $Name;
+ }
+}
+
+:foreach Script in=$RunOrder do={
+ :if ([ :len [ / system script job find where script=$Script ] ] < 2) do={
:do {
- $LogPrintExit2 debug $0 ("Running script: " . $ScriptName) false;
+ $LogPrintExit2 debug $0 ("Running script: " . $Script) false;
/ system script run $Script;
} on-error={
- $LogPrintExit2 warning $0 ("Running script '" . $ScriptName . "' failed!") false;
+ $LogPrintExit2 warning $0 ("Running script '" . $Script . "' failed!") false;
}
}
}