lldpd: shellcheck fixes
authorPaul Donald <newtwen@gmail.com>
Mon, 11 Mar 2024 22:33:47 +0000 (23:33 +0100)
committerRobert Marko <robimarko@gmail.com>
Tue, 17 Sep 2024 10:36:03 +0000 (12:36 +0200)
No functionality/behaviour changes; code is synonymous

Tested on: 22.03.6

Signed-off-by: Paul Donald <newtwen@gmail.com>
(cherry picked from commit 5364fe0f01ca11b47c55d78f756d3176748dd0c2)
Link: https://github.com/openwrt/openwrt/pull/15299
Signed-off-by: Robert Marko <robimarko@gmail.com>
package/network/services/lldpd/files/lldpd.init

index 0ba438c379f110885ce198bff4680d08c31d3590..67ee011ae235416e0cc108e896ef474ad8115662 100644 (file)
@@ -1,5 +1,6 @@
 #!/bin/sh /etc/rc.common
 # Copyright (C) 2008-2015 OpenWrt.org
+# shellcheck disable=1091,2034,3037,3043,3045
 
 START=90
 STOP=01
@@ -39,38 +40,38 @@ get_config_restart_hash() {
        config_load 'lldpd'
 
        config_get      v 'config' 'lldp_class'; append _string "$v" ","
-       if [ "$CONFIG_LLDPD_WITH_SNMP" == "y" ]; then
+       if [ "$CONFIG_LLDPD_WITH_SNMP" = "y" ]; then
                config_get      v 'config' 'agentxsocket'; append _string "$v" ","
        fi
        config_get      v 'config' 'cid_interface'; append _string "$v" ","
        config_get      v 'config' 'filter'; append _string "$v" ","
        config_get_bool v 'config' 'readonly_mode'; append _string "$v" ","
        config_get_bool v 'config' 'lldp_no_version'; append _string "$v" ","
-       if [ "$CONFIG_LLDPD_WITH_LLDPMED" == "y" ]; then
+       if [ "$CONFIG_LLDPD_WITH_LLDPMED" = "y" ]; then
                config_get_bool v 'config' 'lldpmed_no_inventory'; append _string "$v" ","
        fi
        config_get_bool v 'config' 'enable_lldp' 1; append _string "$v" ","
        config_get_bool v 'config' 'force_lldp'; append _string "$v" ","
-       if [ "$CONFIG_LLDPD_WITH_CDP" == "y" ]; then
+       if [ "$CONFIG_LLDPD_WITH_CDP" = "y" ]; then
                config_get_bool v 'config' 'enable_cdp'; append _string "$v" ","
                config_get      v 'config' 'cdp_version'; append _string "$v" ","
                config_get_bool v 'config' 'force_cdp'; append _string "$v" ","
                config_get_bool v 'config' 'force_cdpv2'; append _string "$v" ","
        fi
-       if [ "$CONFIG_LLDPD_WITH_EDP" == "y" ]; then
+       if [ "$CONFIG_LLDPD_WITH_EDP" = "y" ]; then
                config_get_bool v 'config' 'enable_edp'; append _string "$v" ","
                config_get_bool v 'config' 'force_edp'; append _string "$v" ","
        fi
-       if [ "$CONFIG_LLDPD_WITH_FDP" == "y" ]; then
+       if [ "$CONFIG_LLDPD_WITH_FDP" = "y" ]; then
                config_get_bool v 'config' 'enable_fdp'; append _string "$v" ","
                config_get_bool v 'config' 'force_fdp'; append _string "$v" ","
        fi
-       if [ "$CONFIG_LLDPD_WITH_SONMP" == "y" ]; then
+       if [ "$CONFIG_LLDPD_WITH_SONMP" = "y" ]; then
                config_get_bool v 'config' 'enable_sonmp'; append _string "$v" ","
                config_get_bool v 'config' 'force_sonmp'; append _string "$v" ","
        fi
 
-       _hash=`echo -n "${_string}" | md5sum | awk '{ print \$1 }'`
+       _hash=$(echo -n "${_string}" | md5sum | awk '{ print $1 }')
        export -n "$var=$_hash"
 }
 
@@ -108,7 +109,7 @@ write_lldpd_conf()
        local lldp_syscapabilities
        config_get lldp_syscapabilities 'config' 'lldp_syscapabilities'
 
-       if [ "$CONFIG_LLDPD_WITH_LLDPMED" == "y" ]; then
+       if [ "$CONFIG_LLDPD_WITH_LLDPMED" = "y" ]; then
                local lldpmed_fast_start
                config_get_bool lldpmed_fast_start 'config' 'lldpmed_fast_start' 0
 
@@ -148,14 +149,14 @@ write_lldpd_conf()
        [ -n "$lldp_hostname" ] && echo "configure system hostname" "\"$lldp_hostname\"" >> "$LLDPD_CONF"
        [ -n "$lldp_mgmt_ip" ] && echo "configure system ip management pattern" "\"$lldp_mgmt_ip\"" >> "$LLDPD_CONF"
        [ -n "$lldp_syscapabilities" ] && echo "configure system capabilities enabled $lldp_syscapabilities" >> "$LLDPD_CONF"
-       if [ "$CONFIG_LLDPD_WITH_LLDPMED" == "y" ] && [ $lldpmed_fast_start -gt 0 ]; then
-               if [ $lldpmed_fast_start_tx_interval -gt 0 ]; then
+       if [ "$CONFIG_LLDPD_WITH_LLDPMED" = "y" ] && [ "$lldpmed_fast_start" -gt 0 ]; then
+               if [ "$lldpmed_fast_start_tx_interval" -gt 0 ]; then
                        echo "configure med fast-start tx-interval $lldpmed_fast_start_tx_interval" >> "$LLDPD_CONF"
                else
                        echo "configure med fast-start enable" >> "$LLDPD_CONF"
                fi
        fi
-       if [ "$CONFIG_LLDPD_WITH_LLDPMED" == "y" ]; then
+       if [ "$CONFIG_LLDPD_WITH_LLDPMED" = "y" ]; then
                # other 'configure med xxx' statements go here
 
                [ -n "$lldp_location" ] && echo "configure med location" "$lldp_location" >> "$LLDPD_CONF"
@@ -171,11 +172,11 @@ write_lldpd_conf()
        [ -n "$lldp_agenttype" ] && echo "configure lldp agent-type" "\"$lldp_agenttype\"" >> "$LLDPD_CONF"
        [ -n "$lldp_portidsubtype" ] && echo "configure lldp portidsubtype" "\"$lldp_portidsubtype\"" >> "$LLDPD_CONF"
        [ -n "$lldp_platform" ] && echo "configure system platform" "\"$lldp_platform\"" >> "$LLDPD_CONF"
-       [ -n $lldp_tx_interval ] && echo "configure lldp tx-interval $lldp_tx_interval" >> "$LLDPD_CONF"
-       [ $lldp_tx_hold -gt 0 ] && echo "configure lldp tx-hold $lldp_tx_hold" >> "$LLDPD_CONF"
+       [ -n "$lldp_tx_interval" ] && echo "configure lldp tx-interval $lldp_tx_interval" >> "$LLDPD_CONF"
+       [ "$lldp_tx_hold" -gt 0 ] && echo "configure lldp tx-hold $lldp_tx_hold" >> "$LLDPD_CONF"
 
        # Since lldpd's sysconfdir is /tmp, we'll symlink /etc/lldpd.d to /tmp/$LLDPD_CONFS_DIR
-       [ -e $LLDPD_CONFS_DIR ] || ln -s /etc/lldpd.d $LLDPD_CONFS_DIR
+       [ -e "$LLDPD_CONFS_DIR" ] || ln -s /etc/lldpd.d "$LLDPD_CONFS_DIR"
 }
 
 start_service() {
@@ -202,31 +203,31 @@ start_service() {
        config_load 'lldpd'
        config_get_bool enable_lldp 'config' 'enable_lldp' 1
        config_get_bool force_lldp 'config' 'force_lldp' 0
-       if [ "$CONFIG_LLDPD_WITH_CDP" == "y" ]; then
+       if [ "$CONFIG_LLDPD_WITH_CDP" = "y" ]; then
                config_get_bool enable_cdp 'config' 'enable_cdp' 0
                config_get cdp_version 'config' 'cdp_version' 'cdpv1v2'
                config_get_bool force_cdp 'config' 'force_cdp' 0
                config_get_bool force_cdpv2 'config' 'force_cdpv2' 0
        fi
-       if [ "$CONFIG_LLDPD_WITH_FDP" == "y" ]; then
+       if [ "$CONFIG_LLDPD_WITH_FDP" = "y" ]; then
                config_get_bool enable_fdp 'config' 'enable_fdp' 0
                config_get_bool force_fdp 'config' 'force_fdp' 0
        fi
-       if [ "$CONFIG_LLDPD_WITH_SONMP" == "y" ]; then
+       if [ "$CONFIG_LLDPD_WITH_SONMP" = "y" ]; then
                config_get_bool enable_sonmp 'config' 'enable_sonmp' 0
                config_get_bool force_sonmp 'config' 'force_sonmp' 0
        fi
-       if [ "$CONFIG_LLDPD_WITH_EDP" == "y" ]; then
+       if [ "$CONFIG_LLDPD_WITH_EDP" = "y" ]; then
                config_get_bool enable_edp 'config' 'enable_edp' 0
                config_get_bool force_edp 'config' 'force_edp' 0
        fi
        config_get lldp_class 'config' 'lldp_class'
        config_get_bool lldp_no_version 'config' 'lldp_no_version' 0
-       if [ "$CONFIG_LLDPD_WITH_LLDPMED" == "y" ]; then
+       if [ "$CONFIG_LLDPD_WITH_LLDPMED" = "y" ]; then
                config_get_bool lldpmed_no_inventory 'config' 'lldpmed_no_inventory' 0
        fi
        config_get_bool readonly_mode 'config' 'readonly_mode' 0
-       if [ "$CONFIG_LLDPD_WITH_SNMP" == "y" ]; then
+       if [ "$CONFIG_LLDPD_WITH_SNMP" = "y" ]; then
                config_get agentxsocket 'config' 'agentxsocket'
        fi
        config_get filter 'config' 'filter' 15
@@ -241,8 +242,8 @@ start_service() {
        procd_set_param command ${LLDPDBIN}
        procd_append_param command -d
 
-       if [ $enable_lldp -gt 0 ]; then
-               if [ $force_lldp -gt 0 ]; then
+       if [ "$enable_lldp" -gt 0 ]; then
+               if [ "$force_lldp" -gt 0 ]; then
                        procd_append_param command '-l'
                fi
        else
@@ -250,20 +251,20 @@ start_service() {
                procd_append_param command '-ll'
        fi
 
-       if [ "$CONFIG_LLDPD_WITH_CDP" == "y" ] && [ $enable_cdp -gt 0 ]; then
-               if [ $cdp_version == "cdpv2" ]; then
-                       if [ $force_cdp -gt 0 ]; then
+       if [ "$CONFIG_LLDPD_WITH_CDP" = "y" ] && [ "$enable_cdp" -gt 0 ]; then
+               if [ "$cdp_version" = "cdpv2" ]; then
+                       if [ "$force_cdp" -gt 0 ]; then
                                # CDPv1 disabled, CDPv2 forced
                                procd_append_param command '-ccccc'
                        else
                                # CDPv1 disabled, CDPv2 enabled
                                procd_append_param command '-cccc'
                        fi
-               elif [ $cdp_version == "cdpv1v2" ]; then
-                       if [ $force_cdp -gt 0 ] && [ $force_cdpv2 -gt 0 ]; then
+               elif [ "$cdp_version" = "cdpv1v2" ]; then
+                       if [ "$force_cdp" -gt 0 ] && [ "$force_cdpv2" -gt 0 ]; then
                                # CDPv1 enabled, CDPv2 forced
                                procd_append_param command '-ccc'
-                       elif [ $force_cdp -gt 0 ]; then
+                       elif [ "$force_cdp" -gt 0 ]; then
                                # CDPv1 forced, CDPv2 enabled
                                procd_append_param command '-cc'
                        else
@@ -273,8 +274,8 @@ start_service() {
                fi
        fi
 
-       if [ "$CONFIG_LLDPD_WITH_FDP" == "y" ] && [ $enable_fdp -gt 0 ]; then
-               if [ $force_fdp -gt 0 ]; then
+       if [ "$CONFIG_LLDPD_WITH_FDP" = "y" ] && [ "$enable_fdp" -gt 0 ]; then
+               if [ "$force_fdp" -gt 0 ]; then
                        # FDP enabled and forced
                        procd_append_param command '-ff'
                else
@@ -283,8 +284,8 @@ start_service() {
                fi
        fi
 
-       if [ "$CONFIG_LLDPD_WITH_SONMP" == "y" ] && [ $enable_sonmp -gt 0 ]; then
-               if [ $force_sonmp -gt 0 ]; then
+       if [ "$CONFIG_LLDPD_WITH_SONMP" = "y" ] && [ "$enable_sonmp" -gt 0 ]; then
+               if [ "$force_sonmp" -gt 0 ]; then
                        # SONMP enabled and forced
                        procd_append_param command '-ss'
                else
@@ -293,8 +294,8 @@ start_service() {
                fi
        fi
 
-       if [ "$CONFIG_LLDPD_WITH_EDP" == "y" ] && [ $enable_edp -gt 0 ]; then
-               if [ $force_edp -gt 0 ]; then
+       if [ "$CONFIG_LLDPD_WITH_EDP" = "y" ] && [ "$enable_edp" -gt 0 ]; then
+               if [ "$force_edp" -gt 0 ]; then
                        # EDP enabled and forced
                        procd_append_param command '-ee'
                else
@@ -303,11 +304,11 @@ start_service() {
                fi
        fi
 
-       [ $readonly_mode -gt 0 ] && procd_append_param command '-r'
-       [ $lldp_no_version -gt 0 ] && procd_append_param command '-k'
-       [ "$CONFIG_LLDPD_WITH_LLDPMED" == "y" ] && [ $lldpmed_no_inventory -gt 0 ] && procd_append_param command '-i'
+       [ "$readonly_mode" -gt 0 ] && procd_append_param command '-r'
+       [ "$lldp_no_version" -gt 0 ] && procd_append_param command '-k'
+       [ "$CONFIG_LLDPD_WITH_LLDPMED" = "y" ] && [ "$lldpmed_no_inventory" -gt 0 ] && procd_append_param command '-i'
        [ -n "$lldp_class" ] && procd_append_param command -M "$lldp_class"
-       [ "$CONFIG_LLDPD_WITH_SNMP" == "y" ] && [ -n "$agentxsocket" ] && procd_append_param command -x -X "$agentxsocket"
+       [ "$CONFIG_LLDPD_WITH_SNMP" = "y" ] && [ -n "$agentxsocket" ] && procd_append_param command -x -X "$agentxsocket"
        [ -n "$filter" ] && procd_append_param command -H "$filter"
 
     # ChassisID interfaces
@@ -321,7 +322,7 @@ start_service() {
 
        local restart_hash
        get_config_restart_hash restart_hash
-       echo -n "$restart_hash" > $LLDPD_RESTART_HASH
+       echo -n "$restart_hash" > "$LLDPD_RESTART_HASH"
 
        # set auto respawn behavior
        procd_set_param respawn
@@ -339,7 +340,7 @@ reload_service() {
        local config_hash=""
 
        get_config_restart_hash config_hash
-       if [ -f ${LLDPD_RESTART_HASH} ]; then running_hash=`cat $LLDPD_RESTART_HASH`; fi
+       [ -f ${LLDPD_RESTART_HASH} ] && running_hash=$(cat "$LLDPD_RESTART_HASH")
 
        if [ "x$running_hash" != "x$config_hash" ]; then
                # Restart LLDPd
@@ -348,7 +349,7 @@ reload_service() {
                return 0
        fi
 
-       $LLDPCLI -u $LLDPSOCKET &> /dev/null <<-EOF
+       $LLDPCLI -u "$LLDPSOCKET" 2>&1 /dev/null <<-EOF
                pause
                unconfigure lldp custom-tlv
                unconfigure system interface pattern
@@ -357,8 +358,8 @@ reload_service() {
                unconfigure system ip management pattern
                unconfigure system platform
        EOF
-       if [ "$CONFIG_LLDPD_WITH_LLDPMED" == "y" ]; then
-               $LLDPCLI -u $LLDPSOCKET &> /dev/null <<-EOF
+       if [ "$CONFIG_LLDPD_WITH_LLDPMED" = "y" ]; then
+               $LLDPCLI -u "$LLDPSOCKET" 2>&1 /dev/null <<-EOF
                        unconfigure med fast-start
                EOF
 
@@ -366,9 +367,9 @@ reload_service() {
        # Rewrite lldpd.conf
        # If something changed it should be included by the lldpcli call
        write_lldpd_conf
-       $LLDPCLI -u $LLDPSOCKET -c $LLDPD_CONF -c $LLDPD_CONFS_DIR &> /dev/null
+       $LLDPCLI -u "$LLDPSOCKET" -c "$LLDPD_CONF" -c "$LLDPD_CONFS_DIR" 2>&1 /dev/null
        # Broadcast update over the wire
-       $LLDPCLI -u $LLDPSOCKET &> /dev/null <<-EOF
+       $LLDPCLI -u "$LLDPSOCKET" 2>&1 /dev/null <<-EOF
                resume
                update
        EOF
@@ -376,6 +377,6 @@ reload_service() {
 }
 
 stop_service() {
-       rm -rf ${LLDPD_RUN} $LLDPSOCKET 2>/dev/null
+       rm -rf ${LLDPD_RUN} "$LLDPSOCKET" 2> /dev/null
 }