#!/usr/bin/env bash cd /var/www/hugo/site FORCE="$1" # Pull URL from env if it exists, otherwise var2. BASEURL="${BASEURL:-$2}" declare baseurl if [[ -n "$BASEURL" ]]; then baseurl="-b $BASEURL" fi echo "*** Running cronjob @ `date` ***" echo "FORCE=$FORCE" echo "BASEURL=$BASEURL" echo "baseurl=$baseurl" # 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 && -z $FORCE ]]; 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. set -x /usr/local/bin/hugo $baseurl --gc --minify set +x status="$?" echo "* Hugo status is '$status', FORCE is '$FORCE'." 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