refactor(hooks): update script download mechanism in dstr.sh

This commit is contained in:
Jan K9f 2025-04-07 18:58:24 +02:00
parent ea04673ad1
commit 812ac7a432
Signed by: jank
GPG key ID: B9F475106B20F144

View file

@ -1,20 +1,27 @@
#!/bin/bash #!/bin/bash
# URL to the raw script file # 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 if command -v curl &>/dev/null; then
# Pass standard input to the downloaded script and preserve exit code curl -s -o "$TEMP_SCRIPT" "$SCRIPT_URL"
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
else else
# Fall back to wget if curl is not available wget -q -O "$TEMP_SCRIPT" "$SCRIPT_URL"
EXITCODE=0
INPUT=$(cat)
echo "$INPUT" | (wget -q -O - "$SCRIPT_URL" | bash) || EXITCODE=$?
exit $EXITCODE
fi 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 $?