gitea/scripts/watch

21 lines
691 B
Plaintext
Raw Normal View History

#!/bin/bash
DEBOUNCE=1.0
DIR="$(dirname "$(cd "$(dirname "$(readlink -f "$0")")";pwd -P)")" || exit
# export WATCH_DIR="$DIR/frontend/"
# export WATCH_VERBOSE=1
COMMAND=$DIR/scripts/restart "$@"
# LOGFILE="$DIR/watch.log"
echo "watching $DIR/frontend/ $DIR/config/$1.ini with $COMMAND"
inotifywait -mqr -e MODIFY $DIR/frontend/ $DIR/config/$1.ini |
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 $COMMAND
$COMMAND
lastRunTime=$(date +'%H%M%S.%N')
fi
done