# HG changeset patch # User meillo@marmaro.de # Date 1195854221 -3600 # Node ID cb0dff8c48c6e354b27a5ea767960a85aec972f4 # Parent a963f51cfd801a7d1e2e334af4396c6a027a87e2 added option --overwrite; refactored checkCreateDir; fixed HTML output; introduced exit code 3 and 4; better help output diff -r a963f51cfd80 -r cb0dff8c48c6 genwebgallery --- a/genwebgallery Fri Nov 23 20:52:47 2007 +0100 +++ b/genwebgallery Fri Nov 23 22:43:41 2007 +0100 @@ -1,97 +1,144 @@ #!/bin/sh # -# generates a web gallery of static web pages +# generates a web gallery # requires: ImageMagick (convert) # # meillo@marmaro.de # -VERSION=0.3 +VERSION=0.4 -targetDir="web" -index="index.htm" -sizePic=640 -sizeThumb=200 -galleryTitle="gallery title" -copyright="please mind the copyright" +verbose="no" +targetDir="webgallery" +overwrite="no" +index="index.html" +sizePic=800 +sizeThumb=150 +galleryTitle="photo gallery" +copyright="" -verbose="" + function checkCreateDir() { - if [ -d "$targetDir" ] ; then - echo "Target dir '$targetDir' already exists." - echo -n "remove it? [y/n] " + remove="no" + if [ -e "$targetDir" ] ; then + if [ "$overwrite" = "no" ] ; then + echo "output directory '$targetDir' already exists." + echo -n "remove it? [y/n] " + read remove + fi - read remove - if [ $remove = "y" ] ; then + if [ "$remove" = "y" -o "$overwrite" = "yes" ] ; then + echo "removing '$targetDir' ..." rm -r "$targetDir" - echo "removing '$targetDir' ..." + if [ $? -ne 0 ] ; then + echo "ABORT" + exit 4 + fi else - exit 1 + echo "keep output directory" + echo "ABORT" + exit 3 fi fi + mkdir -p "$targetDir" } + function insertHeader() { - echo < - - + echo " + + + $titleName - - + + -EOF +" } + function insertFooter() { - echo < -EOF +" } + function log() { - if [ $verbose ] ; then + if [ $verbose = "yes" ] ; then echo "$1"; fi } + function checkConvert() { log "checking convert installation" (convert -version) 2> /dev/null > /dev/null if [ $? -ne 0 ] ; then - echo "Error: Can not find 'convert' (package imagemagick)" - echo "ABORT!" + echo "Can not find 'convert' (package imagemagick)" + echo "ABORT" exit 2 fi + log "convert found:" log "`convert -version`" } -#### +function usage() { + echo "usage: `basename $0` [OPTIONS] FILES" + exit 1 +} -if [ $# -eq 0 ] ; then - echo "usage: `basename $0` [OPTIONS] FILES" + +function help() { + echo "`basename $0` + +generates a web gallery consisting of html pages + +usage: `basename $0` [OPTIONS] PICTURES + +options: + --version print program version + --help display this output + -v be verbose ($verbose) + -o DIR folder where generated files go to ($targetDir) + -i FILE the name of the index file ($index) + -t TEXT title of the gallery ($galleryTitle) + -c TEXT a copyright notice ($copyright) + -ps PIXELS size of the pics ($sizePic) + -ts PIXELS size of the thumbnails ($sizeThumb) + --overwrite overwrite output directory ($overwrite) + +for more information see man page: genwebgallery(1) + +author: meillo@marmaro.de +homepage: http://prog.marmaro.de +" exit 0 -fi +} + + +# option processing + while [ "$#" -ge 1 -a "${1:0:1}" = '-' ] ; do case $1 in '--version') @@ -99,34 +146,14 @@ exit 0 ;; '--help') - echo "`basename $0` - -generates a web gallery consisting of html pages - -usage: `basename $0` [OPTIONS] FILES - -options: - --version: echo program version - --help: display this output - -v: be verbose - -o DIR: all generated content is copied to this folder - -i FILE: the name of the index file (index.htm) - -t TITLE: title of the gallery - -c COPYRIGHT: a copyright notice - -ps PIXELS: size of the pics - -ts PIXELS: size of the thumbnails - -author: meillo@marmaro.de -homepage: http://prog.marmaro.de -" - exit 0 + help ;; '-v' | '--verbose') - verbose=1 + verbose="yes" shift ;; '-o' | '--output') - targetDir=$2 + targetDir="$2" shift shift ;; @@ -136,7 +163,7 @@ shift ;; '-t' | '--title') - galleryTitle=$2 + galleryTitle="$2" shift shift ;; @@ -155,6 +182,10 @@ shift shift ;; + '--overwrite') + overwrite="yes" + shift + ;; *) echo "invalid option: $1" echo "see: `basename $0` --help" @@ -164,39 +195,51 @@ done if [ $# -eq 0 ] ; then - echo "usage: `basename $0` [OPTIONS] FILES" - exit 0 + usage fi + # verbose output -log "verbose on" -log "output dir is: $targetDir" -log "index file is: $index" -log "gallery title is: $galleryTitle" -log "copyright notice is: $copyright" -log "picture size is: $sizePic" -log "thumbnail size is: $sizeThumb" +log "verbose: $verbose" +log +log "output dir: $targetDir" +log "index file: $index" +log "gallery title: $galleryTitle" +log "copyright notice: $copyright" +log "picture size: ${sizePic}px" +log "thumbnail size: ${sizeThumb}px" +log "overwrite output dir: $overwrite" +log checkConvert -log "" +log + +# generate web gallery + checkCreateDir -insertHeader > "$targetDir/$index" -echo "

$galleryTitle

" >> "$targetDir/$index" +echo `insertHeader` > "$targetDir/$index" +if [ "$galleryTitle" != "" ] ; then + echo "

$galleryTitle

" >> "$targetDir/$index" +fi for i in "$@" ; do - file=`basename $i` + file="`basename $i`" targetFile="$targetDir/$file.htm" log "processing file: $file" # generate pic page - insertHeader > "$targetFile" - echo "

$galleryTitle

" \ - "

\"$file\"

" \ - "

$copyright

" >> "$targetFile" - insertFooter >> "$targetFile" + echo `insertHeader` > "$targetFile" + if [ "$galleryTitle" != "" ] ; then + echo "

$galleryTitle

" >> "$targetFile" + fi + echo "

\"$file\"

" >> "$targetFile" + if [ "$copyright" != "" ] ; then + echo "

$copyright

" >> "$targetFile" + fi + echo `insertFooter` >> "$targetFile" # copy and resize pics convert "$i" -resize ${sizePic}x${sizePic} "$targetDir/$file" @@ -206,5 +249,7 @@ echo " \"$file\"" >> "$targetDir/$index" done -echo "

$copyright

" >> "$targetDir/$index" -insertFooter >> "$targetDir/$index" +if [ "$copyright" != "" ] ; then + echo "

$copyright

" >> "$targetDir/$index" +fi +echo `insertFooter` >> "$targetDir/$index" diff -r a963f51cfd80 -r cb0dff8c48c6 genwebgallery.1 --- a/genwebgallery.1 Fri Nov 23 20:52:47 2007 +0100 +++ b/genwebgallery.1 Fri Nov 23 22:43:41 2007 +0100 @@ -4,20 +4,19 @@ genwebgallery .SH SYNOPSIS -.B genwebgallery [OPTIONS] FILES +.B genwebgallery [OPTIONS] PICTURES .SH DESCRIPTION .B genwebgallery -generates a web gallery of mentioned pictures. +Generates a web gallery of mentioned pictures. Only very minimalistic static HTML pages are generated. Copies of the pictures get resized to the defined sizes. .PP -Only static HTML pages are generated. +All generated content goes in a subdirectory which defaults to 'webgallery'. Or any other directory specified by --output. .PP The .BR convert tool from ImageMagick is required. .SH OPTIONS -.B genwebgallery .TP .B \-\-help Show summary of options. @@ -45,6 +44,14 @@ .TP .B \-ts, \-\-thumb-size Specify size of thumbnails +.TP +.B \-\-overwrite +Overwrites the output directory if it exists without asking. +Without this option, the users is interactively asked what to do. +.PP +See +.B genwebgallery --help +for default values. .SH EXIT CODE .TP @@ -56,12 +63,18 @@ .B convert could not be found. It's probably not installed. Normally it is provided by the ImageMagick tool collection. +.TP +.B 3 +The output directory already exists and the user wanted to keep it. +.TP +.B 4 +The output directory already exists and the user wanted it to be deleted, but it was not possible. .SH SEE ALSO .BR convert (1), .BR ImageMagick (1). .SH AUTHOR -genwebgallery was written by markus schnalke +genwebgallery and this man page was written by markus schnalke .PP Website: http://prog.marmaro.de