#!/bin/sh ## ## Post-Update Hook to update Jekyll Website ## Copyright (C) 2016 Assaf Gordon ## License: GPLv2-or-later ## Example of a 'post-update' hook script ## to trigger a jekyll site rebuild after a push to a git repository. ## This script should be placed in the git repository's ./hooks/ directory ## as 'post-update' (and be made executable). ## ## After every 'push' to the repository, the script will rebuild ## the jekyll static web-pages (by default, in ${HOME}/jekyll/www/[PROJECT]). ## Point your webserver's root directory to this directory and it will ## serve the website. ## ## The BASEDIR directory must be writable by the user running the git push ## (e.g. gitolite3 user if using gitolite). It must be readable by the ## web-server user (e.g. www-data on Debian/ubuntu). ## ## see: ## http://demonastery.org/2012/11/jekyll-gitolite-hook/ ## http://blog.zerosum.org/2010/11/01/pure-git-deploy-workflow.html die() { BASE=$(basename "$0") echo "$BASE: error: $@" >&2 exit 1 } # Get project name PROJECT=$(basename "$PWD") PROJECT=${PROJECT%.git} BASEDIR=${HOME}/jekyll/ WORKDIR=${BASEDIR}/cache/${PROJECT} SITEDIR=${BASEDIR}/www/${PROJECT} ## ## Directory when the checked out repository is ## mkdir -p "$WORKDIR" "$SITEDIR" \ || die "failed to create Jekyll directories" ## ## Update to the latest version ## git --work-tree=${WORKDIR}/ reset --hard \ || die "failed to checkout latest revision on '$WORKDIR'" # Abort if no Jekyll config found test -e "${WORKDIR}/_config.yml" \ || die "no Jekyll _config.yml file found. aborting" ## ## Rebuild ## echo "=== Running Jekyll ===" jekyll build --source "$WORKDIR" \ --destination "$SITEDIR" \ || die "Jekyll failed to build website '$WORKDIR'"