post-update.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. #
  3. #
  4. # This script is copyright Oz N Tiram <nahumoz@gmail.com>
  5. # It is distributed under the terms of GPLv3
  6. # To use this hook rename it to post-update
  7. # Also you need the following software packages installed
  8. # Take a look also in the companion config file
  9. # post-push.conf, you should edit it before using this hook
  10. #
  11. # * curl
  12. # * openssl
  13. #
  14. # you can control the script by editing post-update.conf
  15. # ~~~ HERE BE DRAGONS ! ~~~
  16. source ./hooks/post-update.conf
  17. TO_SUBMIT="["
  18. for HEAD in $@; do
  19. # We love bash too, but there a really fancy basename
  20. BRANCH=`basename $HEAD`
  21. REST_OF_JSON=$(git --no-pager log -n 1 --format='{"branch": "XXXBRANCHXXX", "giturl": "XXXGITURLXXX", "hashes":{"commit":"%H", "tree":"%T", "parents":"%P"},"author":{"date":"%ai","name":"%an","email":"%ae"},"committer":{"date":"%ci","name":"%cn","email":"%ce"}}')
  22. REST_OF_JSON=${REST_OF_JSON/XXXBRANCHXXX/${BRANCH}}
  23. REST_OF_JSON=${REST_OF_JSON/XXXGITURLXXX/${GITURL}}
  24. JSON_TO_SUBMIT=$REST_OF_JSON
  25. TO_SUBMIT=$TO_SUBMIT$JSON_TO_SUBMIT","
  26. JSON_TO_SUBMIT=""
  27. done
  28. # BASH sorcery to remove the last character
  29. TO_SUBMIT=${TO_SUBMIT%?}"]"
  30. all=`mktemp`
  31. echo $TO_SUBMIT > $all
  32. SECRET=$(echo -n $TO_SUBMIT | openssl dgst -sha1 -hmac $SECRET_KEY)
  33. # Why does this produce a different digest?
  34. # SECRET1=$(openssl dgst -sha1 -hmac $SECRET_KEY $all)
  35. SECRET=`echo $SECRET | cut -d'=' -f2`
  36. curl -H "Content-Type: application/json" -H "${SECRET_KEY_NAME}:${SECRET}" \
  37. -X POST http://${SUBMIT_HOST}:${SUBMIT_PORT}/ --data @$all
  38. if [ $? -eq 0 ]; then
  39. rm $all
  40. fi