genwebgallery
diff genwebgallery @ 6:cb0dff8c48c6
added option --overwrite; refactored checkCreateDir; fixed HTML output; introduced exit code 3 and 4; better help output
author | meillo@marmaro.de |
---|---|
date | Fri, 23 Nov 2007 22:43:41 +0100 |
parents | abe1e48e0708 |
children | 6273a788c4fd |
line diff
1.1 --- a/genwebgallery Fri Nov 23 20:52:47 2007 +0100 1.2 +++ b/genwebgallery Fri Nov 23 22:43:41 2007 +0100 1.3 @@ -1,97 +1,144 @@ 1.4 #!/bin/sh 1.5 # 1.6 -# generates a web gallery of static web pages 1.7 +# generates a web gallery 1.8 # requires: ImageMagick (convert) 1.9 # 1.10 # meillo@marmaro.de 1.11 # 1.12 1.13 1.14 -VERSION=0.3 1.15 +VERSION=0.4 1.16 1.17 -targetDir="web" 1.18 -index="index.htm" 1.19 -sizePic=640 1.20 -sizeThumb=200 1.21 -galleryTitle="gallery title" 1.22 -copyright="please mind the copyright" 1.23 +verbose="no" 1.24 +targetDir="webgallery" 1.25 +overwrite="no" 1.26 +index="index.html" 1.27 +sizePic=800 1.28 +sizeThumb=150 1.29 +galleryTitle="photo gallery" 1.30 +copyright="" 1.31 1.32 -verbose="" 1.33 + 1.34 1.35 1.36 function checkCreateDir() { 1.37 - if [ -d "$targetDir" ] ; then 1.38 - echo "Target dir '$targetDir' already exists." 1.39 - echo -n "remove it? [y/n] " 1.40 + remove="no" 1.41 + if [ -e "$targetDir" ] ; then 1.42 + if [ "$overwrite" = "no" ] ; then 1.43 + echo "output directory '$targetDir' already exists." 1.44 + echo -n "remove it? [y/n] " 1.45 + read remove 1.46 + fi 1.47 1.48 - read remove 1.49 - if [ $remove = "y" ] ; then 1.50 + if [ "$remove" = "y" -o "$overwrite" = "yes" ] ; then 1.51 + echo "removing '$targetDir' ..." 1.52 rm -r "$targetDir" 1.53 - echo "removing '$targetDir' ..." 1.54 + if [ $? -ne 0 ] ; then 1.55 + echo "ABORT" 1.56 + exit 4 1.57 + fi 1.58 else 1.59 - exit 1 1.60 + echo "keep output directory" 1.61 + echo "ABORT" 1.62 + exit 3 1.63 fi 1.64 fi 1.65 + 1.66 mkdir -p "$targetDir" 1.67 } 1.68 1.69 1.70 1.71 + 1.72 function insertHeader() { 1.73 - echo <<EOF 1.74 -<?xml version="1.0" encoding="utf-8"?> 1.75 -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 1.76 - "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 1.77 -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 1.78 + echo " 1.79 +<?xml version=\"1.0\" encoding=\"utf-8\"?> 1.80 +<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" 1.81 + \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\"> 1.82 +<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\"> 1.83 <head> 1.84 <title>$titleName</title> 1.85 -<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 1.86 - <meta name="Generator" content="genwebgallery - see http://prog.marmaro.de" /> 1.87 +<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> 1.88 + <meta name=\"Generator\" content=\"genwebgallery - http://prog.marmaro.de\" /> 1.89 </head> 1.90 <body> 1.91 1.92 -EOF 1.93 +" 1.94 } 1.95 1.96 1.97 + 1.98 function insertFooter() { 1.99 - echo <<EOF 1.100 + echo " 1.101 1.102 </body> 1.103 </html> 1.104 -EOF 1.105 +" 1.106 } 1.107 1.108 1.109 + 1.110 function log() { 1.111 - if [ $verbose ] ; then 1.112 + if [ $verbose = "yes" ] ; then 1.113 echo "$1"; 1.114 fi 1.115 } 1.116 1.117 1.118 + 1.119 function checkConvert() { 1.120 log "checking convert installation" 1.121 (convert -version) 2> /dev/null > /dev/null 1.122 if [ $? -ne 0 ] ; then 1.123 - echo "Error: Can not find 'convert' (package imagemagick)" 1.124 - echo "ABORT!" 1.125 + echo "Can not find 'convert' (package imagemagick)" 1.126 + echo "ABORT" 1.127 exit 2 1.128 fi 1.129 + log "convert found:" 1.130 log "`convert -version`" 1.131 } 1.132 1.133 1.134 -#### 1.135 1.136 +function usage() { 1.137 + echo "usage: `basename $0` [OPTIONS] FILES" 1.138 + exit 1 1.139 +} 1.140 1.141 1.142 -if [ $# -eq 0 ] ; then 1.143 - echo "usage: `basename $0` [OPTIONS] FILES" 1.144 + 1.145 +function help() { 1.146 + echo "`basename $0` 1.147 + 1.148 +generates a web gallery consisting of html pages 1.149 + 1.150 +usage: `basename $0` [OPTIONS] PICTURES 1.151 + 1.152 +options: 1.153 + --version print program version 1.154 + --help display this output 1.155 + -v be verbose ($verbose) 1.156 + -o DIR folder where generated files go to ($targetDir) 1.157 + -i FILE the name of the index file ($index) 1.158 + -t TEXT title of the gallery ($galleryTitle) 1.159 + -c TEXT a copyright notice ($copyright) 1.160 + -ps PIXELS size of the pics ($sizePic) 1.161 + -ts PIXELS size of the thumbnails ($sizeThumb) 1.162 + --overwrite overwrite output directory ($overwrite) 1.163 + 1.164 +for more information see man page: genwebgallery(1) 1.165 + 1.166 +author: meillo@marmaro.de 1.167 +homepage: http://prog.marmaro.de 1.168 +" 1.169 exit 0 1.170 -fi 1.171 +} 1.172 1.173 1.174 + 1.175 + 1.176 +# option processing 1.177 + 1.178 while [ "$#" -ge 1 -a "${1:0:1}" = '-' ] ; do 1.179 case $1 in 1.180 '--version') 1.181 @@ -99,34 +146,14 @@ 1.182 exit 0 1.183 ;; 1.184 '--help') 1.185 - echo "`basename $0` 1.186 - 1.187 -generates a web gallery consisting of html pages 1.188 - 1.189 -usage: `basename $0` [OPTIONS] FILES 1.190 - 1.191 -options: 1.192 - --version: echo program version 1.193 - --help: display this output 1.194 - -v: be verbose 1.195 - -o DIR: all generated content is copied to this folder 1.196 - -i FILE: the name of the index file (index.htm) 1.197 - -t TITLE: title of the gallery 1.198 - -c COPYRIGHT: a copyright notice 1.199 - -ps PIXELS: size of the pics 1.200 - -ts PIXELS: size of the thumbnails 1.201 - 1.202 -author: meillo@marmaro.de 1.203 -homepage: http://prog.marmaro.de 1.204 -" 1.205 - exit 0 1.206 + help 1.207 ;; 1.208 '-v' | '--verbose') 1.209 - verbose=1 1.210 + verbose="yes" 1.211 shift 1.212 ;; 1.213 '-o' | '--output') 1.214 - targetDir=$2 1.215 + targetDir="$2" 1.216 shift 1.217 shift 1.218 ;; 1.219 @@ -136,7 +163,7 @@ 1.220 shift 1.221 ;; 1.222 '-t' | '--title') 1.223 - galleryTitle=$2 1.224 + galleryTitle="$2" 1.225 shift 1.226 shift 1.227 ;; 1.228 @@ -155,6 +182,10 @@ 1.229 shift 1.230 shift 1.231 ;; 1.232 + '--overwrite') 1.233 + overwrite="yes" 1.234 + shift 1.235 + ;; 1.236 *) 1.237 echo "invalid option: $1" 1.238 echo "see: `basename $0` --help" 1.239 @@ -164,39 +195,51 @@ 1.240 done 1.241 1.242 if [ $# -eq 0 ] ; then 1.243 - echo "usage: `basename $0` [OPTIONS] FILES" 1.244 - exit 0 1.245 + usage 1.246 fi 1.247 1.248 1.249 + 1.250 # verbose output 1.251 -log "verbose on" 1.252 -log "output dir is: $targetDir" 1.253 -log "index file is: $index" 1.254 -log "gallery title is: $galleryTitle" 1.255 -log "copyright notice is: $copyright" 1.256 -log "picture size is: $sizePic" 1.257 -log "thumbnail size is: $sizeThumb" 1.258 +log "verbose: $verbose" 1.259 +log 1.260 +log "output dir: $targetDir" 1.261 +log "index file: $index" 1.262 +log "gallery title: $galleryTitle" 1.263 +log "copyright notice: $copyright" 1.264 +log "picture size: ${sizePic}px" 1.265 +log "thumbnail size: ${sizeThumb}px" 1.266 +log "overwrite output dir: $overwrite" 1.267 +log 1.268 checkConvert 1.269 -log "" 1.270 +log 1.271 1.272 1.273 + 1.274 +# generate web gallery 1.275 + 1.276 checkCreateDir 1.277 1.278 -insertHeader > "$targetDir/$index" 1.279 -echo "<h1>$galleryTitle</h1>" >> "$targetDir/$index" 1.280 +echo `insertHeader` > "$targetDir/$index" 1.281 +if [ "$galleryTitle" != "" ] ; then 1.282 + echo "<h1>$galleryTitle</h1>" >> "$targetDir/$index" 1.283 +fi 1.284 1.285 for i in "$@" ; do 1.286 - file=`basename $i` 1.287 + file="`basename $i`" 1.288 targetFile="$targetDir/$file.htm" 1.289 log "processing file: $file" 1.290 1.291 # generate pic page 1.292 - insertHeader > "$targetFile" 1.293 - echo "<h1>$galleryTitle</h1>" \ 1.294 - "<p><a href=\"$index\"><img src=\"$file\" alt=\"$file\" /></a></p>" \ 1.295 - "<p>$copyright</p>" >> "$targetFile" 1.296 - insertFooter >> "$targetFile" 1.297 + echo `insertHeader` > "$targetFile" 1.298 + if [ "$galleryTitle" != "" ] ; then 1.299 + echo "<h1>$galleryTitle</h1>" >> "$targetFile" 1.300 + fi 1.301 + echo "<p><a href=\"$index\"><img src=\"$file\" alt=\"$file\" /></a></p>" >> "$targetFile" 1.302 + if [ "$copyright" != "" ] ; then 1.303 + echo "<p>$copyright</p>" >> "$targetFile" 1.304 + fi 1.305 + echo `insertFooter` >> "$targetFile" 1.306 1.307 # copy and resize pics 1.308 convert "$i" -resize ${sizePic}x${sizePic} "$targetDir/$file" 1.309 @@ -206,5 +249,7 @@ 1.310 echo " <a href=\"$file.htm\"><img src=\"_$file\" alt=\"$file\" /></a>" >> "$targetDir/$index" 1.311 done 1.312 1.313 -echo "<p>$copyright</p>" >> "$targetDir/$index" 1.314 -insertFooter >> "$targetDir/$index" 1.315 +if [ "$copyright" != "" ] ; then 1.316 + echo "<p>$copyright</p>" >> "$targetDir/$index" 1.317 +fi 1.318 +echo `insertFooter` >> "$targetDir/$index"