# Print a message and exit.
die ()
{
- echo "$1" >&2 ; exit ${2:-1}
+ echo "$1" >&2 ; exit "${2:-1}"
}
not_implemented_exit_code=1
done
[ -n "$args" ] || usage
+# Want word splitting
+# shellcheck disable=SC2086
set -- $args
setup_tickles ()
{
# Make sure tickles file exists.
tickles_file="${CTDB_TEST_TMP_DIR}/fake-ctdb/tickles"
- mkdir -p $(dirname "$tickles_file")
+ mkdir -p "$(dirname "$tickles_file")"
touch "$tickles_file"
}
setup_tickles
echo "|source ip|port|destination ip|port|"
- while read _src _dst ; do
- if [ -z "$_ip" -o "$_ip" = "${_dst%:*}" ] ; then
- if [ -z "$_port" -o "$_port" = "${_dst##*:}" ] ; then
+ while read -r _src _dst ; do
+ if [ -z "$_ip" ] || [ "$_ip" = "${_dst%:*}" ] ; then
+ if [ -z "$_port" ] || [ "$_port" = "${_dst##*:}" ] ; then
echo "|${_src%:*}|${_src##*:}|${_dst%:*}|${_dst##*:}|"
fi
fi
_t=$(grep -F -v "${_src} $${_dst}" "$tickles_file")
else
_t=$(cat "$tickles_file")
- while read _src _dst ; do
+ while read -r _src _dst ; do
_t=$(echo "$_t" | grep -F -v "${_src} ${_dst}")
done
fi
if [ "$nodespec" = "all" ] ; then
nodes="$(seq 0 $((FAKE_CTDB_NUMNODES - 1)) )"
elif [ -n "$nodespec" ] ; then
- nodes="$(echo $nodespec | sed -e 's@,@ @g')"
+ nodes="$(echo "$nodespec" | sed -e 's@,@ @g')"
else
- node=$(ctdb_pnn)
+ nodes=$(ctdb_pnn)
fi
}
{
touch "$FAKE_CTDB_IP_LAYOUT"
+ # ShellCheck doesn't understand this flock pattern
+ # shellcheck disable=SC2094
(
flock 0
for _j in "$FAKE_CTDB_STATE/node-state/"*"/$_i" ; do
_tf="${_j%/*}" # dirname
_f="${_tf##*/}" # basename
- _this=$(( $_this | $_f ))
+ _this=$(( _this | _f ))
done
else
_this="0"
# process output line by line...
_pa="${CTDB_BASE}/public_addresses"
sed -e 's@/@ @' "$_pa" | sort | join - "$FAKE_CTDB_IP_LAYOUT" |
- while read _ip _bit _ifaces _pnn ; do
+ while read -r _ip _ _ifaces _pnn ; do
if $verbose ; then
# If more than 1 interface, assume all addresses are on the 1st.
_first_iface="${_ifaces%%,*}"
ip_reallocate # should be harmless and ensures we have good state
+ # ShellCheck doesn't understand this flock pattern
+ # shellcheck disable=SC2094
(
flock 0
_t="${FAKE_CTDB_IP_LAYOUT}.new"
- while read _i _pnn ; do
+ while read -r _i _pnn ; do
if [ "$_ip" = "$_i" ] ; then
echo "$_i $_target"
else
ctdb_enable ()
{
parse_nodespec
-
+
for _i in $nodes ; do
rm -f "${FAKE_CTDB_NODES_DISABLED}/${_i}"
done
ctdb_nodestatus ()
{
echo '|Node|IP|Disconnected|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|'
- _line=$(( $FAKE_CTDB_PNN + 1 ))
+ _line=$(( FAKE_CTDB_PNN + 1 ))
_ip=$(sed -e "${_line}p" "${CTDB_NATGW_NODES:-${CTDB_LVS_NODES}}")
echo "|${FAKE_CTDB_PNN}|${_ip}|0|0|0|0|0|0|0|Y|"
}
{
_t_setup "$1"
- while IFS="" read _line ; do
+ while IFS="" read -r _line ; do
_k=$(echo "$_line" | sed -n -e 's@^"\([^"]*\)" "[^"]*"$@\1@p')
_v=$(echo "$_line" | sed -e 's@^"[^"]*" "\([^"]*\)"$@\1@')
- [ -n "$_k" ] || die "ctdb ptrans: bad line \"${line}\""
+ [ -n "$_k" ] || die "ctdb ptrans: bad line \"${_line}\""
if [ -n "$_v" ] ; then
_t_put "$_k" "$_v"
else
[ -r "$_i" ] || continue
_k="${_i##*/}" # basename
_v=$(_t_get "$_k")
- _kn=$(echo -n "$_k" | wc -c)
- _vn=$(echo -n "$_v" | wc -c)
+ _kn=$(printf '%s' "$_k" | wc -c)
+ _vn=$(printf '%s' "$_v" | wc -c)
cat <<EOF
key(${_kn}) = "${_k}"
dmaster: 0
data(${_vn}) = "${_v}"
EOF
- _count=$(($_count + 1))
+ _count=$((_count + 1))
done
echo "Dumped ${_count} records"
# Assume -Y.
echo "|Name|LinkStatus|References|"
- while read _ip _iface ; do
+ while read -r _ip _iface ; do
case "$_ip" in
\#*) : ;;
*)
[ "$netid" = "tcp" ] || usage
host="$1" ; shift
- [ "$host" = "localhost" -o "$host" = "127.0.0.1" ] || usage
+ [ "$host" = "localhost" ] || [ "$host" = "127.0.0.1" ] || usage
- [ 1 -le $# -a $# -le 2 ] || usage
+ if [ $# -lt 1 ] || [ $# -gt 2 ]; then
+ usage
+ fi
p="$1"
v="$2"
# This is stupidly cummulative, but needs to happen after the
# initial split of the list above.
IFS="${IFS}:"
+ # Want glob expansion
+ # shellcheck disable=SC2086
set -- $i
# $1 = program, $2 = low version, $3 = high version
if [ "$1" = "$p" ] ; then
if [ -n "$v" ] ; then
- if [ "$2" -le "$v" -a "$v" -le "$3" ] ; then
+ if [ "$2" -le "$v" ] && [ "$v" -le "$3" ] ; then
echo "program ${p} version ${v} ready and waiting"
exit 0
else
exit 1
fi
else
- for j in $(seq $2 $3) ; do
+ for j in $(seq "$2" "$3") ; do
echo "program ${p} version ${j} ready and waiting"
done
exit 0
ip="${socket%:*}"
port="${socket##*:}"
- if [ "$ok_ports" != "|" -a "${ok_ports#*|${port}|}" = "$ok_ports" ] ; then
+ if [ "$ok_ports" != "|" ] &&
+ [ "${ok_ports#*|"${port}"|}" = "$ok_ports" ]; then
return 1
fi
- if [ "$ok_ips" != "|" -a "${ok_ips#*|${ip}|}" = "$ok_ips" ] ; then
+ if [ "$ok_ips" != "|" ] && [ "${ok_ips#*|"${ip}"|}" = "$ok_ips" ]; then
return 1
fi
echo "Recv-Q Send-Q Local Address:Port Peer Address:Port"
fi
+ # Yes, lose the quoting so we can do a hacky parsing job
+ # shellcheck disable=SC2048,SC2086
parse_filter $*
for i in $FAKE_NETSTAT_TCP_ESTABLISHED ; do
if [ -z "$FAKE_NETSTAT_TCP_ESTABLISHED_FILE" ] ; then
return
fi
- while read src dst ; do
+ while read -r src dst ; do
if filter_socket "$srcs" "$sports" "$src" ; then
echo 0 0 "$src" "$dst"
fi
EOF
fi
+ # Yes, lose the quoting so we can do a hacky parsing job
+ # shellcheck disable=SC2048,SC2086
parse_filter $*
_n=12345
shift $((OPTIND - 1))
$tcp || $unix || not_supported "$*"
+if [ -z "$all" ]; then
+ nosupported "$*"
+fi
if $tcp ; then
- if [ "$1" != "state" -o "$2" != "established" ] || $listen ; then
+ if [ "$1" != "state" ] || [ "$2" != "established" ] || $listen; then
usage
fi
shift 2
# Yes, lose the quoting so we can do a hacky parsing job
+ # shellcheck disable=SC2048,SC2086
ss_tcp_established $*
exit
fi
# Yes, lose the quoting so we can do a hacky parsing job
+ # shellcheck disable=SC2048,SC2086
unix_listen $*
exit