Skip to content

Instantly share code, notes, and snippets.

@rkfg
Last active August 29, 2015 14:06
Show Gist options
  • Save rkfg/bb1f6d229e3eeae7a402 to your computer and use it in GitHub Desktop.
Save rkfg/bb1f6d229e3eeae7a402 to your computer and use it in GitHub Desktop.
#!/bin/bash
APIKEY=
ADDRESS=127.0.0.1:8080
WATCHDIRS=()
WATCHREPOS=()
TIMEOUTCHANGE=5
function watchdir {
local CHANGED
local EVENTS
while true
do
if [[ -n "$CHANGED" ]]
then
TIMEOUT=$TIMEOUTCHANGE
fi
if [[ -n "$CHANGED" && -z "$EVENTS" ]]
then
echo "Updating $2" >&2
wget --post-data="" --header="X-API-Key:$APIKEY" -qO- http://$ADDRESS/rest/scan?repo=$2
CHANGED=
TIMEOUT=
fi
if [ -n "$TIMEOUT" ]
then
EVENTS=$(inotifywait -r -e modify,delete,create,move -t $TIMEOUT "$1")
else
EVENTS=$(inotifywait -r -e modify,delete,create,move "$1")
fi
if [[ -n "$EVENTS" ]]
then
echo "Changed: $EVENTS" >&2
CHANGED=1
fi
done
}
if [ -z "$(which inotifywait)" ]
then
echo "Please install inotify-tools."
exit 1
fi
cd "$(dirname "$0")"
if [ -f stwatch.conf ]
then
. stwatch.conf
fi
for i in $(seq ${#WATCHDIRS[@]})
do
d=$(readlink -f "${WATCHDIRS[$i-1]}")
repo=${WATCHREPOS[$i-1]}
watchdir "$d" "$repo" &
done
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment