From 44a2404eaf7a2dfaad07fab472f8edd09f514486 Mon Sep 17 00:00:00 2001 From: Valentin Brandl Date: Mon, 5 Jun 2017 15:31:47 +0200 Subject: [PATCH] Add post-receive hook for automated deployments --- hooks/post-receive | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 hooks/post-receive diff --git a/hooks/post-receive b/hooks/post-receive new file mode 100644 index 0000000..40db5ed --- /dev/null +++ b/hooks/post-receive @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +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 + +rm -rf $WORKING_DIRECTORY +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 + +git clone $GIT_REPO $WORKING_DIRECTORY +cd $WORKING_DIRECTORY +git submodule update --init --recursive --remote +rm -rf $PUBLIC_WWW/* +hugo -s $WORKING_DIRECTORY -d ${PUBLIC_WWW} -b "https://${MY_DOMAIN}" +find $PUBLIC_WWW -type f \( -name '*.html' -o -name '*.js' -o -name '*.css' -o -name '*.xml' -o -name '*.svg' \) -exec gzip -v -k -f --best {} \; -exec touch -r {} "{}.gz" \; +rm -rf $WORKING_DIRECTORY +trap - EXIT