summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow (mars.fritz.box) <paul@buetow.org>2013-12-22 17:03:14 +0100
committerPaul Buetow (mars.fritz.box) <paul@buetow.org>2013-12-22 17:03:14 +0100
commit3e957609d606d435f70920a0f51650e8015cc11f (patch)
tree95c97a62f7ca112f79b8dea62a11e7417a238147
parent73c5f00efba75a67c0bbc001bfb09cea103d25f0 (diff)
add option to include a full tarball of the original pictures to the dist
-rw-r--r--Makefile7
-rw-r--r--photoalbum.conf7
-rwxr-xr-xphotoalbum.sh82
-rw-r--r--templates/footer.tmpl9
4 files changed, 60 insertions, 45 deletions
diff --git a/Makefile b/Makefile
index 4d283df..312bff1 100644
--- a/Makefile
+++ b/Makefile
@@ -2,9 +2,4 @@ all: generate dist
generate:
./photoalbum.sh
clean:
- rm -Rf dist photos
-dist:
- rm -Rf dist 2>/dev/null
- mkdir dist
- mv thumbs html photos dist
- mv index.html ./dist
+ sh -c 'rm -Rf dist *.tar; exit 0'
diff --git a/photoalbum.conf b/photoalbum.conf
index defd59e..64012f0 100644
--- a/photoalbum.conf
+++ b/photoalbum.conf
@@ -8,3 +8,10 @@ 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
index e579bdc..2fc9997 100755
--- a/photoalbum.sh
+++ b/photoalbum.sh
@@ -5,65 +5,61 @@
source photoalbum.conf
-function createdirs () {
- for dir in photos thumbs html; do
- [ -d ${dir} ] || mkdir -vp ${dir}
- done
-}
-
function template () {
local -r template=${1} ; shift
local -r html=${1} ; shift
local destdir=${1} ; shift
if [ -z "${destdir}" ]; then
- destdir=html/
+ destdir=./dist/html/
fi
if [ -d ./templates/ ]; then
- source ./templates/${template}.tmpl >> ./${destdir}/${html}.html
+ source ./templates/${template}.tmpl >> ${destdir}/${html}.html
else
- source ../templates/${template}.tmpl >> ../${destdir}/${html}.html
+ source ../../templates/${template}.tmpl >> ../../${destdir}/${html}.html
fi
}
-function scale () {
- cd ${INCOMING} && find ./ -type f | sort | while read photo; do
- if [ ! -f "../photos/${photo}" ]; then
+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 __
- if [[ "${photo}" =~ / ]]; then
- destphoto="${photo//\//__}"
- else
- destphoto="${photo}"
- fi
+ destphoto="${photo//\//__}"
- destphoto="${destphoto//./}"
+ if [ ! -f "../dist/photos/${destphoto}" ]; then
+ echo "Scaling ${photo} to ../dist/photos/${destphoto}"
- echo "Scaling ${photo} to ../photos/${destphoto}"
-
- convert -auto-orient \
- -geometry ${GEOMETRY} "${photo}" "../photos/${destphoto}"
- fi
+ convert -auto-orient \
+ -geometry ${GEOMETRY} "${photo}" "../dist/photos/${destphoto}"
+ fi
done
+ cd - &>/dev/null
echo 'Removing spaces from file names'
- find ../photos -type f -name '* *' | while read file; do
+ find ./dist/photos -type f -name '* *' | while read file; do
rename 's/ /_/g' "${file}"
done
-
- cd ..
}
function generate () {
- local num=${1} ; shift
+ local num=1
local name=page-${num}
local -i i=0
template header ${name}
template header-first-add ${name}
- cd photos && find ./ -type f | sort | sed 's;^\./;;' |
+ cd ./dist/photos || exit 1
+
+ find ./ -type f | sort | sed 's#^\./##' |
while read photo; do
: $(( i++ ))
@@ -96,17 +92,15 @@ function generate () {
fi
done
- cd ..
- template footer $(cd html;ls -t page-*.html | head -n 1 | sed 's/.html//')
+ cd - &>/dev/null
- ls html/*.html | grep -v page- | cut -d'-' -f1 | uniq |
- while read prefix; do
+ template footer $(cd ./dist/html;ls -t page-*.html | head -n 1 | sed 's/.html//')
- declare page=$(ls -t ${prefix}-*.html |
- head -n 1 | sed 's#html/\(.*\)-.*.html#\1#')
+ ls ./dist/html/*.html | grep -v page- | cut -d'-' -f1 | uniq |
+ while read prefix; do
- declare lastview=$(ls -t ${prefix}-*.html |
- head -n 1 | sed 's/.*-\(.*\).html/\1/')
+ 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))
@@ -129,6 +123,16 @@ function generate () {
createdirs
scale
-find ./html -type f -name \*.html -delete
-generate 1
-template index index .
+find ./dist/html -type f -name \*.html -delete
+template index index ./dist
+generate
+
+if [ "${INCLUDETARBALL}" = 'yes' ]; then
+ echo Creating tarball
+ mv "${INCOMING}" "${TARBALLNAME}"
+ tar $TAROPTS -f "./dist/${TARBALLNAME}${TARBALLSUFFIX}" "${TARBALLNAME}"
+ mv "${TARBALLNAME}" "${INCOMING}"
+else
+ # Cleanup tarball from prev run if any
+ find ./dist/ -maxdepth 1 -type f -name \*.tar -delete
+fi
diff --git a/templates/footer.tmpl b/templates/footer.tmpl
index f917970..fa9f675 100644
--- a/templates/footer.tmpl
+++ b/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>