#!/bin/sh
#
# THE BEER-WARE LICENSE 2012
# <as@paefchen.net> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return Aron Schlesinger
#
# $Paefchen: scripts/pgallery/src/pgalleryindex.sh,v 1.3 2012/09/11 16:47:16 as Exp $
#
. /usr/local/libexec/libpgallery
ARG_TITLE="PGallery"
ARG_TNSIZE="180"
ARG_BIGSIZE="950"
ARG_INDEX="index.html"
ARG_DIR="."
ARG_COPYRIGHT="© $(date +%Y)"
#
# usage()
#
usage()
{
cat <<USAGE
usage $0: ( [-d <dir>] [-n <name>] [-i <index>] [-C <copyright>] [-I <config>]
| -h | -v
Options:
-d dir gallery dir (default: $ARG_DIR)
-h this page
-i name index file name (default: $ARG_INDEX)
-n name page title (default: $ARG_TITLE)
-v print version
-C copyright copyright (html) string (default: $ARG_COPYRIGHT)
-I config info text file for pgallery. info file paras prefered.
the syntax of the file is MAKE(1)
supported variable: TITLE COPYRIGHT INDEX
USAGE
exit
}
# parse args
while [ "$1" != "" ]
do
arg=$1
shift
case $arg in
-h)
usage;;
-n)
ARG_TITLE=$1
shift;;
-d)
ARG_DIR=$1
shift;;
-C)
ARG_COPYRIGHT=$1
shift;;
-I)
ARG_INFOFILE=$1
shift;;
-v)
echo $VERSION
exit;;
*)
echo "unknown argument $arg"
exit
esac
done
# go to gallery directory
MY=$(get_my_path)
cd "$ARG_DIR" || exit 1
# parese info file
if [ "$ARG_INFOFILE" != "" ]
then
test -f $ARG_INFOFILE || err "info file not found \`\`$ARG_INFOFILE''"
for n in TITLE INDEX COPYRIGHT
do
v=$(make -f $ARG_INFOFILE -V$n)
test "$v" = "" && continue
eval "ARG_$n='$v'"
done
fi
# paras from iso to utf-8
for n in $(set | awk -F= '{print $1}')
do
echo "$n" | grep -q '^ARG_' || continue
eval "$n=\"\$(echo \"\$$n\" | iconv -f ISO-8859-1 -t UTF-8)\""
done
title="$ARG_TITLE"
cr="$ARG_COPYRIGHT"
DIRS=
for dir in $(find . -type d -maxdepth 1 -mindepth 1)
do
test -f "$dir/$ARGFILE" || continue
. "$dir/$ARGFILE"
test "$ARG_INDEXIMG" = "" && continue
DIRS="$DIRS $dir"
done
test "$DIRS" = "" && err "no pgallery found"
DIRS=$(
(
for dir in $DIRS
do
. "$dir/$ARGFILE"
echo "$(get_exif_ts ${dir}/${ARG_INDEXIMG}) $dir"
done
) | sort -nr | awk '{print $2}'
)
# create index
ARG_TITLE="$title"
ARG_COPYRIGHT="$cr"
(
html_header
for dir in $DIRS
do
test -f "$dir/$ARGFILE" || continue
. "$dir/$ARGFILE"
test "$ARG_INDEXIMG" = "" && continue
tn="$dir/${ARG_INDEXIMG}.tn.jpg"
imglink="${dir}/${ARG_INDEX}"
html_tn $tn $imglink "$ARG_TITLE"
done
echo "<div class='clear'></div>"
echo "<div class='c'>$ARG_COPYRIGHT</div>"
html_footer
) > $ARG_INDEX