refactor(hooks): update script download mechanism in dstr.sh
This commit is contained in:
parent
ea04673ad1
commit
812ac7a432
1 changed files with 20 additions and 13 deletions
|
@ -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 $?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue