Skip to content

Instantly share code, notes, and snippets.

@cesarmiquel
Created December 18, 2012 16:51
Show Gist options
  • Save cesarmiquel/4329655 to your computer and use it in GitHub Desktop.
Save cesarmiquel/4329655 to your computer and use it in GitHub Desktop.
#!/bin/bash -x
#
# Script que actualiza el codigo en el ambiente a donde se hace push
#
#
# The "post-receive" script is run after receive-pack has accepted a pack
# and the repository has been updated. It is passed arguments in through
# stdin in the form
# <oldrev> <newrev> <refname>
# For example:
# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
#
while read OLDREV NEWREV REFNAME
do
echo "Executing post-receive hook with args [$OLDREV] [$NEWREV] [$REFNAME]"
echo
HOST="none"
# DEV -------------------------------------------------------------------
if [ $REFNAME = 'refs/heads/project-master' ]
then
HOST='dev.server.com'
fi
# QA -------------------------------------------------------------------
if [ $REFNAME = 'refs/heads/project-qa' ]
then
HOST='qa.server.com'
fi
# PROD -------------------------------------------------------------------
if [ $REFNAME = 'refs/heads/project-prod' ]
then
HOST='prod.server.com'
fi
if [ $HOST != 'none' ]
then
echo
echo '---------------------------------------------------------------------'
echo "Sincronizando el codigo en [$HOST]"
echo '---------------------------------------------------------------------'
echo
ssh drupal@$HOST <<'ENDSSH'
cd /project/docroot
git pull
ENDSSH
echo
echo '---------------------------------------------------------------------'
echo "Codigo actualizado."
echo '---------------------------------------------------------------------'
echo
fi
done
exit 0
# vim: se ts=4 sw=4 si:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment