gitea/scripts/watch

21 lines
722 B
Bash
Executable File

#!/bin/bash
DEBOUNCE=1.0
[[ ! $GITEA_DIR ]] && export GITEA_DIR="$(dirname "$(cd "$(readlink -f "$BASH_SOURCE")"; pwd -P)")"
# export WATCH_DIR="$DIR/frontend/"
# export WATCH_VERBOSE=1
COMMAND=$GITEA_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