--- scripts/pgallery/src/pgallery.sh 2012/08/29 13:36:01 1.14 +++ scripts/pgallery/src/pgallery.sh 2012/09/11 15:40:43 1.22 @@ -1,12 +1,13 @@ -#!/bin/sh +#!/home/as/sh # # THE BEER-WARE LICENSE 2012 # 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/pgallery.sh,v 1.13 2012/08/29 12:41:06 as Exp $ +# $Paefchen: scripts/pgallery/src/pgallery.sh,v 1.21 2012/08/31 15:58:03 as Exp $ # +. $(dirname $0)/libpgallery ARG_TITLE="PGallery" ARG_FILES= @@ -24,16 +25,12 @@ ARG_MAILTO="" ARG_MAILFROM="PGallery <${USER}@${HOST}>" ARG_URL= ARG_EXIF="0x920a 0x829d 0x829a ISO 0x8827 / 0x010f - 0x0110" +ARG_INDEXIMG= +ARG_STARTTS= +ARG_ENDTS= +ARG_LINK= -BIN_CONVERT="/usr/local/bin/convert" -BIN_EXIFAUTOTRAN="/usr/local/bin/exifautotran" -BIN_IMGINFO="/usr/local/bin/imginfo" -BIN_SENDMAIL="/usr/sbin/sendmail" -BIN_EXIFTRAN="/usr/local/bin/exiftran" -BIN_EXIF="/usr/local/bin/exif" - MKAKEFILE=".htmakefile" -VERSION="pgallery-1.2" # # usage() @@ -42,7 +39,7 @@ usage() { cat <] | [-s ] ) [-d ] [-n ] - [-t ] [-u ] + [-t ] [-u ] [-H ] [-b ] [-c ] [-l link] [-e ] [-i ] [-C ] [-F ] [-T ] [-U] | -h | -v @@ -56,6 +53,7 @@ Options: -h this page -i name index file name (default: $ARG_INDEX) -l url gallery link + -m image image for pgalleryindex. default the first image -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 @@ -65,11 +63,12 @@ Options: -v print version -C copyright copyright (html) string (default: $ARG_COPYRIGHT) -F from mail sender (default: $ARG_MAILFROM) + -L link optional home link -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 + EXIF INDEXIMG LINK -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 @@ -77,434 +76,25 @@ USAGE exit } -# -# get_my_path() -# -get_my_path() -{ - current=$(pwd) - cd $(dirname $0) - echo $(pwd)/$(basename $0) - cd "$current" -} - -# -# html_header() -# -html_header() -{ - cat < - - - $ARG_TITLE - - - - -HTML -} - -# -# html_footer() -# -html_footer() -{ - cat < -HTML -} - -# -# html_tn() -# -html_tn() -{ - tn=$1 - link=$2 - - info=$($BIN_IMGINFO -f $tn) - width=$(echo $info | awk '{print $3}') - height=$(echo $info | awk '{print $4}') - top=$(($(($ARG_TNSIZE - $height)) / 2)) - - cat < - - $tn - - -HTML -} - -# -# html_img() -# -html_img() -{ - orig=$1 - num=$2 - all=$3 - img=$4 - link=$5 - linkb=$6 - linkn=$7 - - info=$($BIN_IMGINFO -f $img) - width=$(echo $info | awk '{print $3}') - height=$(echo $info | awk '{print $4}') - - desc=$(get_exif_desc $orig) - if [ "$desc" != "" ] +# first find image dir +is_dir=0 +for arg in $* +do + if [ $is_dir -eq 1 ] then - desc="
$desc
" + ARG_DIR="$arg" + break fi + test $arg = -d && is_dir=1 +done - if [ "$linkb" != "" ] - then - hlinkb="prev" - olinkb="" - fi +# load save args +if [ -f "$ARG_DIR/$ARGFILE" ] +then + echo "load save settings" + . "$ARG_DIR/$ARGFILE" +fi - if [ "$linkn" != "" ] - then - hlinkn="next" - olinkn="" - fi - - cat < - -
- $img -
- $desc -
-
$(get_exif_info $orig)
-
$ARG_TITLE $ARG_COPYRIGHT
-
-
- $olinkb - $olinkn -
- -HTML -} - -# -# err -# -err() -{ - echo "$1" >&2 - exit 1 -} - -# -# mysendmail() -# -mysendmail() -{ - subject=$1 - ( - cat < /dev/null | iconv -t ISO-8859-1 -f UTF-8 | while read line - do - echo "$line
" - done -} - -# -# get_exif_ts() -# -get_exif_ts() -{ - img=$1 - date=$($BIN_EXIF --ifd=EXIF --tag=0x9003 -m $img 2> /dev/null) - if [ "$date" = "" ] - then - echo "-1" - return 1 - fi - date -j -f "%Y:%m:%d %T" "$date" "+%s" -} - -# -# get_exif_date() -# -get_exif_date() -{ - img=$1 - ts=$(get_exif_ts $img) && date -r $ts "+%d.%m.%Y %H:%M" || echo "" -} - -# -# get_exif_value() -# -get_exif_value() -{ - img=$1 - hex=$2 - $BIN_EXIFTRAN -d $img | grep $hex | sed -E 's/^.{45}//' -} - -# -# get_exif_info() -# -get_exif_info() -{ - img=$1 - - exifinfo= - created=$(get_exif_date $img) && exifinfo="$created / " - - for exif in $ARG_EXIF - do - if echo $exif | grep -q -E '0x[[:alnum:]]{4}' - then - exifinfo="$exifinfo$(get_exif_value $img $exif) " - else - exifinfo="$exifinfo$exif " - fi - done - echo $exifinfo | sed -E -e 's/ mm /mm /' -e 's/ sec./s/' -e 's/ ISO / ISO/' -e 's/ ISO(\/| )/ \1/' -} - -# -# is_in_list() -# -is_in_list() -{ - list=$1 - value=$2 - for entry in $list - do - test "$entry" = "$value" && return 0 - done - return 1 -} - # parse args while [ "$1" != "" ] do @@ -549,6 +139,9 @@ do -F) ARG_MAILFROM=$1 shift;; + -L) + ARG_LINK=$1 + shift;; -I) ARG_INFOFILE=$1 shift;; @@ -575,7 +168,7 @@ if [ "$ARG_INFOFILE" != "" ] then test -f $ARG_INFOFILE || err "info file not found \`\`$ARG_INFOFILE''" for n in TITLE COPYRIGHT INDEX FILETYPES TNSIZE TNQALITY BIGSIZE \ - BIGQALITY MAILTO MAILFROM URL EXIF + BIGQALITY MAILTO MAILFROM URL EXIF INDEXIMG LINK do v=$(make -f $ARG_INFOFILE -V$n) test "$v" = "" && continue @@ -583,6 +176,13 @@ then 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 @@ -598,19 +198,22 @@ then match="$match *.$(echo $type | tr '[:lower:]' '[:upper:]')" match="$match *.$(echo $type | tr '[:upper:]' '[:lower:]')" done - ARG_FILES=$(cd $ARG_DIR && ls $match 2>/dev/null) + FLIST=$(ls $match 2>/dev/null) +else + FLIST="$ARG_FILES" fi # Filter big and thumbnails echo -n "find images" -FLIST= -for file in $ARG_FILES +FLISTF= +for file in $FLIST do test $(echo $file | grep -E '\.(tn|big)\.jpg$') && continue - FLIST="$FLIST $file" + FLISTF="$FLISTF $file" echo -n " $file" done -echo +echo +FLIST="$FLISTF" test $(echo $FLIST | wc -w) -eq 0 && err "error: no image found in \`\`$ARG_DIR''" @@ -624,6 +227,13 @@ FLIST=$( ) | sort -n | awk '{print $2}' ) +# if no master image, we use the first one +test "$ARG_INDEXIMG" = "" && ARG_INDEXIMG=$(echo $FLIST | awk '{print $1}') + +# find start and end ts +ARG_STARTTS=$(get_exif_ts $(echo $FLIST | awk '{print $1}')) +ARG_ENDTS=$(get_exif_ts $(echo $FLIST | awk '{print $NF}')) + # find new and to update images FLIST_NEW= FLIST_UPDATE= @@ -650,6 +260,15 @@ echo "tns: $targets" >> $MKAKEFILE FLIST_UPDATE=$(make -f $MKAKEFILE) rm $MKAKEFILE +# save args +test -f $ARGFILE && rm $ARGFILE +echo "save settings" +set | while read n +do + echo "$n" | grep -q '^ARG_' || continue + echo "$n" >> $ARGFILE +done + # update and no new and update images found if [ $ARG_UPDATE -eq 1 -a "$FLIST_NEW" = "" -a "$FLIST_UPDATE" = "" ] then @@ -696,24 +315,33 @@ make -f $MKAKEFILE rm $MKAKEFILE # create html index -index="" -for file in $FLIST -do - tn="${file}.tn.jpg" - imglink="${file}.html" - index="$index $(html_tn $tn $imglink)" -done echo create html index ( html_header - echo $index + + startdate= + test $ARG_STARTTS -ne -1 && startdate=$(date -r $ARG_STARTTS "+%d.%m.%Y") + enddate= + test $ARG_ENDTS -ne -1 && enddate=$(date -r $ARG_ENDTS "+%d.%m.%Y") + date= + test "$startdate" != "" && date="$startdate" + test "$enddate" != "$startdate" && date="$date - $enddate" + link= + test "$ARG_LINK" != "" && link="overview" + html_title "$ARG_TITLE" "$link" "$date" + + for file in $FLIST + do + tn="${file}.tn.jpg" + imglink="${file}.html" + html_tn $tn $imglink + done echo "
" echo "
$ARG_TITLE $ARG_COPYRIGHT
" html_footer ) > $ARG_INDEX # create single html files -#test $ARG_UPDATE -eq 1 && FLIST="$FLIST_NEW $FLIST_UPDATE" i=0 all=$(echo $FLIST | wc -w) echo -n "create single html files " @@ -747,6 +375,14 @@ do ) > $imglink done echo + +# .htaccess +if [ -f .htaccess ] +then + grep -q 'AddCharset UTF-8 .html' < .htaccess || echo "AddCharset UTF-8 .html" >> .htaccess +else + echo "AddCharset UTF-8 .html" > .htaccess +fi test "$ARG_MAILTO" = "" && exit 0