post-update.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 control the script by editing post-update.conf
  15. #
  16. # ~~~ HERE BE DRAGONS ! ~~~
  17. source ./hooks/post-update.conf
  18. TO_SUBMIT="["
  19. for HEAD in $@; do
  20. # We love bash too, but there a really fancy basename
  21. BRANCH=`basename $HEAD`
  22. # CUT, UNIX, No bash
  23. # BRANCH=$(echo $HEAD |cut -d / -f 3)
  24. # FUCK, BASHSIMS
  25. #echo $HEAD
  26. #IFS="/"
  27. #BRANCH=($HEAD)
  28. #BRANCH=${BRANCH[2]}
  29. 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"}')
  30. REST_OF_JSON=$REST_OF_JSON,\"branch\":\""${BRANCH}"\",
  31. REST_OF_JSON=$REST_OF_JSON,\"giturl\":\"$GITURL\",
  32. JSON_TO_SUBMIT=$JSON_TO_SUBMIT{\"$BRANCH\":$REST_OF_JSON\}
  33. JSON_TO_SUBMIT=$JSON_TO_SUBMIT}
  34. REST_OF_JSON=""
  35. TO_SUBMIT=$TO_SUBMIT$JSON_TO_SUBMIT","
  36. JSON_TO_SUBMIT=""
  37. done
  38. # BASH sorcery to remove the last character
  39. TO_SUBMIT=${TO_SUBMIT%?}"]"
  40. all=`mktemp`
  41. echo $TO_SUBMIT > $all
  42. SECRET=$(echo -n $TO_SUBMIT | openssl dgst -sha1 -hmac $SECRET_KEY)
  43. # Why does this produce a different digest?
  44. # SECRET1=$(openssl dgst -sha1 -hmac $SECRET_KEY $all)
  45. SECRET=`echo $SECRET | cut -d'=' -f2`
  46. curl -H "Content-Type: application/json" -H "${SECRET_KEY_NAME}:${SECRET}" \
  47. http://${SUBMIT_HOST}:${SUBMIT_PORT}/ --data @$all
  48. if [ $? -eq 0 ]; then
  49. rm $all
  50. fi