1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #!/bin/bash
- #
- #
- # This script is copyright Oz N Tiram <nahumoz@gmail.com>
- # It is distributed under the terms of GPLv3
- # To use this hook rename it to post-update
- # Also you need the following software packages installed
- # Take a look also in the companion config file
- # post-push.conf, you should edit it before using this hook
- #
- # * curl
- # * openssl
- #
- # ~~~ HERE BE DRAGONS ! ~~~
- source ./post-update.conf
- TO_SUBMIT="["
- for HEAD in $@; do
- # We love bash too, but there a really fancy basename
- BRANCH=`basename $HEAD`
- # CUT, UNIX, No bash
- # BRANCH=$(echo $HEAD |cut -d / -f 3)
- # FUCK, BASHSIMS
- #echo $HEAD
- #IFS="/"
- #BRANCH=($HEAD)
- #BRANCH=${BRANCH[2]}
- REST_OF_JSON=$(git --no-pager log -n 1 --format='{"hashes":{"commit":"%H", "tree":"%T", "parents":"%P"},"author":{"date":"%ai","name":"%an","email":"%ae"},"committer":{"date":"%ci","name":"%cn","email":"%ce"}')
- REST_OF_JSON=$REST_OF_JSON,\"branch\":\""${BRANCH}"\",
- REST_OF_JSON=$REST_OF_JSON,\"giturl\":\"$GITURL\",
- JSON_TO_SUBMIT=$JSON_TO_SUBMIT{\"$BRANCH\":$REST_OF_JSON\}
- JSON_TO_SUBMIT=$JSON_TO_SUBMIT}
- REST_OF_JSON=""
- TO_SUBMIT=$TO_SUBMIT$JSON_TO_SUBMIT","
- JSON_TO_SUBMIT=""
- done
- # BASH sorcery to remove the last character
- TO_SUBMIT=${TO_SUBMIT%?}"]"
- all=`mktemp`
- echo $TO_SUBMIT > $all
- SECRET=$(echo -n $TO_SUBMIT | openssl dgst -sha1 -hmac $SECRET_KEY)
- # Why does this produce a different digest?
- # SECRET1=$(openssl dgst -sha1 -hmac $SECRET_KEY $all)
- SECRET=`echo $SECRET | cut -d'=' -f2`
- curl -H "Content-Type: application/json" -H "${SECRET_KEY_NAME}:${SECRET}" \
- http://${SUBMIT_HOST}:${SUBMIT_PORT}/ --data @$all
- if [ $? -eq 0 ]; then
- rm $all
- fi
|