#!/usr/bin/env bash REPO="$1" echo "REPO=$REPO" PROD="$2" typeset -u PROD echo "PROD=$PROD" DEV="$3" typeset -u DEV echo "DEV=$DEV" echo "*** Creating Git Repo ***" sudo -u hugo git clone --recurse-submodules $REPO /var/www/hugo/site status="$?" echo "*** Validating Git Repo ***" if [[ $status != 0 || ! -d /var/www/hugo/site/.git ]]; then echo "ERROR: Hugo project may not have cloned correctly. status='$status'" echo "Aborting." exit 1 fi echo "*** Copying Static Files to NGINX ***" sudo -u hugo /var/www/hugo/cronjob.sh echo "*** Starting Cron ***" service cron start if [[ "$PROD" == "Y"* || "$PROD" == "T"* ]]; then echo "*** Starting Production Server Loop ***" while true; do curl -sS http://localhost:80 > /dev/null || { echo "* Prod server not detected, starting..." service nginx start } sleep 15 done & cd /var/log/nginx tail -f access.log error.log & fi if [[ "$DEV" == "Y"* || "$DEV" == "T"* ]]; then echo "*** Starting Development Server Loop ***" while true; do curl -sS http://localhost:1380 > /dev/null || { echo "* Dev server not detected, starting..." cd /var/www/hugo/site killall hugo 2>/dev/null sudo -u hugo hugo server -D --noBuildLock --bind 0.0.0.0 -p 1380 & } sleep 30 done & fi cd echo "*** Finished $0 ***" wait -n exit $?