Skip to content

Instantly share code, notes, and snippets.

@oodler577
Last active October 11, 2025 07:51
Show Gist options
  • Select an option

  • Save oodler577/f4e21869a44363663cbd9a29e3f8786d to your computer and use it in GitHub Desktop.

Select an option

Save oodler577/f4e21869a44363663cbd9a29e3f8786d to your computer and use it in GitHub Desktop.
Bash script to use on a shared host to handle github commit hook
#!/usr/bin/env bash
# cgi-bin/publish.sh (chmod +x)
SECRET='THIS IS YOUR SECRET WITH GITHUB' # <-- set this
SIG_HDR="${HTTP_X_HUB_SIGNATURE_256:-}" # e.g. sha256=abc123...
# read raw POST body (exact bytes)
BODY="$(dd bs=1 count="${CONTENT_LENGTH:-0}" status=none 2>/dev/null)"
# compute expected signature (hex) over raw body
HEX="$(printf %s "$BODY" | openssl dgst -sha256 -hmac "$SECRET" | sed -E 's/^.*= //')"
EXP="sha256=$HEX"
# simple compare; on mismatch, 403
if [[ "$SIG_HDR" != "$EXP" ]]; then
printf 'Status: 403 Forbidden\r\nContent-Type: text/plain\r\n\r\nforbidden\n'
exit 0
fi
# success
printf 'Content-Type: text/plain\r\n\r\nok\n'
cd ..
git pull origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment