2020-08-09 14:53:51 -07:00
|
|
|
#!/bin/bash
|
|
|
|
DEBOUNCE=1.0
|
2020-12-13 17:16:53 -08:00
|
|
|
[[ ! $GITEA_DIR ]] && export GITEA_DIR=$(dirname $(cd $(dirname $(readlink -f $BASH_SOURCE));pwd -P))
|
|
|
|
|
|
|
|
fext=ini
|
|
|
|
declare OPTARG
|
|
|
|
declare OPTION
|
|
|
|
declare OPTIND=0
|
|
|
|
|
|
|
|
Saved=("$*")
|
|
|
|
|
|
|
|
while getopts 'fg:itud:' OPTION; do
|
|
|
|
case "$OPTION" in
|
|
|
|
t) fext=tmpl ;;
|
|
|
|
*) ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
shift $(( $OPTIND - 1 ))
|
|
|
|
|
|
|
|
echo stopping any systemd process
|
|
|
|
$GITEA_DIR/scripts/systemd/stop $1
|
|
|
|
# $GITEA_DIR/scripts/start $Saved
|
|
|
|
# LOGFILE="$GITEA_DIR/watch.log"
|
|
|
|
COMMAND="$GITEA_DIR/scripts/restart $Saved"
|
|
|
|
$COMMAND
|
|
|
|
echo "watching: $GITEA_DIR/frontend/ $GITEA_DIR/config/$1.$fext, running: $COMMAND"
|
|
|
|
# export WATCH_DIR="$GITEA_DIR/frontend/"
|
2020-12-11 22:55:28 -08:00
|
|
|
# export WATCH_VERBOSE=1
|
2020-12-13 17:16:53 -08:00
|
|
|
inotifywait -mqr -e MODIFY $GITEA_DIR/frontend/ $GITEA_DIR/config/$1.$fext |
|
2020-08-09 14:53:51 -07:00
|
|
|
while read ; do
|
|
|
|
# debounce extra events
|
|
|
|
currentTime=$(date +'%H%M%S.%N')
|
|
|
|
delta=$(bc <<< "$lastRunTime - $currentTime")
|
|
|
|
# echo "$currentTime, $lastRunTime, $delta"
|
|
|
|
if (( $(echo "$delta < -$DEBOUNCE" | bc -l) )); then
|
2020-12-13 17:16:53 -08:00
|
|
|
echo File Changes Detected - restarting
|
|
|
|
# echo $COMMAND
|
2020-08-09 14:53:51 -07:00
|
|
|
$COMMAND
|
|
|
|
lastRunTime=$(date +'%H%M%S.%N')
|
2020-12-13 17:16:53 -08:00
|
|
|
echo "!Restarted - Refresh The Browser To See Changes"
|
2020-08-09 14:53:51 -07:00
|
|
|
fi
|
|
|
|
done
|