Last active
July 8, 2021 10:17
-
-
Save amfg/d84329fdd56b2733a5980308334428bd to your computer and use it in GitHub Desktop.
Simple GitLab webhook using netcat & bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
read request | |
TOKEN='secret token from gitlab' # from https://gitlab.com/{user}/{project}/settings/integrations | |
HAS_TOKEN=0 | |
while /bin/true; do | |
read header | |
[[ "$header" =~ 'X-Gitlab-Token' ]] && [[ "$header" =~ $TOKEN ]] && HAS_TOKEN=1; | |
[[ "$header" == $'\r' ]] && break; | |
done | |
[[ $HAS_TOKEN -eq 0 ]] && exit 0; | |
url="${request#POST }" | |
url="${url% HTTP/*}" | |
echo -e "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nOK\r\n\r\n" | |
([[ $url = "/optional/endpoint" ]] && $(cd /project && git checkout master && git pull)&>/dev/null) & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while [ 1 ]; do nc -l -p 9000 -q 5 -e ./handle.sh ; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment