File:  [Paefchen] / scripts / pgallery / src / pgalleryindex.sh
Revision 1.6: download - view: text, annotated - select for diffs - revision graph
Thu Dec 7 14:24:00 2017 UTC (6 years, 11 months ago) by as
Branches: MAIN
CVS tags: HEAD
ignore galleries

#!/usr/local/libexec/pgallerysh
#
# THE BEER-WARE LICENSE 2012,13

# <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.6 2017/12/07 14:24:00 as Exp $
#

. /usr/local/libexec/libpgallery

ARG_TITLE="PGallery"
ARG_TNSIZE="180"
ARG_BIGSIZE="950"
ARG_INDEX="index.html"
ARG_DIR="."
ARG_COPYRIGHT="&copy; $(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\" | $BIN_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
		ARG_INDEXIMG=
		ARG_NOINDEX=
		. "$dir/$ARGFILE"
		test "$ARG_INDEXIMG" = "" && continue
		test "$ARG_NOINDEX" != "" && 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