#!/usr/bin/env bash # post-receive hook for automated deployment GIT_REPO=$HOME/vbrandl.git WORKING_DIRECTORY=$HOME/vbrandl-working PUBLIC_WWW="/var/www/vbrandl.net" BACKUP_WWW=$HOME/blog_backup MY_DOMAIN=www.vbrandl.net set -e echo Deleting old working directory... rm -rf $WORKING_DIRECTORY echo Creating backup... rsync -aqz ${PUBLIC_WWW}/ $BACKUP_WWW trap "echo 'A problem occurred. Reverting to backup.'; rsync -aqz --del $BACKUP_WWW/ $PUBLIC_WWW; rm -rf $WORKING_DIRECTORY" EXIT echo Cloning into working directory... git clone --recursive $GIT_REPO $WORKING_DIRECTORY echo Deleting old version... rm -rf $PUBLIC_WWW/* echo Generating HTML... $HOME/.local/bin/hugo -s $WORKING_DIRECTORY -d ${PUBLIC_WWW} -b "https://${MY_DOMAIN}" # ahead of time compression echo Compressing files ahead of time... make -C $PUBLIC_WWW -f $WORKING_DIRECTORY/Makefile echo Deleting working directory... rm -rf $WORKING_DIRECTORY trap - EXIT