]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-scripts: Reformat with "shfmt -w -i 0 -fn"
authorMartin Schwenke <mschwenke@ddn.com>
Wed, 8 Apr 2026 01:31:44 +0000 (11:31 +1000)
committerMartin Schwenke <martins@samba.org>
Thu, 16 Apr 2026 23:09:33 +0000 (23:09 +0000)
Best reviewed with "git show -w" or similar.

Signed-off-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: John Mulligan <jmulligan@redhat.com>
ctdb/config/ctdb-crash-cleanup.sh
ctdb/config/events/legacy/11.natgw.script
ctdb/config/functions

index 95cfd75981fd48caf8faea747baa7cf306be18ae..8afc5fa269eb1e8e7e827e983ca47dbf1b73c212 100755 (executable)
@@ -4,24 +4,24 @@
 # all public ip addresses if CTDBD has crashed or stopped running.
 #
 
-[ -n "$CTDB_BASE" ] || \
+[ -n "$CTDB_BASE" ] ||
        CTDB_BASE=$(d=$(dirname "$0") && cd -P "$d" && echo "$PWD")
 
 . "${CTDB_BASE}/functions"
 
 # If ctdb is running, just exit
-if service ctdb status >/dev/null 2>&1 ; then
-    exit 0
+if service ctdb status >/dev/null 2>&1; then
+       exit 0
 fi
 
 load_script_options "failover" "11.natgw"
 
-if [ ! -f "$CTDB_BASE/public_addresses" ] ; then
+if [ ! -f "$CTDB_BASE/public_addresses" ]; then
        die "No public addresses file found. Can't clean up."
 fi
 
 drop_all_public_ips 2>&1 | script_log "ctdb-crash-cleanup.sh"
 
-if [ -n "$CTDB_NATGW_PUBLIC_IP" ] ; then
-    drop_ip "$CTDB_NATGW_PUBLIC_IP" "ctdb-crash-cleanup.sh"
+if [ -n "$CTDB_NATGW_PUBLIC_IP" ]; then
+       drop_ip "$CTDB_NATGW_PUBLIC_IP" "ctdb-crash-cleanup.sh"
 fi
index 9fe834156a09d8cd0d730eb5b497edcb6fb9cbae..99944c64402dba77c9ce3a98b47daf346a2a0045 100755 (executable)
@@ -5,7 +5,7 @@
 # available.
 #
 
-[ -n "$CTDB_BASE" ] || \
+[ -n "$CTDB_BASE" ] ||
        CTDB_BASE=$(d="$(dirname "$0")" && cd -P "$d/../../" && pwd)
 
 . "${CTDB_BASE}/functions"
@@ -25,37 +25,37 @@ natgw_cfg_new="${script_state_dir}/cfg_new"
 natgw_cfg_old="${script_state_dir}/cfg_old"
 natgw_leader_old="${script_state_dir}/leader_old"
 
-ctdb_natgw_follower_only ()
+ctdb_natgw_follower_only()
 {
-    _ip_address=$(ctdb_get_ip_address)
+       _ip_address=$(ctdb_get_ip_address)
 
-    awk -v my_ip="$_ip_address" \
-       '$1 == my_ip { if ($2 ~ "follower-only") { exit 0 } else { exit 1 } }' \
-       "$CTDB_NATGW_NODES"
+       awk -v my_ip="$_ip_address" \
+               '$1 == my_ip { if ($2 ~ "follower-only") { exit 0 } else { exit 1 } }' \
+               "$CTDB_NATGW_NODES"
 }
 
-natgw_check_config ()
+natgw_check_config()
 {
-    [ -r "$CTDB_NATGW_NODES" ] || \
-       die "error: CTDB_NATGW_NODES=${CTDB_NATGW_NODES} unreadable"
-    if ! ctdb_natgw_follower_only ; then
-       [ -n "$CTDB_NATGW_PUBLIC_IP" ] || \
-           die "Invalid configuration: CTDB_NATGW_PUBLIC_IP not set"
-       [ -n "$CTDB_NATGW_PUBLIC_IFACE" ] || \
-           die "Invalid configuration: CTDB_NATGW_PUBLIC_IFACE not set"
-    fi
-    [ -n "$CTDB_NATGW_PRIVATE_NETWORK" ] || \
-           die "Invalid configuration: CTDB_NATGW_PRIVATE_NETWORK not set"
-
-    # The default is to create a single default route
-    [ -n "$CTDB_NATGW_STATIC_ROUTES" ] || CTDB_NATGW_STATIC_ROUTES="0.0.0.0/0"
+       [ -r "$CTDB_NATGW_NODES" ] ||
+               die "error: CTDB_NATGW_NODES=${CTDB_NATGW_NODES} unreadable"
+       if ! ctdb_natgw_follower_only; then
+               [ -n "$CTDB_NATGW_PUBLIC_IP" ] ||
+                       die "Invalid configuration: CTDB_NATGW_PUBLIC_IP not set"
+               [ -n "$CTDB_NATGW_PUBLIC_IFACE" ] ||
+                       die "Invalid configuration: CTDB_NATGW_PUBLIC_IFACE not set"
+       fi
+       [ -n "$CTDB_NATGW_PRIVATE_NETWORK" ] ||
+               die "Invalid configuration: CTDB_NATGW_PRIVATE_NETWORK not set"
+
+       # The default is to create a single default route
+       [ -n "$CTDB_NATGW_STATIC_ROUTES" ] || CTDB_NATGW_STATIC_ROUTES="0.0.0.0/0"
 }
 
-natgw_write_config ()
+natgw_write_config()
 {
-    _f="$1"
+       _f="$1"
 
-    cat >"$_f" <<EOF
+       cat >"$_f" <<EOF
 CTDB_NATGW_NODES="$CTDB_NATGW_NODES"
 CTDB_NATGW_PUBLIC_IP="$CTDB_NATGW_PUBLIC_IP"
 CTDB_NATGW_PUBLIC_IFACE="$CTDB_NATGW_PUBLIC_IFACE"
@@ -65,124 +65,126 @@ CTDB_NATGW_STATIC_ROUTES="$CTDB_NATGW_STATIC_ROUTES"
 EOF
 }
 
-natgw_config_has_changed ()
+natgw_config_has_changed()
 {
-    natgw_write_config "$natgw_cfg_new"
-
-    # Non-existent old returns true, no log message
-    if [ ! -f "$natgw_cfg_old" ] ; then
-       return 0
-    fi
+       natgw_write_config "$natgw_cfg_new"
 
-    # Handle no change
-    if cmp "$natgw_cfg_old" "$natgw_cfg_new" >/dev/null 2>&1 ; then
-       return 1
-    fi
+       # Non-existent old returns true, no log message
+       if [ ! -f "$natgw_cfg_old" ]; then
+               return 0
+       fi
 
-    echo "NAT gateway configuration has changed"
-    return 0
-}
+       # Handle no change
+       if cmp "$natgw_cfg_old" "$natgw_cfg_new" >/dev/null 2>&1; then
+               return 1
+       fi
 
-_natgw_clear ()
-{
-    _ip="${CTDB_NATGW_PUBLIC_IP%/*}"
-    _maskbits="${CTDB_NATGW_PUBLIC_IP#*/}"
-
-    delete_ip_from_iface \
-       "$CTDB_NATGW_PUBLIC_IFACE" "$_ip" "$_maskbits" >/dev/null 2>&1
-    for _net_gw in $CTDB_NATGW_STATIC_ROUTES ; do
-       _net="${_net_gw%@*}"
-       ip route del "$_net" metric 10 >/dev/null 2>/dev/null
-    done
-
-    # Delete the masquerading setup from a previous iteration where we
-    # were the NAT-GW
-    iptables -D POSTROUTING -t nat \
-       -s "$CTDB_NATGW_PRIVATE_NETWORK" ! -d "$CTDB_NATGW_PRIVATE_NETWORK" \
-       -j MASQUERADE >/dev/null 2>/dev/null
-
-    iptables -D INPUT -p tcp --syn -d "${_ip}/32" -j REJECT 2>/dev/null
+       echo "NAT gateway configuration has changed"
+       return 0
 }
 
-natgw_clear ()
+_natgw_clear()
 {
-    if [ -r "$natgw_cfg_old" ] ; then
-       (. "$natgw_cfg_old" ; _natgw_clear)
-    else
-       _natgw_clear
-    fi
+       _ip="${CTDB_NATGW_PUBLIC_IP%/*}"
+       _maskbits="${CTDB_NATGW_PUBLIC_IP#*/}"
+
+       delete_ip_from_iface \
+               "$CTDB_NATGW_PUBLIC_IFACE" "$_ip" "$_maskbits" >/dev/null 2>&1
+       for _net_gw in $CTDB_NATGW_STATIC_ROUTES; do
+               _net="${_net_gw%@*}"
+               ip route del "$_net" metric 10 >/dev/null 2>/dev/null
+       done
+
+       # Delete the masquerading setup from a previous iteration where we
+       # were the NAT-GW
+       iptables -D POSTROUTING -t nat \
+               -s "$CTDB_NATGW_PRIVATE_NETWORK" ! -d "$CTDB_NATGW_PRIVATE_NETWORK" \
+               -j MASQUERADE >/dev/null 2>/dev/null
+
+       iptables -D INPUT -p tcp --syn -d "${_ip}/32" -j REJECT 2>/dev/null
 }
 
-natgw_set_leader ()
+natgw_clear()
 {
-    set_proc sys/net/ipv4/ip_forward 1
-    iptables -A POSTROUTING -t nat \
-       -s "$CTDB_NATGW_PRIVATE_NETWORK" ! -d "$CTDB_NATGW_PRIVATE_NETWORK" \
-       -j MASQUERADE
-
-    # block all incoming connections to the NATGW IP address
-    ctdb_natgw_public_ip_host="${CTDB_NATGW_PUBLIC_IP%/*}/32"
-    iptables -D INPUT -p tcp --syn \
-       -d "$ctdb_natgw_public_ip_host" -j REJECT 2>/dev/null
-    iptables -I INPUT -p tcp --syn \
-       -d "$ctdb_natgw_public_ip_host" -j REJECT 2>/dev/null
-
-    ip addr add "$CTDB_NATGW_PUBLIC_IP" dev "$CTDB_NATGW_PUBLIC_IFACE"
-    for _net_gw in $CTDB_NATGW_STATIC_ROUTES ; do
-       _net="${_net_gw%@*}"
-       if [ "$_net" != "$_net_gw" ] ; then
-           _gw="${_net_gw#*@}"
+       if [ -r "$natgw_cfg_old" ]; then
+               (
+                       . "$natgw_cfg_old"
+                       _natgw_clear
+               )
        else
-           _gw="$CTDB_NATGW_DEFAULT_GATEWAY"
+               _natgw_clear
        fi
+}
 
-       [ -n "$_gw" ] || continue
-       ip route add "$_net" metric 10 via "$_gw"
-    done
+natgw_set_leader()
+{
+       set_proc sys/net/ipv4/ip_forward 1
+       iptables -A POSTROUTING -t nat \
+               -s "$CTDB_NATGW_PRIVATE_NETWORK" ! -d "$CTDB_NATGW_PRIVATE_NETWORK" \
+               -j MASQUERADE
+
+       # block all incoming connections to the NATGW IP address
+       ctdb_natgw_public_ip_host="${CTDB_NATGW_PUBLIC_IP%/*}/32"
+       iptables -D INPUT -p tcp --syn \
+               -d "$ctdb_natgw_public_ip_host" -j REJECT 2>/dev/null
+       iptables -I INPUT -p tcp --syn \
+               -d "$ctdb_natgw_public_ip_host" -j REJECT 2>/dev/null
+
+       ip addr add "$CTDB_NATGW_PUBLIC_IP" dev "$CTDB_NATGW_PUBLIC_IFACE"
+       for _net_gw in $CTDB_NATGW_STATIC_ROUTES; do
+               _net="${_net_gw%@*}"
+               if [ "$_net" != "$_net_gw" ]; then
+                       _gw="${_net_gw#*@}"
+               else
+                       _gw="$CTDB_NATGW_DEFAULT_GATEWAY"
+               fi
+
+               [ -n "$_gw" ] || continue
+               ip route add "$_net" metric 10 via "$_gw"
+       done
 }
 
-natgw_set_follower ()
+natgw_set_follower()
 {
-    _natgwip="$1"
+       _natgwip="$1"
 
-    for _net_gw in $CTDB_NATGW_STATIC_ROUTES ; do
-       _net="${_net_gw%@*}"
-       ip route add "$_net" via "$_natgwip" metric 10
-    done
+       for _net_gw in $CTDB_NATGW_STATIC_ROUTES; do
+               _net="${_net_gw%@*}"
+               ip route add "$_net" via "$_natgwip" metric 10
+       done
 }
 
-natgw_ensure_leader ()
+natgw_ensure_leader()
 {
-    # Intentional word splitting here
-    # shellcheck disable=SC2046
-    set -- $("${CTDB_HELPER_BINDIR}/ctdb_natgw" leader)
-    natgwleader="${1:--1}" # Default is -1, for failure above
-    natgwip="$2"
-
-    if [ "$natgwleader" = "-1" ]; then
-       # Fail...
-       die "There is no NATGW leader node"
-    fi
+       # Intentional word splitting here
+       # shellcheck disable=SC2046
+       set -- $("${CTDB_HELPER_BINDIR}/ctdb_natgw" leader)
+       natgwleader="${1:--1}" # Default is -1, for failure above
+       natgwip="$2"
+
+       if [ "$natgwleader" = "-1" ]; then
+               # Fail...
+               die "There is no NATGW leader node"
+       fi
 }
 
-natgw_leader_has_changed ()
+natgw_leader_has_changed()
 {
-    if [ -r "$natgw_leader_old" ] ; then
-       read -r _old_natgwleader <"$natgw_leader_old"
-    else
-       _old_natgwleader=""
-    fi
-    [ "$_old_natgwleader" != "$natgwleader" ]
+       if [ -r "$natgw_leader_old" ]; then
+               read -r _old_natgwleader <"$natgw_leader_old"
+       else
+               _old_natgwleader=""
+       fi
+       [ "$_old_natgwleader" != "$natgwleader" ]
 }
 
-natgw_save_state ()
+natgw_save_state()
 {
-    echo "$natgwleader" >"$natgw_leader_old"
-    # Created by natgw_config_has_changed()
-    mv "$natgw_cfg_new" "$natgw_cfg_old"
+       echo "$natgwleader" >"$natgw_leader_old"
+       # Created by natgw_config_has_changed()
+       mv "$natgw_cfg_new" "$natgw_cfg_old"
 }
 
-
 case "$1" in
 setup)
        natgw_check_config
@@ -194,7 +196,7 @@ startup)
        # Error if CTDB_NATGW_PUBLIC_IP is listed in public addresses
        ip_pat=$(echo "$CTDB_NATGW_PUBLIC_IP" | sed -e 's@\.@\\.@g')
        ctdb_public_addresses="${CTDB_BASE}/public_addresses"
-       if grep -q "^${ip_pat}[[:space:]]" "$ctdb_public_addresses" ; then
+       if grep -q "^${ip_pat}[[:space:]]" "$ctdb_public_addresses"; then
                die "ERROR: CTDB_NATGW_PUBLIC_IP same as a public address"
        fi
 
@@ -202,7 +204,7 @@ startup)
        set_proc sys/net/ipv4/conf/all/arp_announce 2
        ;;
 
-updatenatgw|ipreallocated)
+updatenatgw | ipreallocated)
        natgw_check_config
 
        natgw_ensure_leader
@@ -213,9 +215,9 @@ updatenatgw|ipreallocated)
 
        pnn=$(ctdb_get_pnn)
        if [ "$pnn" = "$natgwleader" ]; then
-           natgw_set_leader
+               natgw_set_leader
        else
-           natgw_set_follower "$natgwip"
+               natgw_set_follower "$natgwip"
        fi
 
        # flush our route cache
@@ -225,7 +227,7 @@ updatenatgw|ipreallocated)
        natgw_save_state
        ;;
 
-shutdown|removenatgw)
+shutdown | removenatgw)
        natgw_check_config
        natgw_clear
        ;;
@@ -233,8 +235,8 @@ shutdown|removenatgw)
 monitor)
        natgw_check_config
 
-       if [ -n "$CTDB_NATGW_PUBLIC_IFACE" ] ; then
-           interface_monitor "$CTDB_NATGW_PUBLIC_IFACE" || exit 1
+       if [ -n "$CTDB_NATGW_PUBLIC_IFACE" ]; then
+               interface_monitor "$CTDB_NATGW_PUBLIC_IFACE" || exit 1
        fi
        ;;
 esac
index 47408fa359ff1cfaeec7821d7337e0d7e3bf1b28..d4fda5da11a06039213494f9253184e57d6d13e5 100755 (executable)
@@ -96,7 +96,7 @@ script_log()
 
        case "$CTDB_LOGGING" in
        file:)
-               if [ -n "$*" ] ; then
+               if [ -n "$*" ]; then
                        echo "$*"
                else
                        cat
@@ -313,7 +313,7 @@ update_my_public_ip_addresses()
                        _pnn=$(ctdb_get_pnn)
                        $CTDB -X ip |
                                awk -F'|' -v pnn="$_pnn" \
-                                   '$3 == pnn {print $2}' >"$_new"
+                                       '$3 == pnn {print $2}' >"$_new"
                        ;;
                esac
 
@@ -993,13 +993,13 @@ failcount_incr()
        if _failcount_validate_threshold "$_unhealthy_threshold" "$_thing"; then
                if [ "$_failcount" -ge "$_unhealthy_threshold" ]; then
                        printf 'ERROR: %s: fail count %d >= threshold %d\n' \
-                              "$_thing" \
-                              "$_failcount" \
-                              "$_unhealthy_threshold"
+                               "$_thing" \
+                               "$_failcount" \
+                               "$_unhealthy_threshold"
                        # Only print output when exceeding the
                        # unhealthy threshold
-                       if [ "$_failcount" -eq "$_unhealthy_threshold" ] && \
-                                  [ -n "$_output" ]; then
+                       if [ "$_failcount" -eq "$_unhealthy_threshold" ] &&
+                               [ -n "$_output" ]; then
                                echo "$_output"
                        fi
                        exit 1
@@ -1013,9 +1013,9 @@ failcount_incr()
        fi
 
        printf 'WARNING: %s: fail count %d >= threshold %d\n' \
-              "$_thing" \
-              "$_failcount" \
-              "$_warn_threshold"
+               "$_thing" \
+               "$_failcount" \
+               "$_warn_threshold"
        if [ "$_failcount" -eq "$_warn_threshold" ] && [ -n "$_output" ]; then
                # Only print output when exceeding the warning threshold
                echo "$_output"