Skip to content

Instantly share code, notes, and snippets.

@gravitano
Last active August 29, 2015 14:18
Show Gist options
  • Save gravitano/58d292295260210e1bdd to your computer and use it in GitHub Desktop.
Save gravitano/58d292295260210e1bdd to your computer and use it in GitHub Desktop.
New Git Hook Script (bash)
#!/bin/sh
#
## store the arguments given to the script
read oldrev newrev refname
# The deployed directory (the running site)
DEPLOYDIR=/var/www/html/
# Repository Directory
REPODIR=$HOME/repo.git
## Where to store the log information about the updates
LOGFILE=$REPODIR/post-receive.log
# The composer directory
COMPOSERDIR=composer
# Show User
echo "Logged as : " whoami
## Record the fact that the push has been received
echo -e "Received Push Request at $( date +%F )" >> $LOGFILE
echo " - Old SHA: $oldrev New SHA: $newrev Branch Name: $refname" >> $LOGFILE
## Down
php $DEPLOYDIR/artisan down
## Update the deployed copy
echo "Starting Deploy" >> $LOGFILE
echo "- Deploying"
GIT_WORK_TREE="$DEPLOYDIR" git checkout -f
echo "- OK"
echo "- Composer Hook : Updating Dependencies"
cd $DEPLOYDIR && $COMPOSERDIR update -v
echo "- OK"
## Run Hook
HOOK_SCRIPT=$DEPLOYDIR/build/hooks.sh
if [ -f $HOOK_SCRIPT ]; then
. $HOOK_SCRIPT
fi
## Live
php $DEPLOYDIR/artisan up
echo "- Done"
echo "Finished Deploy" >> $LOGFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment