Last active
August 29, 2015 14:06
-
-
Save dmitrythaler/9f5e29df1366b3fd92de to your computer and use it in GitHub Desktop.
post-receive git hook, shared repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 2 points assumed | |
# * web server and repository are/can-be placed on different boxes | |
# * one can login to repository box without manual password entering - rsa keys are keychained by ssh-agent | |
PRODUCTIONBRANCH='master' | |
DEVBRANCH='dev' | |
PRODUCTIONPATH='/var/www/path/to/prod/server' | |
DEVPATH='/var/www/path/to/dev/server' | |
WEBSERVERBOX='webserverthere.example.com' | |
SSHPORT=1022 | |
while read oldsha newsha REFNAME; do | |
echo post-receive script, refname: $REFNAME | |
if [[ $REFNAME == *$PRODUCTIONBRANCH* ]]; then | |
ssh -p $SSHPORT $WEBSERVERBOX "cd $PRODUCTIONPATH; git pull origin $PRODUCTIONBRANCH" | |
fi | |
if [[ $REFNAME == *$DEVBRANCH* ]]; then | |
ssh -p $SSHPORT $WEBSERVERBOX "cd $DEVPATH; git pull origin $DEVBRANCH" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment