From 812ac7a43293c6e8f17ef6a7fd6026613b87c221 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Mon, 7 Apr 2025 18:58:24 +0200 Subject: [PATCH] refactor(hooks): update script download mechanism in dstr.sh --- hooks/dstr.sh | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/hooks/dstr.sh b/hooks/dstr.sh index e396c46..401df6d 100644 --- a/hooks/dstr.sh +++ b/hooks/dstr.sh @@ -1,20 +1,27 @@ #!/bin/bash # URL to the raw script file -SCRIPT_URL="https://git.kjan.de/jank/scripts/raw/branch/main/hooks/pre-recieve.sh" +SCRIPT_URL="https://gitea.example.com/org/hooks-repo/raw/branch/main/semantic-commit-validator.sh" -# Try curl first, then fall back to wget if curl is not available +# Temporary file for the downloaded script (necessary to execute it properly) +TEMP_SCRIPT=$(mktemp) +trap 'rm -f "$TEMP_SCRIPT"' EXIT + +# Download the script (try curl, fall back to wget) if command -v curl &>/dev/null; then - # Pass standard input to the downloaded script and preserve exit code - EXITCODE=0 - # Read all input into a variable so we can pass it to the downloaded script - INPUT=$(cat) - echo "$INPUT" | (curl -s "$SCRIPT_URL" | bash) || EXITCODE=$? - exit $EXITCODE + curl -s -o "$TEMP_SCRIPT" "$SCRIPT_URL" else - # Fall back to wget if curl is not available - EXITCODE=0 - INPUT=$(cat) - echo "$INPUT" | (wget -q -O - "$SCRIPT_URL" | bash) || EXITCODE=$? - exit $EXITCODE + wget -q -O "$TEMP_SCRIPT" "$SCRIPT_URL" fi + +if [ ! -s "$TEMP_SCRIPT" ]; then + echo "Error: Could not download validation script from $SCRIPT_URL" + exit 1 +fi + +# Make the script executable +chmod +x "$TEMP_SCRIPT" + +# Pass all input to the downloaded script and preserve its exit code +cat | "$TEMP_SCRIPT" +exit $?