summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--photoalbum.conf17
-rwxr-xr-xphotoalbum.sh143
-rw-r--r--share/templates/footer.tmpl9
4 files changed, 173 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index e89e992..eb8fba6 100644
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,7 @@ deinstall:
test ! -z "$(DESTDIR)" && test -d $(DESTDIR)/usr/share/$(NAME) && rm -r $(DESTDIR)/usr/share/$(NAME) || exit 0
test ! -z "$(DESTDIR)" && test -f $(DESTDIR)/etc/default/photoalbum && rm $(DESTDIR)/etc/default/photoalbum || exit 0
clean:
+<<<<<<< HEAD
test -d ./bin && rm -Rf ./bin || exit 0
test -d ./debian/photoalbum && rm -Rf ./debian/photoalbum || exit 0
version:
@@ -42,3 +43,6 @@ clean-top:
rm ../$(NAME)_*.changes
rm ../$(NAME)_*.deb
+=======
+ sh -c 'rm -Rf dist *.tar; exit 0'
+>>>>>>> 14250af451c56b00f9e94d7b27dc24465d954a81
diff --git a/photoalbum.conf b/photoalbum.conf
new file mode 100644
index 0000000..64012f0
--- /dev/null
+++ b/photoalbum.conf
@@ -0,0 +1,17 @@
+#set -e
+#set -x
+
+declare -i THUMBGEOMETRY=250
+declare -i GEOMETRY=800
+declare -i MAXPREVIEWS=100
+
+declare -r TITLE='A simple Photoalbum'
+declare -r INCOMING=./incoming
+
+# Includes a .tar of the incoming dir in the dist, can be yes or no
+declare -r INCLUDETARBALL=yes
+
+# If INCLUDETARBALL=yes, set the Name of the tarball
+declare -r TARBALLNAME=all-$(date +'%Y-%m-%d-%H%M%S')
+declare -r TARBALLSUFFIX=.tar
+declare -r TAROPTS='-c'
diff --git a/photoalbum.sh b/photoalbum.sh
new file mode 100755
index 0000000..57d953e
--- /dev/null
+++ b/photoalbum.sh
@@ -0,0 +1,143 @@
+#!/bin/bash
+
+# Small quick n dirty photo album script
+# 2011, 2012, 2013 Paul Buetow
+
+source photoalbum.conf
+
+function template () {
+ local -r template=${1} ; shift
+ local -r html=${1} ; shift
+ local destdir=${1} ; shift
+
+ if [ -z "${destdir}" ]; then
+ destdir=./dist/html/
+ fi
+
+ if [ -d ./templates/ ]; then
+ source ./templates/${template}.tmpl >> ${destdir}/${html}.html
+ else
+ source ../../templates/${template}.tmpl >> ../../${destdir}/${html}.html
+ fi
+}
+
+function createdirs () {
+ for dir in ./dist/{photos,thumbs,html}; do
+ [ -d ${dir} ] || mkdir -vp ${dir}
+ done
+}
+
+function scale () {
+ cd "${INCOMING}" || exit 1
+ find . -type f | sed 's#^\./##' |
+ while read photo; do
+ # Flatten directories / to __
+ destphoto="${photo//\//__}"
+
+ if [ ! -f "../dist/photos/${destphoto}" ]; then
+ echo "Scaling ${photo} to ../dist/photos/${destphoto}"
+
+ convert -auto-orient \
+ -geometry ${GEOMETRY} "${photo}" "../dist/photos/${destphoto}"
+ fi
+ done
+ cd - &>/dev/null
+
+ echo 'Removing spaces from file names'
+ find ./dist/photos -type f -name '* *' |
+ while read file; do
+ rename 's/ /_/g' "${file}"
+ done
+}
+
+function generate () {
+ local num=1
+ local name=page-${num}
+ local -i i=0
+
+ template header ${name}
+ template header-first-add ${name}
+
+ cd ./dist/photos || exit 1
+
+ find ./ -type f | sort | sed 's#^\./##' |
+ while read photo; do
+ : $(( i++ ))
+
+ if [ ${i} -gt ${MAXPREVIEWS} ]; then
+ i=1
+ : $(( num++ ))
+
+ next=page-${num}
+ template next ${name}
+ template footer ${name}
+
+ prev=${name}
+ name=${next}
+ template header ${name}
+ template prev ${name}
+ fi
+
+ # Preview page
+ template preview ${name}
+
+ # View page
+ template header ${num}-${i}
+ template view ${num}-${i}
+ template footer ${num}-${i}
+
+ if [ ! -f "../thumbs/${photo}" ]; then
+ echo "Creating thumb for ${photo}";
+ convert -geometry x${THUMBGEOMETRY} "${photo}" \
+ "../thumbs/${photo}"
+ fi
+ done
+
+ cd - &>/dev/null
+
+ template footer $(cd ./dist/html;ls -t page-*.html | head -n 1 | sed 's/.html//')
+
+ # Generate HTTP redirect pages
+ ls ./dist/html/*.html | grep -v page- | cut -d'-' -f1 | uniq |
+ while read prefix; do
+ declare page=$(ls -t ${prefix}-*.html | head -n 1 | sed 's#./dist/html/\(.*\)-.*.html#\1#')
+ declare lastview=$(ls -t ${prefix}-*.html | head -n 1 | sed 's/.*-\(.*\).html/\1/')
+
+ declare prevredirect=${page}-0
+ declare nextredirect=${page}-$((lastview+1))
+
+ redirectpage=$(( page-1 ))-${MAXPREVIEWS}
+ template redirect ${prevredirect}
+
+ if [ ${lastview} -eq ${MAXPREVIEWS} ]; then
+ redirectpage=$(( page+1 ))-1
+ else
+ redirectpage=${page}-${lastview}
+ template redirect 0-${MAXPREVIEWS}
+
+ redirectpage=1-1
+ fi
+
+ template redirect ${nextredirect}
+ done
+}
+
+function tarball () {
+ # Cleanup tarball from prev run if any
+ find ./dist/ -maxdepth 1 -type f -name \*.tar -delete
+
+ if [ "${INCLUDETARBALL}" = 'yes' ]; then
+ echo Creating tarball
+ mv "${INCOMING}" "${TARBALLNAME}"
+ tar $TAROPTS -f "./dist/${TARBALLNAME}${TARBALLSUFFIX}" "${TARBALLNAME}"
+ mv "${TARBALLNAME}" "${INCOMING}"
+ fi
+}
+
+createdirs
+scale
+find ./dist/ -type f -name \*.html -delete
+template index index ./dist
+generate
+tarball
+
diff --git a/share/templates/footer.tmpl b/share/templates/footer.tmpl
index f917970..fa9f675 100644
--- a/share/templates/footer.tmpl
+++ b/share/templates/footer.tmpl
@@ -1,6 +1,15 @@
cat <<END
</p>
<hr />
+END
+
+if [ "${INCLUDETARBALL}" = 'yes' ]; then
+cat <<END
+Download all photos in original size <a href='../${TARBALLNAME}${TARBALLSUFFIX}'>here</a><br /><br />
+END
+fi
+
+cat <<END
Page generated at $(date) using Bash, ImageMagick and Git at $(uname); &lt;photoalbum@mx.buetow.org&gt;
</body>
</html>