File:  [Paefchen] / scripts / pgallery / src / pgalleryindex.sh
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Fri Aug 31 12:33:07 2012 UTC (12 years, 2 months ago) by as
Branches: MAIN
CVS tags: HEAD
Mit pgalleryindex lässt sich ein index von allen Gallerien erstellen.

#!/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.1 2012/08/31 12:33:07 as Exp $
#

. $(dirname $0)/libpgallery

ARG_TITLE="PGallery"
#ARG_FILES=
#ARG_FILETYPES="jpg jpeg png gif tif tiff"
ARG_TNSIZE="180"
#ARG_TNQALITY="70"
ARG_BIGSIZE="950"
#ARG_BIGQALITY="90"
ARG_INDEX="index.html"
ARG_DIR="."
#ARG_UPDATE=1
ARG_COPYRIGHT="&copy; $(date +%Y)"
#ARG_INFOFILE=""
#ARG_MAILTO=""
#ARG_MAILFROM="PGallery <${USER}@${HOST}>"
ARG_URL=
#ARG_EXIF="0x920a 0x829d 0x829a ISO 0x8827 / 0x010f - 0x0110"

#MKAKEFILE=".htmakefile"

#
# usage()
#
usage()
{
	cat <<USAGE
usage $0: ( [-f <files>] | [-s <suffix>] ) [-d <dir>] [-n <name>]
                [-t <thumbnail_size>] [-u <thumbnail_quality>]
                [-b <big_size>] [-c <big_quality>] [-l link] [-e <exif>]
                [-i <index>] [-C <copyright>] [-F <mailfrom>] [-T <mailto>]
                [-U] | -h | -v
Options:
  -b size       size from big images in pixel (default: $ARG_BIGSIZE)
  -c quality    quality from big images 0-100% (default: $ARG_BIGQALITY)
  -d dir        gallery dir (default: $ARG_DIR)
  -e exif       list of tags in hex. (default: $ARG_EXIF)
                see: http://www.exiv2.org/tags.html
  -f files      gallery images
  -h            this page
  -i name       index file name (default: $ARG_INDEX)
  -l url        gallery link
  -n name       page title (default: $ARG_TITLE)
  -s suffix     list of suffix. if no \`\`-f'' defined, used to find images
                in \`\`-d'' directoy. case insensitive
                (default: $ARG_FILETYPES)
  -t size       size from thumbnail images in pixel (default: $ARG_TNSIZE)
  -u quality    quality from thumbnail images 0-100% (default: $ARG_BIGQALITY)
  -v            print version
  -C copyright  copyright (html) string (default: $ARG_COPYRIGHT)
  -F from       mail sender (default: $ARG_MAILFROM)
  -I file       info text file for pgallery. info file paras prefered.
                the syntax of the file is MAKE(1)
                supported variable: TITLE COPYRIGHT INDEX FILETYPES TNSIZE URL
                                    TNQALITY BIGSIZE BIGQALITY MAILTO MAILFROM
                                    EXIF
  -T mailto     send update infos to this address. if not set, no mail delivery
  -U            no update, new calculation of all images.
                normally only new and modified images will calculated
USAGE
	exit
}

# parse args
while [ "$1" != "" ]
do
	arg=$1
	shift
	case $arg in
		-h)
			usage;;
		-n)
			ARG_TITLE=$1
			shift;;
#		-t)
#			ARG_TNSIZE=$1
#			shift;;
#		-u)
#			ARG_TNQALITY=$1
#			shift;;
#		-b)
#			ARG_BIGSIZE=$1
#			shift;;
#		-c)
#			ARG_BIGQALITY=$1
#			shift;;
#		-f)
#			ARG_FILES=$1
#			shift;;
		-l)
			ARG_URL=$1
			shift;;
#		-s)
#			ARG_FILETYPES=$1
#			shift;;
		-d)
			ARG_DIR=$1
			shift;;
#		-e)
#			ARG_EXIF=$1
#			shift;;
		-C)
			ARG_COPYRIGHT=$1
			shift;;
#		-F)
#			ARG_MAILFROM=$1
#			shift;;
		-I)
			ARG_INFOFILE=$1
			shift;;
#		-T)
#			ARG_MAILTO=$1
#			shift;;
#		-U)
#			ARG_UPDATE=0;;
		-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 URL 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

# fix url
if [ "$ARG_URL" != "" ]
then
	echo "$ARG_URL" | grep -q '/$' || ARG_URL="${ARG_URL}/"
fi

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