#!/bin/bash
-set -e
-
tmpfile1=$(mktemp -p .)
-if [ ! -w $tmpfile1 ] ; then
- echo "Failed to create tmp file" >&2
- exit 0
-fi
-
-tmpfile2=$(mktemp -p .)
-if [ ! -w $tmpfile2 ] ; then
- echo "Failed to create tmp file" >&2
- exit 0
+if [ ! -w "$tmpfile1" ] ; then
+ # cwd might be readonly, mark as skip.
+ echo "Failed to create tmp file" >&2
+ exit 77
fi
trap "rm -rf $tmpfile1 $tmpfile2" EXIT # cleanup if aborted
+set -e
+
+tmpfile2=$(mktemp -p .)
RULESET1="add table x"
RULESET2="include \"$tmpfile1\""
# instead of return value of nft.
-tmpfile1=$(mktemp -p .)
-if [ ! -w $tmpfile1 ] ; then
+tmpfile1=$(mktemp)
+if [ ! -w "$tmpfile1" ] ; then
echo "Failed to create tmp file" >&2
- exit 0
+ exit 1
fi
-tmpfile2=$(mktemp -p .)
-if [ ! -w $tmpfile2 ] ; then
+trap "rm -rf $tmpfile1 $tmpfile2 $tmpfile3 $tmpfile4" EXIT # cleanup if aborted
+
+tmpfile2=$(mktemp)
+if [ ! -w "$tmpfile2" ] ; then
echo "Failed to create tmp file" >&2
- exit 0
+ exit 1
fi
-tmpfile3=$(mktemp -p .)
-if [ ! -w $tmpfile3 ] ; then
+tmpfile3=$(mktemp)
+if [ ! -w "$tmpfile3" ] ; then
echo "Failed to create tmp file" >&2
- exit 0
+ exit 1
fi
-tmpfile4=$(mktemp -p .)
-if [ ! -w $tmpfile4 ]; then
+tmpfile4=$(mktemp)
+if [ ! -w "$tmpfile4" ]; then
echo "Failed to create tmp file" >&2
- exit 0
+ exit 1
fi
-trap "rm -rf $tmpfile1 $tmpfile2 $tmpfile3 $tmpfile4" EXIT # cleanup if aborted
-
RULESET1="include \"$tmpfile2\""
RULESET2="include \"$tmpfile3\""
RULESET3="add rule x y anything everything" # wrong nft syntax
$NFT -f $tmpfile1 2> $tmpfile4
-var=$(awk -F: '$4==" Error"{print $1;exit;}' $tmpfile4)
+var=$(awk -F: '$4==" Error"{print $1;exit;}' "$tmpfile4")
if [ $var == "$tmpfile3" ]; then
echo "E: Test failed" >&2