Harden shell commands
Also improve/add MacOS readlink compatibility.
Change-Id: I9d78e8a271b85b6810d307b6ed0072c1ec13bfa6
diff --git a/test/docker/run.sh b/test/docker/run.sh
index d4ae3fa..ef6f771 100755
--- a/test/docker/run.sh
+++ b/test/docker/run.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
-readlink --canonicalize / &> /dev/null || readlink() { greadlink "$@" ; } # for MacOS
+readlink -f / &> /dev/null || readlink() { greadlink "$@" ; } # for MacOS
MYDIR=$(dirname -- "$(readlink -f -- "$0")")
ARTIFACTS=$MYDIR/gerrit/artifacts
@@ -78,13 +78,13 @@
COMPOSE_ARGS=(--project-name "$PROJECT_NAME" -f "$COMPOSE_YAML")
check_prerequisite
mkdir -p -- "$ARTIFACTS"
-[ -n "$EVENTS_PLUGIN_JAR" ] && cp -f "$EVENTS_PLUGIN_JAR" "$ARTIFACTS/events.jar"
+[ -n "$EVENTS_PLUGIN_JAR" ] && cp -f -- "$EVENTS_PLUGIN_JAR" "$ARTIFACTS/events.jar"
if [ ! -e "$ARTIFACTS/events.jar" ] ; then
MISSING="Missing $ARTIFACTS/events.jar"
[ -n "$EVENTS_PLUGIN_JAR" ] && die "$MISSING, check for copy failure?"
usage "$MISSING, did you forget --events-plugin-jar?"
fi
-[ -n "$GERRIT_WAR" ] && cp -f "$GERRIT_WAR" "$ARTIFACTS/gerrit.war"
+[ -n "$GERRIT_WAR" ] && cp -f -- "$GERRIT_WAR" "$ARTIFACTS/gerrit.war"
progress "Building docker images" build_images
run_events_plugin_tests ; RESULT=$?
cleanup
diff --git a/test/test_events_plugin.sh b/test/test_events_plugin.sh
index f44d51e..6d88db9 100755
--- a/test/test_events_plugin.sh
+++ b/test/test_events_plugin.sh
@@ -118,8 +118,8 @@
[ -n "$count" ] || count=1
# Re-create the fifo to ensure that is is empty
- rm -f "$EVENT_FIFO"
- mkfifo "$EVENT_FIFO"
+ rm -f -- "$EVENT_FIFO"
+ mkfifo -- "$EVENT_FIFO"
head -n $count < "$EVENT_FIFO" > "$EVENTS" &
CAPTURE_PID_HEAD=$!
@@ -195,17 +195,18 @@
[ -n "$REF_BRANCH" ] || usage "ref branch not set"
}
-MYPROG=$(basename "$0")
-MYDIR=$(dirname "$0")
+readlink -f / &> /dev/null || readlink() { greadlink "$@" ; } # for MacOS
+MYDIR=$(dirname -- "$(readlink -f -- "$0")")
+MYPROG=$(basename -- "$0")
source "$MYDIR/lib_result.sh"
parseArgs "$@"
TEST_DIR=$MYDIR/../target/test
-rm -rf "$TEST_DIR"
-mkdir -p "$TEST_DIR"
-TEST_DIR=$(readlink -f "$TEST_DIR")
+rm -rf -- "$TEST_DIR"
+mkdir -p -- "$TEST_DIR"
+TEST_DIR=$(readlink -f -- "$TEST_DIR")
REST_API_CHANGES_URL="http://$SERVER:8080/a/changes"
GITURL=ssh://$SERVER:29418/$PROJECT
@@ -214,7 +215,7 @@
git ls-remote "$GITURL" | grep -q "$DEST_REF" || usage "invalid project/server/ref"
REPO_DIR=$TEST_DIR/repo
-q git init "$REPO_DIR"
+q git init -- "$REPO_DIR"
GIT_DIR="$REPO_DIR/.git"
FILE_A="$REPO_DIR/fileA"
@@ -287,7 +288,7 @@
# ------------------------- Compare them all to Core -------------------------
-out=$(diff "$EVENTS_CORE" "$EVENTS_PLUGIN")
+out=$(diff -- "$EVENTS_CORE" "$EVENTS_PLUGIN")
result "core/plugin diff" "$out"
exit $RESULT