From 2c17785f9576670a86eabe5a6eb4a441551d0aa8 Mon Sep 17 00:00:00 2001 From: Dominic Reich Date: Tue, 14 Mar 2023 18:35:36 +0100 Subject: [PATCH] adds git hooks/post-receive.d/publish-website hook --- .git-post-receive-hook | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .git-post-receive-hook diff --git a/.git-post-receive-hook b/.git-post-receive-hook new file mode 100644 index 0000000..90982a6 --- /dev/null +++ b/.git-post-receive-hook @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +GIT_REPO=/var/lib/gitea/data/gitea-repositories/dominic/oe7drt-website.git +WORKING_DIR=${HOME}/oe7drt-website-working +PUBLIC_WWW=/var/www/oe7drt +BACKUP_WWW=/var/www/oe7drt-backup +MY_DOMAIN=oe7drt.com + +set -e + +rm -rf ${WORKING_DIR} +rsync -aqz ${PUBLIC_WWW}/ ${BACKUP_WWW} +trap "echo 'A problem occured. Reverting to backup.'; rsync -aqz --del ${BACKUP_WWW}/ ${PUBLIC_WWW}; rm -rf ${WORKING_DIR}" EXIT + +git clone ${GIT_REPO} ${WORKING_DIR} +rm -rf ${PUBLIC_WWW}/* +${HOME}/go/bin/hugo --gc --minify --cleanDestinationDir -s ${WORKING_DIR} -d ${PUBLIC_WWW} +rm -rf ${WORKING_DIR} +trap - EXIT