summaryrefslogtreecommitdiffstats
path: root/iptables/iptables-apply
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2023-08-01 16:56:42 +0200
committerPhil Sutter <phil@nwl.cc>2023-08-01 17:16:37 +0200
commit9f98550d58a49fc95d529ebdc0173579d957b425 (patch)
treeea2075aa1bd03b0c279c5dba103914e7d1ce7ed5 /iptables/iptables-apply
parent4d9453233538200e9663c6bd0c2df09e1671b5f4 (diff)
iptables-apply: Eliminate shellcheck warnings
Actual warnings were only about use of '-a' in bracket expressions (replace by '&&' pipeline) and the immediate evaluation of the variable in trap command. The remaining changes silence info-level messages: missing quoting around variables, pointless '$' in arithmetic expressions, backticks instead of $(...), missing '-r' parameter when calling read and an awkward negated '-z' check. Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'iptables/iptables-apply')
-rwxr-xr-xiptables/iptables-apply16
1 files changed, 8 insertions, 8 deletions
diff --git a/iptables/iptables-apply b/iptables/iptables-apply
index 3a7df5e3..c603fb21 100755
--- a/iptables/iptables-apply
+++ b/iptables/iptables-apply
@@ -141,9 +141,9 @@ for opt in $OPTS; do
;;
(*)
case "${OPT_STATE:-}" in
- (SET_TIMEOUT) eval TIMEOUT=$opt;;
+ (SET_TIMEOUT) eval TIMEOUT="$opt";;
(SET_SAVEFILE)
- eval SAVEFILE=$opt
+ eval SAVEFILE="$opt"
[ -z "$SAVEFILE" ] && SAVEFILE="$DEF_SAVEFILE"
;;
esac
@@ -163,13 +163,13 @@ done
# Validate parameters
if [ "$TIMEOUT" -ge 0 ] 2>/dev/null; then
- TIMEOUT=$(($TIMEOUT))
+ TIMEOUT=$((TIMEOUT))
else
echo "Error: timeout must be a positive number" >&2
exit 1
fi
-if [ -n "$SAVEFILE" -a -e "$SAVEFILE" -a ! -w "$SAVEFILE" ]; then
+if [ -n "$SAVEFILE" ] && [ -e "$SAVEFILE" ] && [ ! -w "$SAVEFILE" ]; then
echo "Error: savefile not writable: $SAVEFILE" >&2
exit 8
fi
@@ -205,8 +205,8 @@ esac
### Begin work
# Store old iptables rules to temporary file
-TMPFILE=`mktemp /tmp/$PROGNAME-XXXXXXXX`
-trap "rm -f $TMPFILE" EXIT HUP INT QUIT ILL TRAP ABRT BUS \
+TMPFILE=$(mktemp "/tmp/$PROGNAME-XXXXXXXX")
+trap 'rm -f $TMPFILE' EXIT HUP INT QUIT ILL TRAP ABRT BUS \
FPE USR1 SEGV USR2 PIPE ALRM TERM
if ! "$SAVE" >"$TMPFILE"; then
@@ -257,13 +257,13 @@ esac
# Prompt user for confirmation
echo -n "Can you establish NEW connections to the machine? (y/N) "
-read -n1 -t "$TIMEOUT" ret 2>&1 || :
+read -r -n1 -t "$TIMEOUT" ret 2>&1 || :
case "${ret:-}" in
(y*|Y*)
# Success
echo
- if [ ! -z "$SAVEFILE" ]; then
+ if [ -n "$SAVEFILE" ]; then
# Write successfully applied rules to the savefile
echo "Writing successfully applied rules to '$SAVEFILE'..."
if ! "$SAVE" >"$SAVEFILE"; then