From 7eafd0ada63825d560b8ea6ef3dd9230926e5e57 Mon Sep 17 00:00:00 2001 From: "Daniel F. Dickinson" Date: Sun, 11 Jan 2026 05:36:43 -0500 Subject: [PATCH] nut: add linting and fix whitespace and typos shellcheck is a useful linter if a bit pedantic and overzealous so add overrides to silence false positives Also, fix issues found by the linting. * misspelling meant initscript could skip updating configuration in certain circumstances * minor: assignment of the result of execution as the time of creating local. This has been separated. Fix whitespace and comment typos Fix typo in Config.in option text * This is cosmetic, but user-facing (for users building via SDK or buildroot). Signed-off-by: Daniel F. Dickinson --- net/nut/Config.in | 4 +- net/nut/files/nut-server.init | 81 +++++++++++++++++++++-------------- 2 files changed, 50 insertions(+), 35 deletions(-) diff --git a/net/nut/Config.in b/net/nut/Config.in index 2457655509..28d40329b2 100644 --- a/net/nut/Config.in +++ b/net/nut/Config.in @@ -26,14 +26,14 @@ config NUT_DRIVER_SERIAL depends on PACKAGE_nut - bool "Build with suport for serial drivers" + bool "Build with support for serial drivers" help If you have a UPS connected via serial cable, select this. default y config NUT_DRIVER_NEON depends on PACKAGE_nut - bool "Build with suport for netxml drivers" + bool "Build with support for netxml drivers" help If you have a UPS connected via netxml, select this. default y diff --git a/net/nut/files/nut-server.init b/net/nut/files/nut-server.init index 70cb21f871..8e0cc6b4f1 100755 --- a/net/nut/files/nut-server.init +++ b/net/nut/files/nut-server.init @@ -4,6 +4,10 @@ # 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 @@ -48,36 +52,37 @@ upsd_runas() { } 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() { @@ -93,11 +98,13 @@ 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" } @@ -105,12 +112,12 @@ nut_user_add() { 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" @@ -178,28 +185,35 @@ build_driver_config() { 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" @@ -235,7 +249,7 @@ build_global_driver_config() { 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" @@ -260,7 +274,7 @@ start_driver_instance() { [ "$havedriver" != 1 ] && return # If wanting a specific instance, only start it - if [ "$requested" != "$cfg" ] && [ "$request" != "" ]; then + if [ "$requested" != "$cfg" ] && [ "$requested" != "" ]; then return 0 fi @@ -270,11 +284,11 @@ start_driver_instance() { 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 @@ -297,6 +311,7 @@ interface_triggers() { config_get triggerlist upsd triggerlist + # shellcheck disable=SC1091 . /lib/functions/network.sh if [ -n "$triggerlist" ]; then @@ -334,7 +349,7 @@ start_server_instance() { 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