nut: refactor upssched uci-defaults script
authorPascal Coudurier <coudu@wanadoo.fr>
Tue, 4 Jan 2022 13:12:31 +0000 (14:12 +0100)
committerRosen Penev <rosenp@gmail.com>
Wed, 12 Jan 2022 00:27:19 +0000 (16:27 -0800)
Add checks not to overwrite defaultnotify options in the nut-sendmail-notify fashion.
Use lists for defaultnotify instead of option.
Add check not to overwrite notifycmd if already defined.
upssched-cmd script must not be called directly, it is called by the upssched binary with needed arguments.

Signed-off-by: Pascal Coudurier <coudu@wanadoo.fr>
net/nut/Makefile
net/nut/files/nut-sched.default

index ed065311cce81609927b82a9065e6c8b26cf2c72..42839b7667a34158b8bafd874f621eedb698e27e 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=nut
 PKG_VERSION:=2.7.4
-PKG_RELEASE:=25
+PKG_RELEASE:=26
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://www.networkupstools.org/source/2.7/
index d8b13f0e3b11ac3a3c4ab9a4b8f5307a0b60fbed..4b73b6c61c51e50f301f4e678d5692b439ded0cb 100644 (file)
@@ -1,10 +1,53 @@
 #!/bin/sh
 
-uci batch <<EOF
-set nut_monitor.@upsmon[-1]=upsmon
-set nut_monitor.@upsmon[-1].notifycmd=/usr/bin/upssched-cmd
-set nut_monitor.@upsmon[-1].defaultnotify="SYSLOG EXEC"
-commit nut_monitor
-EOF
+. "${IPKG_INSTROOT}"/lib/functions.sh
 
+REMOVEDEFAULTNOTIFY=0
+SKIPADDSYSLOG=0
+SKIPADDEXEC=0
+SKIPADDNOTIFYCMD=0
 
+upsmon() {
+       local cfg="$1"
+       local val
+
+       config_get val "$cfg" notifycmd
+       if [ -n "$val" ]; then
+               SKIPADDNOTIFYCMD=1
+       fi
+
+       config_get val "$cfg" defaultnotify
+       if [ -n "$val" ]; then
+               if echo "$val" |grep -q "IGNORE"; then
+                       REMOVEDEFAULTNOTIFY=1
+               else
+                       SKIPADDSYSLOG=1
+                       if echo "$val" |grep -q "EXEC"; then
+                               SKIPADDEXEC=1
+                       fi
+               fi
+       fi
+}
+
+config_load nut_monitor
+config_foreach upsmon upsmon
+
+uci set nut_monitor.@upsmon[-1]=upsmon
+
+if [ "$SKIPADDNOTIFYCMD" != "1" ]; then
+       uci set nut_monitor.@upsmon[-1].notifycmd=/usr/sbin/upssched
+fi
+
+if [ "$REMOVEDEFAULTNOTIFY" = "1" ]; then
+       uci delete nut_monitor.@upsmon[-1].defaultnotify || true
+fi
+
+if [ "$SKIPADDEXEC" != "1" ]; then
+       uci add_list nut_monitor.@upsmon[-1].defaultnotify="EXEC"
+fi
+
+if [ "$SKIPADDSYSLOG" != "1" ]; then
+       uci add_list nut_monitor.@upsmon[-1].defaultnotify="SYSLOG"
+fi
+
+uci commit nut_monitor