|  | @@ -1,20 +1,23 @@
 | 
	
		
			
				|  |  |  #!/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
 | 
	
		
			
				|  |  |  #
 | 
	
		
			
				|  |  | -# EDIT THE FOLLOWING VARIABLES TO FIT YOUR NEEDS
 | 
	
		
			
				|  |  | -# THE KEY SHOULD ALSO BE KNOWN ON THE SERVER THAT LISTENS TO SUBMITS
 | 
	
		
			
				|  |  | -SECRET_KEY=MOO_RONJA_FOO
 | 
	
		
			
				|  |  | -SUBMIT_HOST=127.0.0.1
 | 
	
		
			
				|  |  | -SUBMIT_PORT=8080
 | 
	
		
			
				|  |  | -GITURL="git@yourhost.domain:oz123/frank.git"
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +# ~~~ 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`
 | 
	
	
		
			
				|  | @@ -25,7 +28,7 @@ for HEAD in $@; do
 | 
	
		
			
				|  |  |  	#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=$(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\}
 | 
	
	
		
			
				|  | @@ -35,18 +38,16 @@ for HEAD in $@; do
 | 
	
		
			
				|  |  |  	JSON_TO_SUBMIT=""
 | 
	
		
			
				|  |  |  done
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -# BASH sourcery to remove the last character
 | 
	
		
			
				|  |  | +# 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)
 | 
	
		
			
				|  |  | -# echo $SECRET
 | 
	
		
			
				|  |  | -# echo $SECRET1
 | 
	
		
			
				|  |  |  SECRET=`echo $SECRET | cut -d'=' -f2`
 | 
	
		
			
				|  |  | -set -x
 | 
	
		
			
				|  |  | -curl -H "Content-Type: application/json" -H "X-Secret:${SECRET}" -X POST http://${SUBMIT_HOST}:${SUBMIT_PORT}/ --data @$all
 | 
	
		
			
				|  |  | +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
 |