1
0
mirror of https://git.openwrt.org/feed/packages.git synced 2024-06-18 13:23:57 +02:00
openwrt-packages/net/nut/files/nut-sched.default
Pascal Coudurier f9bbc5173c 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>
2022-01-11 16:27:19 -08:00

54 lines
1000 B
Bash

#!/bin/sh
. "${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