Rename cronjob.sh to check_git.sh. Eventually do the same with the photo checker code so that it can be called from check_git.
This commit is contained in:
68
check_git.sh
Executable file
68
check_git.sh
Executable file
@@ -0,0 +1,68 @@
|
||||
#!/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 kill-project {
|
||||
# Kill node.js which will complete run.sh and restart any Docker containers.
|
||||
# This is more intended towards Development and Stage sites since Production
|
||||
# will only see git changes when a pull request is manually completed.
|
||||
log "Stopping continuous processes!"
|
||||
pkill node
|
||||
}
|
||||
|
||||
function reload-project {
|
||||
# Not much to do, run.sh and main.js automatically uses the latest files.
|
||||
rm -v files/photos/index.html
|
||||
# TBD/TODO: Call check_photos.sh once it has been pulled from run.sh.
|
||||
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', checking for changes is '$grep_status'."
|
||||
|
||||
# Check whether the continuously running jobs have been updated.
|
||||
echo "$output" | grep "main.js"
|
||||
main_changed="$?"
|
||||
echo "$output" | grep "run.sh"
|
||||
run_changed="$?"
|
||||
|
||||
# Determine where we've landed and whether we need to do anything.
|
||||
if [[ $git_status != 0 ]]; then
|
||||
log "*** ERROR: Git reported a failure! ***"
|
||||
exit 1
|
||||
elif [[ $git_status == 0 && ($main_changed == 0 || $run_changed == 0) ]]; then
|
||||
log "Either main ('$main_changed'), or run ('$run_changed') were changed!"
|
||||
kill-project
|
||||
elif [[ $git_status == 0 && $grep_status == 0 ]]; then
|
||||
reload-project
|
||||
elif [[ $git_status == 0 && $grep_status != 0 ]]; then
|
||||
log "Nothing to do. '$output'"
|
||||
else
|
||||
log "*** WARNING: Unknown Situation ***"
|
||||
fi
|
||||
|
||||
## Success! ##
|
||||
|
||||
exit 0
|
Reference in New Issue
Block a user