|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# Only this official platform archive has been pinned and verified. |
| 5 | +if [[ "$(uname -s)" != Linux || "$(uname -m)" != x86_64 ]]; then |
| 6 | + echo "Trusted review scanner bootstrap supports Linux amd64 only." >&2 |
| 7 | + exit 1 |
| 8 | +fi |
| 9 | + |
| 10 | +review_tools_root="$(mktemp -d "${RUNNER_TEMP:?}/clawsweeper-review-tools.XXXXXX")" |
| 11 | +case "$review_tools_root/" in |
| 12 | + "${GITHUB_WORKSPACE:?}/"*) echo "Review tools must be outside the checkout." >&2; exit 1 ;; |
| 13 | +esac |
| 14 | +chmod 700 "$review_tools_root" |
| 15 | +mkdir -m 700 "$review_tools_root/bin" "$review_tools_root/smoke" |
| 16 | +review_tools_ready=0 |
| 17 | +cleanup() { |
| 18 | + rm -rf "$review_tools_root/smoke" "$review_tools_root/archive.tar.gz" "$review_tools_root/stdout" "$review_tools_root/stderr" |
| 19 | + if [[ "$review_tools_ready" != 1 ]]; then rm -rf "$review_tools_root"; fi |
| 20 | +} |
| 21 | +trap cleanup EXIT |
| 22 | + |
| 23 | +curl --fail --show-error --silent --location \ |
| 24 | + "https://github.com/trufflesecurity/trufflehog/releases/download/v3.97.1/trufflehog_3.97.1_linux_amd64.tar.gz" \ |
| 25 | + --output "$review_tools_root/archive.tar.gz" |
| 26 | +printf '%s %s\n' \ |
| 27 | + "f863ea3a8d786f7d097870496c977944cce7372a2fe1e56707d965016e543ece" \ |
| 28 | + "$review_tools_root/archive.tar.gz" | sha256sum --check - |
| 29 | +tar -xzf "$review_tools_root/archive.tar.gz" -C "$review_tools_root/bin" trufflehog |
| 30 | +chmod 700 "$review_tools_root/bin/trufflehog" |
| 31 | +export PATH="$review_tools_root/bin:$PATH" |
| 32 | +version="$(env -i HOME="$review_tools_root" "$review_tools_root/bin/trufflehog" --version 2>&1)" |
| 33 | +[[ "$version" == "trufflehog 3.97.1" ]] |
| 34 | +printf 'A harmless review scanner installation check.\n' > "$review_tools_root/smoke/clean.txt" |
| 35 | +chmod 600 "$review_tools_root/smoke/clean.txt" |
| 36 | +if ! env -i HOME="$review_tools_root" TMPDIR="$review_tools_root" \ |
| 37 | + "$review_tools_root/bin/trufflehog" filesystem "$review_tools_root/smoke" \ |
| 38 | + --results=verified,unknown --fail --fail-on-scan-errors --no-update --json --no-color \ |
| 39 | + > "$review_tools_root/stdout" 2> "$review_tools_root/stderr"; then |
| 40 | + echo "Trusted review scanner smoke failed; diagnostics withheld." >&2 |
| 41 | + exit 1 |
| 42 | +fi |
| 43 | +if [[ -s "$review_tools_root/stdout" ]]; then |
| 44 | + echo "Trusted review scanner smoke emitted unexpected output; diagnostics withheld." >&2 |
| 45 | + exit 1 |
| 46 | +fi |
| 47 | +echo "$review_tools_root/bin" >> "$GITHUB_PATH" |
| 48 | +review_tools_ready=1 |
| 49 | +echo "Trusted TruffleHog 3.97.1 scanner installed and benign scan passed." |
0 commit comments