Browse Source

nut: refactor upssched uci-defaults script

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>
lilik-openwrt-22.03
Pascal Coudurier 2 years ago
committed by Rosen Penev
parent
commit
f9bbc5173c
2 changed files with 50 additions and 7 deletions
  1. +1
    -1
      net/nut/Makefile
  2. +49
    -6
      net/nut/files/nut-sched.default

+ 1
- 1
net/nut/Makefile View 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/


+ 49
- 6
net/nut/files/nut-sched.default View 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

Loading…
Cancel
Save