From c6b4e3861c78860af6e1110a2ed5566f23c78e5e Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Tue, 18 Mar 2008 23:22:03 +0000 Subject: New script to autonomously keep web gallery uptodate. --- localwebgallerydaemon | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100755 localwebgallerydaemon (limited to 'localwebgallerydaemon') diff --git a/localwebgallerydaemon b/localwebgallerydaemon new file mode 100755 index 0000000..f0bc0d1 --- /dev/null +++ b/localwebgallerydaemon @@ -0,0 +1,112 @@ +#!/bin/sh +# +# /usr/local/bin/localwebgalleryupdate +# Copyright 2008 Jonas Smedegaard +# +# $Id: localwebgallerydaemon,v 1.1 2008-03-18 23:22:03 jonas Exp $ +# +# (Re)generate web gallery whenever source directory changes +# +# TODO: Implement options: +# --help +# --sourcedir +# --targetdir +# --run-once +# --now +# --verbose +# --debug +# --init (create targetdir if missing, fail if exists and non-empty) +# +# TODO: implement ask() and the following options: +# --reset (purge output dir -- use with --init to always build from scratch) +# --force +# +# TODO: Support more gallery engines +# +# TODO: Support overriding defaults in rc-file +# + +set -e +#set -bm + +# Defaults options +SOURCEDIR="$HOME/public_media" +TARGETDIR="$HOME/public_html/gallery" +GENERATOR="lazygal" +THEME="image-index" + +# Use defaults if not overridden +sourcedir="${1:-$SOURCEDIR}" +targetdir="${2:-$TARGETDIR}" + +PRG=$(basename "$0") + +# Required external programs +EXTPRG="/usr/bin/fileschanged" +case $GENERATOR in + lazygal) + EXTPRG="$EXTPRG /usr/bin/$GENERATOR" + ;; +esac + +showhelp() { + cat <&2 "Error: $1" + echo >&2 "Exiting..." + exit 1 +} + +lazygal_opts="--quiet --check-all-dirs --clean-destination ${THEME:+--theme $THEME}" + +# Sanity checks +[ -d "$sourcedir" ] || exit1 "Source directory \"$sourcedir\" is not a directory" +[ -d "$targetdir" ] || exit1 "Target directory \"$targetdir\" is not a directory" +for prg in $EXTPRG; do + [ -x "$prg" ] || exit1 "Required program \"$prg\" not installed" +done + +updategallery() { + onemoretime=yes + trap 'onemoretime=yes' USR1 + while [ -n "$onemoretime" ]; do + onemoretime= + case "$GENERATOR" in + lazygal) + lazygal $lazygal_opts -o "$targetdir" "$sourcedir" + ;; + esac + sleep 10 + done +} + +pid= +fileschanged -r -s created,changed,deleted "$sourcedir" | while read file; do + + # Ignore hidden files (used for temporary files by rsync) + case "$file" in + .*) + continue + ;; + esac + + # Invoke update if not active or telling to take another spin fails + if [ -z "$progress" ] || ! kill -USR1 $(jobs -p) 2>/dev/null; then + progress=yes + updategallery & + fi +done + +exit 0 -- cgit v1.2.3