ctdb-scripts: Silence shellcheck warning SC2166
authorMartin Schwenke <martin@meltin.net>
Mon, 2 Sep 2019 04:58:22 +0000 (14:58 +1000)
committerAmitay Isaacs <amitay@samba.org>
Tue, 17 Sep 2019 04:35:27 +0000 (04:35 +0000)
This covers the following:

  SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
  SC2166: Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.

POSIX agrees that -a and -o should not be used:

  https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html

Fixing these doesn't cause much churn.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/config/events/legacy/11.routing.script
ctdb/config/events/legacy/13.per_ip_routing.script
ctdb/config/events/legacy/60.nfs.script
ctdb/tests/shellcheck/scripts/local.sh
ctdb/tools/ctdb_diagnostics
ctdb/tools/onnode

index 018ee5732a6e8bc98e66e44d074a5ec48e82b741..3a526e1ed47e95fb4e22bcdca0fce78b519f4ff3 100755 (executable)
@@ -39,7 +39,7 @@ updateip)
        oiface=$2
        niface=$3
        while read iface dest gw; do
-           if [ "$niface" = "$iface" -o "$oiface" = "$iface" ] ; then
+           if [ "$niface" = "$iface" ] || [ "$oiface" = "$iface" ] ; then
                ip route add "$dest" via "$gw" dev "$iface" >/dev/null 2>&1
            fi
        done <"${CTDB_BASE}/static-routes"
index 269829483abd644e82ac8b4a660adb09a9a47487..ed5677327a183c7b5e462b7cf5d9aebeeed8fb9c 100755 (executable)
@@ -20,8 +20,8 @@ table_id_prefix="ctdb."
 [ "$CTDB_PER_IP_ROUTING_TABLE_ID_LOW" -lt "$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH" ] 2>/dev/null || \
     die "error: CTDB_PER_IP_ROUTING_TABLE_ID_LOW[$CTDB_PER_IP_ROUTING_TABLE_ID_LOW] and/or CTDB_PER_IP_ROUTING_TABLE_ID_HIGH[$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH] improperly configured"
 
-if [ "$CTDB_PER_IP_ROUTING_TABLE_ID_LOW" -le 253 -a \
-    255 -le "$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH" ] ; then
+if [ "$CTDB_PER_IP_ROUTING_TABLE_ID_LOW" -le 253 ] &&  \
+          [ 255 -le "$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH" ] ; then
     die "error: range CTDB_PER_IP_ROUTING_TABLE_ID_LOW[$CTDB_PER_IP_ROUTING_TABLE_ID_LOW]..CTDB_PER_IP_ROUTING_TABLE_ID_HIGH[$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH] must not include 253-255"
 fi
 
@@ -49,7 +49,7 @@ ipv4_is_valid_addr()
     for _o in $(export IFS="." ; echo $_ip) ; do
        # The 2>/dev/null stops output from failures where an "octet"
        # is not numeric.  The test will still fail.
-       if ! [ 0 -le $_o -a $_o -le 255 ] 2>/dev/null ; then
+       if ! [ 0 -le $_o ] && [ $_o -le 255 ] 2>/dev/null ; then
            return 1
        fi
        _count=$((_count + 1))
@@ -149,8 +149,9 @@ ensure_table_id_for_ip ()
            fi
            # Potentially update the new table id to be used.  The
            # redirect stops error spam for a non-numeric value.
-           if [ "$_new" -le "$_t" -a \
-               "$_t" -le "$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH" ] 2>/dev/null ; then
+           if [ "$_new" -le "$_t" ] && \
+                      [ "$_t" -le "$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH" ] \
+                              2>/dev/null ; then
                _new=$((_t + 1))
            fi
        done <"$rt_tables"
@@ -317,8 +318,8 @@ add_missing_routes ()
            [ -n "$_iface" ] || continue
 
            _table_id="${table_id_prefix}${_ip}"
-           if [ -z "$(ip route show table "$_table_id" 2>/dev/null)" -o \
-               "$1" = "force" ]  ; then
+           if [ -z "$(ip route show table "$_table_id" 2>/dev/null)" ] || \
+                      [ "$1" = "force" ]  ; then
                add_routing_for_ip "$_iface" "$_ip"
            fi
        done
index 2eb90b421c86d69253a115cf9a9af3c8809908dc..1b87b3d27e31f018fe652eb609bc1a900ce2ac14 100755 (executable)
@@ -139,7 +139,7 @@ nfs_check_service ()
        fi
 
        if $_ok ; then
-           if [ $unhealthy_after -ne 1 -o $restart_every -ne 0 ] ; then
+           if [ $unhealthy_after -ne 1 ] || [ $restart_every -ne 0 ] ; then
                ctdb_counter_init "$_progname"
            fi
            exit 0
@@ -179,7 +179,7 @@ nfs_check_service ()
 # shellcheck disable=SC2031
 nfs_restart_service ()
 {
-    if [ -z "$service_stop_cmd" -o -z "$service_start_cmd" ] ; then
+    if [ -z "$service_stop_cmd" ] || [ -z "$service_start_cmd" ] ; then
        die "ERROR: Can not restart service \"${_progname}\" without corresponding service_start_cmd/service_stop_cmd settings"
     fi
 
index ab92aaa557520a0ea2fbe0a09e746bfc3f5c8991..84019144009595b72b645a0e4edd8190122b1e02 100644 (file)
@@ -28,14 +28,7 @@ shellcheck_test ()
                # SC2164: Use cd ... || exit in case cd fails.
                #         - Most hits are on known directories.  Too
                #           much churn, maybe later.
-               # SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not
-               #         well defined.
-               # SC2166: Prefer [ p ] || [ q ] as [ p -o q ] is not
-               #         well defined.
-               #         - This can cause issues but the number of
-               #           true positives will be very low.  Too much
-               #           churn, maybe later.
-               _excludes="SC1090,SC1091,SC2162,SC2164,SC2166"
+               _excludes="SC1090,SC1091,SC2162,SC2164"
                unit_test shellcheck --exclude="$_excludes" "$@"
        else
                echo "WARNING: shellcheck not installed, skipping test"
index ccaf85963cb8c9de680c45ad012c6851eb3d0093..f86d14d389eaddc87c21cb44d7e307eb28ca9761 100755 (executable)
@@ -217,7 +217,7 @@ t=$(date +%s)
 for i in $nodes; do
     t2=$(onnode "$i" date +%s)
     d=$((t2 - t))
-    if [ "$d" -gt 30 -o "$d" -lt -30 ]; then
+    if [ "$d" -gt 30 ] || [ "$d" -lt -30 ]; then
        error "time on node $i differs by $d seconds"
     fi
 done
index d6595fff4aa9ba3cbeae33ef9e8b41e6e0dc0ccf..35c46c3c77997ac9264e0d2cbd0c1fe90c7a6b25 100755 (executable)
@@ -106,7 +106,7 @@ echo_nth ()
            node="$1"
     fi
 
-    if [ -n "$node" -a "$node" != "#DEAD" ] ; then
+    if [ -n "$node" ] && [ "$node" != "#DEAD" ] ; then
        echo "$node"
     else
        echo "${prog}: \"node ${n}\" does not exist" >&2
@@ -213,7 +213,7 @@ get_nodes ()
        local f="${CTDB_BASE}/nodes"
        if [ -n "$ctdb_nodes_file" ] ; then
                f="$ctdb_nodes_file"
-               if [ ! -e "$f" -a "${f#/}" = "$f" ] ; then
+               if [ ! -e "$f" ] && [ "${f#/}" = "$f" ] ; then
                        # $f is relative, try in $CTDB_BASE
                        f="${CTDB_BASE}/${f}"
                fi