Skip to content

Instantly share code, notes, and snippets.

@seveas
Created November 2, 2012 20:19
Show Gist options
  • Save seveas/4004079 to your computer and use it in GitHub Desktop.
Save seveas/4004079 to your computer and use it in GitHub Desktop.
Post receive publishing hook
#!/bin/bash
#
# Hook to copy the contents of a static blog generator to its final location.
# Publishing is now a matter of 'git push blog'
set -e
read oldrev newrev refname
if [ $refname = refs/heads/master ]; then
rev=$(echo $newrev | cut -c1-7)
if [ -e /srv/blog/$rev ]; then
echo "Already published"
exit 0
fi
# Output is where the blog generator stores output. Copy it to a per-push
# directory and 'activate' it by pointing a symlink.
git archive HEAD:output/ --prefix $rev/ | (cd /srv/blog && tar -x)
chmod -R g+w /srv/blog/$rev
ln -snf $rev /srv/blog/current
echo "Published blog on http://blog......com"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment