51 lines
1.3 KiB
Bash
Executable File
51 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# 2025-10-14 Hyperling
|
|
# Copied cronjob.sh from env-docker/Config/Hugo-Example/files/ to use for this
|
|
# project so that docker container can do periodic git pulls rather than having
|
|
# to reload /rebuild the container each time a release is pushed out.
|
|
|
|
## Setup ##
|
|
|
|
DIR="$(dirname -- "${BASH_SOURCE[0]}")"
|
|
PROG="$(basename -- "${BASH_SOURCE[0]}")"
|
|
cd $DIR
|
|
DIR="`pwd`"
|
|
NAME="'$PROG'"
|
|
|
|
function log {
|
|
echo -e "`date` : $NAME - $1"
|
|
}
|
|
|
|
function reload-project {
|
|
## Kill node.js which will complete run.sh and restart any Docker containers.
|
|
#pkill node
|
|
# Do not kill program, just use the new files and if run.sh or main.js were
|
|
# changed then they can get reloaded manually or by the nightly backup.
|
|
log "Project reloaded successfully!"
|
|
}
|
|
|
|
## Main ##
|
|
|
|
# Pull any updates, and if the project is already up to date, exit successfully.
|
|
output="`git pull`"
|
|
git_status="$?"
|
|
|
|
echo "$output" | grep -v "up to date"
|
|
grep_status="$?"
|
|
|
|
log "Pull status is '$git_status', anything but 'up to date' is '$grep_status'."
|
|
|
|
if [[ $git_status != 0 ]]; then
|
|
log "*** ERROR: Git reported a failure! ***"
|
|
exit 1
|
|
elif [[ $git_status == 0 && $grep_status == 0 ]]; then
|
|
reload-project
|
|
elif [[ $git_status == 0 && $grep_status != 0 ]]; then
|
|
log "Site is already up to date, exiting."
|
|
exit 0
|
|
else
|
|
log "*** WARNING: Unknown Situation ***"
|
|
fi
|
|
|
|
exit 0
|