Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 61 lines (51 sloc) 1.854 kb
#!/usr/bin/env bash
#
# live example of imagedex.py and prep_images scripts used with inotify tools.
#
watch="${1:-/srv/http/subs/content/www/drawings}"
PID_LOG="${2:-/srv/http/subs/content/inc/api_drawings.pid}"
#check if thisscript is up and running
if [[ $1 = -c ]];then
[[ -n "$(< "$PID_LOG")" && -d /proc/$(< "$PID_LOG") ]]
exit $?
elif [[ -n "$(< "$PID_LOG")" ]];then
echo 'Error: PID file found not empty, script is running sowewhere else with PID, "%d".' \
"$(< "$PID_LOG")" >&2
exit 3
fi
#sanity check
[[ -r "$watch" && -d "$watch" ]] || {
echo 'Error: Must pass a valid directory to be watched by inotify utilities.' >&2
exit 1
}
touch "$PID_LOG"
[[ $? == 0 && -w "$PID_LOG" && -f "$PID_LOG" ]] || {
printf 'Error: Cannot write to "%s", make sure its a regular, writeable file.'
\ "$PID_LOG" >&2
exit 2
}
echo -n "$$" > "$PID_LOG"
die() {
printf 'Emptying PID file, "%s".\n' "$PID_LOG"
echo -n '' > "$PID_LOG"
}
#more sanity checking
trap die $E_DIRTY SIGINT
if type inotifywait >& /dev/null && type imagedex >& /dev/null;then
#actual juice of watching...
echo ":: [$(date --rfc-3339=seconds)] Watching for changes under '$watch' ..."
while inotifywait --excludei='*.json' --excludei='.*.swp' -r -e modify "$watch"; do
echo ":: [$(date --rfc-3339=seconds)] ... re-building index of files."
imagedex -j drawings -p '/drawings/' -r \
-f /srv/http/subs/content/www/drawings/imagedex.json \
/srv/http/subs/content/www/drawings
echo ":: [$(date --rfc-3339=seconds)] ... re-building conversions and thumbnails of drawings"
/srv/http/subs/content/inc/prep_images > /srv/http/subs/content/inc/prep_images.log
done
else
echo "
Error: '$(basename $0)', is a simple wrapper around inotifywait,
prep_images, and imagedex and cannot run without them \$PATH.
" >&2
exit 2
fi
Jump to Line
Something went wrong with that request. Please try again.