Skip to content

Instantly share code, notes, and snippets.

@130db
Created April 18, 2013 23:48
Show Gist options
  • Save 130db/5417091 to your computer and use it in GitHub Desktop.
Save 130db/5417091 to your computer and use it in GitHub Desktop.
GIT post-update hook for gitalized web. Update master branch only when it's pushed to repositary
#!/bin/sh
host="api"
domain="example.com"
sites="/path/to/your/sites"
site="$sites/$host.$domain"
cd "$site" || exit
unset GIT_DIR
update_master()
{
echo
echo "$host.$domain"
echo "Update initialized"
echo " * Data wipe out ..."
sudo -u www-data rm -rf *
echo " * Preparing essential site folders ..."
sudo -u www-data mkdir -m 770 -p app/cache
sudo -u www-data mkdir -m 770 -p app/logs
sudo -u www-data mkdir -p app/config
sudo -u www-data mkdir -p root/assets
echo " * Site reset & update ..."
sudo -u www-data git reset --hard
sudo -u www-data git clean -fX
sudo -u www-data git pull
if [ $? = 0 ]; then
echo "Site update finalized!"
else
echo "Site update FAILED!"
fi
echo
}
case " $* " in
*' refs/heads/master '*)
update_master
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment