vbrandl.net/hooks/post-receive

31 lines
933 B
Plaintext
Raw Permalink Normal View History

#!/usr/bin/env bash
2017-06-05 18:53:32 +02:00
# 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...
2017-06-05 15:35:26 +02:00
git clone --recursive $GIT_REPO $WORKING_DIRECTORY
echo Deleting old version...
rm -rf $PUBLIC_WWW/*
echo Generating HTML...
2017-06-05 15:36:28 +02:00
$HOME/.local/bin/hugo -s $WORKING_DIRECTORY -d ${PUBLIC_WWW} -b "https://${MY_DOMAIN}"
2017-06-05 18:49:57 +02:00
# 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