summaryrefslogtreecommitdiff
path: root/localwebgallerydaemon
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2008-03-18 23:22:03 +0000
committerJonas Smedegaard <dr@jones.dk>2008-03-18 23:22:03 +0000
commitc6b4e3861c78860af6e1110a2ed5566f23c78e5e (patch)
tree0e9642adb9a7ea893323eac71094b529968d013e /localwebgallerydaemon
parent5a5d5b3a0506d895566c43a6ad31c9f553c3862d (diff)
New script to autonomously keep web gallery uptodate.
Diffstat (limited to 'localwebgallerydaemon')
-rwxr-xr-xlocalwebgallerydaemon112
1 files changed, 112 insertions, 0 deletions
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 <dr@jones.dk>
+#
+# $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 <<EOF
+Usage: $PRG [ SOURCEDIR ] [ TARGETDIR ]
+
+Defaults:
+ SOURCEDIR: $SOURCEDIR
+ TARGETDIR: $TARGETDIR
+
+Examples:
+ $PRG ~/my/images /var/www/gallery &
+ daemon -u me -n gallery-me -- $PRG ~/my/images /var/www/gallery
+EOF
+}
+
+exit1() {
+ echo >&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