gitea/scripts/watch

44 lines
1.2 KiB
Plaintext
Raw Permalink Normal View History

#!/bin/bash
DEBOUNCE=1.0
[[ ! $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/"
# export WATCH_VERBOSE=1
inotifywait -mqr -e MODIFY $GITEA_DIR/frontend/ $GITEA_DIR/config/$1.$fext |
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
echo File Changes Detected - restarting
# echo $COMMAND
$COMMAND
lastRunTime=$(date +'%H%M%S.%N')
echo "!Restarted - Refresh The Browser To See Changes"
fi
done