# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
+
+# shellcheck shell=ash
+
+# shellcheck disable=SC2034
START=70
STOP=30
}
listen_address() {
- local cfg="$1"
+ local cfg="$1"
- config_get address "$cfg" address "::1"
- config_get port "$cfg" port
- echo "LISTEN $address $port" >>"$UPSD_C"
+ config_get address "$cfg" address "::1"
+ config_get port "$cfg" port
+ # shellcheck disable=SC2154
+ echo "LISTEN $address $port" >>"$UPSD_C"
}
upsd_config() {
- local cfg="$1"
- local maxage maxconn certfile runas statepath
+ local cfg="$1"
+ local maxage maxconn certfile runas statepath
- # Note runas support requires you make sure USB device file is readable by
- # the runas user
- config_get runas "$cfg" runas nut
- RUNAS="$runas"
+ # Note runas support requires you make sure USB device file is readable by
+ # the runas user
+ config_get runas "$cfg" runas nut
+ RUNAS="$runas"
- config_get statepath "$cfg" statepath /var/run/nut
- STATEPATH="$statepath"
+ config_get statepath "$cfg" statepath /var/run/nut
+ STATEPATH="$statepath"
- config_get maxage "$cfg" maxage
- [ -n "$maxage" ] && echo "MAXAGE $maxage" >>"$UPSD_C"
+ config_get maxage "$cfg" maxage
+ [ -n "$maxage" ] && echo "MAXAGE $maxage" >>"$UPSD_C"
- [ -n "$statepath" ] && echo "STATEPATH $statepath" >>"$UPSD_C"
+ [ -n "$statepath" ] && echo "STATEPATH $statepath" >>"$UPSD_C"
- config_get maxconn "$cfg" maxconn
- [ -n "$maxconn" ] && echo "MAXCONN $maxconn" >>"$UPSD_C"
+ config_get maxconn "$cfg" maxconn
+ [ -n "$maxconn" ] && echo "MAXCONN $maxconn" >>"$UPSD_C"
- #NOTE: certs only apply to SSL-enabled version
- config_get certfile "$cfg" certfile
- [ -n "$certfile" ] && echo "CERTFILE $certfile" >>"$UPSD_C"
+ #NOTE: certs only apply to SSL-enabled version
+ config_get certfile "$cfg" certfile
+ [ -n "$certfile" ] && echo "CERTFILE $certfile" >>"$UPSD_C"
}
nut_user_add() {
config_get val "$cfg" actions
for a in $val; do
- echo " actions = $a" >> "$USERS_C"
+ echo " actions = $a" >> "$USERS_C"
done
instcmd() {
+ # shellcheck disable=2317
local val="$1"
+ # shellcheck disable=2317
echo " instcmds = $val" >> "$USERS_C"
}
config_get val "$cfg" upsmon
if [ -n "$val" ]; then
- echo " upsmon $val" >> "$USERS_C"
+ echo " upsmon $val" >> "$USERS_C"
fi
}
build_server_config() {
- mkdir -p "$(dirname "$UPSD_C")"
+ mkdir -p "$(dirname "$UPSD_C")"
chmod 0640 "$UPS_C"
rm -f "$USERS_C"
rm -f "$UPSD_C"
get_write_driver_config "$cfg" vendorid
# Params specific to NetXML driver
- get_write_driver_config "$cfg" login
- get_write_driver_config "$cfg" password
- get_write_driver_config "$cfg" subscribe 0 1
+ get_write_driver_config "$cfg" login
+ get_write_driver_config "$cfg" password
+ get_write_driver_config "$cfg" subscribe 0 1
+ # shellcheck disable=SC2317
defoverride() {
local overvar="$1"
local defover="$2"
- local overtype="$(echo "$overvar" | tr '_' '.')"
+ local overtype
local overval
+ overtype="$(echo "$overvar" | tr '_' '.')"
+
config_get overval "${defover}_${overvar}" value
- [ -n "$overval" ] && echo "${defover}.${overtype} = $overval" >>"$UPS_C"
+ [ -n "$overval" ] && echo "${defover}.${overtype} = $overval" >>"$UPS_C"
}
config_list_foreach "$cfg" override defoverride override
config_list_foreach "$cfg" default defoverride default
other() {
+ # shellcheck disable=SC2317
local othervar="$1"
+ # shellcheck disable=SC2317
local othervarflag="$2"
+ # shellcheck disable=SC2317
local otherval
+ # shellcheck disable=SC2317
if [ "$othervarflag" = "otherflag" ]; then
config_get_bool otherval "${othervarflag}_${othervar}" value
[ "$otherval" = "1" ] && echo "${othervar}" >>"$UPS_C"
build_config() {
local STATEPATH=/var/run/nut
- mkdir -p "$(dirname "$UPS_C")"
+ mkdir -p "$(dirname "$UPS_C")"
rm -f "$UPS_C"
echo "# Config file automatically generated from UCI config" > "$UPS_C"
chmod 0640 "$UPS_C"
[ "$havedriver" != 1 ] && return
# If wanting a specific instance, only start it
- if [ "$requested" != "$cfg" ] && [ "$request" != "" ]; then
+ if [ "$requested" != "$cfg" ] && [ "$requested" != "" ]; then
return 0
fi
upsd_statepath
build_config
- # Avoid hotplug inadvertenly restarting driver during
+ # Avoid hotplug inadvertently restarting driver during
# forced shutdown
[ -f /var/run/killpower ] && return 0
if [ -d /var/run/nut ] && [ -f /var/run/nut/disable-hotplug ]; then
- return 0
+ return 0
fi
if [ -n "$RUNAS" ]; then
config_get triggerlist upsd triggerlist
+ # shellcheck disable=SC1091
. /lib/functions/network.sh
if [ -n "$triggerlist" ]; then
start_service() {
local STATEPATH=/var/run/nut
- # Avoid hotplug inadvertenly restarting driver during
+ # Avoid hotplug inadvertently restarting driver during
# forced shutdown
[ -f /var/run/killpower ] && return 0