post-update.sh 1.6 KB

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