ensure_not_tainted_license: fix exit codes
grep returns exit code 1, if pattern was not found, and due to `set -e`
ensure_not_tainted_license.sh exits immediately with code 1. This change
fixes it.
This change also ensures that the correct code 1 is returned when the
pattern is found.
BUG=chromium:1163996
TEST=N/A
BRANCH=none
Signed-off-by: Sergey Frolov <sfrolov@google.com>
Change-Id: Idd33cec8795420ca1aab9ab1490a338a04d20257
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2638856
Tested-by: George Engelbrecht <engeg@google.com>
Commit-Queue: George Engelbrecht <engeg@google.com>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: George Engelbrecht <engeg@google.com>
diff --git a/scripts/image_signing/ensure_not_tainted_license.sh b/scripts/image_signing/ensure_not_tainted_license.sh
index daa00b5..7eab1c9 100755
--- a/scripts/image_signing/ensure_not_tainted_license.sh
+++ b/scripts/image_signing/ensure_not_tainted_license.sh
@@ -48,7 +48,10 @@
fi
tainted_tag="<!-- tainted -->"
- tainted_status=$(grep "${tainted_tag}" "${license}")
+ # Add "|| :" to the grep command to prevent it from returning error code 1 if
+ # no match is found, which would cause the script to exit immediately with
+ # error code 1 due to set -e.
+ tainted_status=$(grep "${tainted_tag}" "${license}") || :
if [[ -n "${tainted_status}" ]]; then
echo "${license}:"
echo "License file contains packages with LICENSE=TAINTED."
@@ -61,6 +64,7 @@
/^[[:space:]]*$/d
p
}' "${license}"
+ exit 1
fi
exit 0
}