From 57ade9f67d4cff2486e560ba81ae4569ef8ee3b2 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Sun, 17 Aug 2025 11:00:34 -0700 Subject: [PATCH] Give the cronjob some safety so that it churns less. --- Config/HugoExample/files/hugo.cronjob.sh | 25 +++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Config/HugoExample/files/hugo.cronjob.sh b/Config/HugoExample/files/hugo.cronjob.sh index 0e215bc..88accb9 100644 --- a/Config/HugoExample/files/hugo.cronjob.sh +++ b/Config/HugoExample/files/hugo.cronjob.sh @@ -2,10 +2,25 @@ cd /var/www/hugo/site -git pull && hugo --gc --minify -status="$?" +echo "*** Running cronjob @ `date` ***" -if [[ $status == 0 && -e public/* ]]; then - rm -rfv /var/www/html/* - mv -rfv public/* /var/www/html/ +# Pull any updates, and if the project is already up to date, exit successfully. +git pull | grep -v "up to date" +status="$?" +echo "* Pull status is '$status'." +if [[ $status != 0 && -e /var/www/html/index.html ]]; then + echo "* Site is already up to date and copied, exiting." + exit 0 fi + +# If the project was not already up to date, build the new files for NGINX. +hugo --gc --minify +status="$?" +echo "* Hugo status is '$status'." +if [[ $status == 0 && -e public/index.html ]]; then + echo "* Copying files..." + rm -rfv /var/www/html/* + mv -v public/* /var/www/html/ +fi + +exit 0