Annotation of scripts/pgallery/src/pgalleryindex.sh, revision 1.1
1.1 ! as 1: #!/bin/sh
! 2: #
! 3: # THE BEER-WARE LICENSE 2012
! 4: # <as@paefchen.net> wrote this file. As long as you retain this notice you
! 5: # can do whatever you want with this stuff. If we meet some day, and you think
! 6: # this stuff is worth it, you can buy me a beer in return Aron Schlesinger
! 7: #
! 8: # $Paefchen: scripts/pgallery/src/pgallery.sh,v 1.17 2012/08/29 14:44:04 as Exp $
! 9: #
! 10:
! 11: . $(dirname $0)/libpgallery
! 12:
! 13: ARG_TITLE="PGallery"
! 14: #ARG_FILES=
! 15: #ARG_FILETYPES="jpg jpeg png gif tif tiff"
! 16: ARG_TNSIZE="180"
! 17: #ARG_TNQALITY="70"
! 18: ARG_BIGSIZE="950"
! 19: #ARG_BIGQALITY="90"
! 20: ARG_INDEX="index.html"
! 21: ARG_DIR="."
! 22: #ARG_UPDATE=1
! 23: ARG_COPYRIGHT="© $(date +%Y)"
! 24: #ARG_INFOFILE=""
! 25: #ARG_MAILTO=""
! 26: #ARG_MAILFROM="PGallery <${USER}@${HOST}>"
! 27: ARG_URL=
! 28: #ARG_EXIF="0x920a 0x829d 0x829a ISO 0x8827 / 0x010f - 0x0110"
! 29:
! 30: #MKAKEFILE=".htmakefile"
! 31:
! 32: #
! 33: # usage()
! 34: #
! 35: usage()
! 36: {
! 37: cat <<USAGE
! 38: usage $0: ( [-f <files>] | [-s <suffix>] ) [-d <dir>] [-n <name>]
! 39: [-t <thumbnail_size>] [-u <thumbnail_quality>]
! 40: [-b <big_size>] [-c <big_quality>] [-l link] [-e <exif>]
! 41: [-i <index>] [-C <copyright>] [-F <mailfrom>] [-T <mailto>]
! 42: [-U] | -h | -v
! 43: Options:
! 44: -b size size from big images in pixel (default: $ARG_BIGSIZE)
! 45: -c quality quality from big images 0-100% (default: $ARG_BIGQALITY)
! 46: -d dir gallery dir (default: $ARG_DIR)
! 47: -e exif list of tags in hex. (default: $ARG_EXIF)
! 48: see: http://www.exiv2.org/tags.html
! 49: -f files gallery images
! 50: -h this page
! 51: -i name index file name (default: $ARG_INDEX)
! 52: -l url gallery link
! 53: -n name page title (default: $ARG_TITLE)
! 54: -s suffix list of suffix. if no \`\`-f'' defined, used to find images
! 55: in \`\`-d'' directoy. case insensitive
! 56: (default: $ARG_FILETYPES)
! 57: -t size size from thumbnail images in pixel (default: $ARG_TNSIZE)
! 58: -u quality quality from thumbnail images 0-100% (default: $ARG_BIGQALITY)
! 59: -v print version
! 60: -C copyright copyright (html) string (default: $ARG_COPYRIGHT)
! 61: -F from mail sender (default: $ARG_MAILFROM)
! 62: -I file info text file for pgallery. info file paras prefered.
! 63: the syntax of the file is MAKE(1)
! 64: supported variable: TITLE COPYRIGHT INDEX FILETYPES TNSIZE URL
! 65: TNQALITY BIGSIZE BIGQALITY MAILTO MAILFROM
! 66: EXIF
! 67: -T mailto send update infos to this address. if not set, no mail delivery
! 68: -U no update, new calculation of all images.
! 69: normally only new and modified images will calculated
! 70: USAGE
! 71: exit
! 72: }
! 73:
! 74: # parse args
! 75: while [ "$1" != "" ]
! 76: do
! 77: arg=$1
! 78: shift
! 79: case $arg in
! 80: -h)
! 81: usage;;
! 82: -n)
! 83: ARG_TITLE=$1
! 84: shift;;
! 85: # -t)
! 86: # ARG_TNSIZE=$1
! 87: # shift;;
! 88: # -u)
! 89: # ARG_TNQALITY=$1
! 90: # shift;;
! 91: # -b)
! 92: # ARG_BIGSIZE=$1
! 93: # shift;;
! 94: # -c)
! 95: # ARG_BIGQALITY=$1
! 96: # shift;;
! 97: # -f)
! 98: # ARG_FILES=$1
! 99: # shift;;
! 100: -l)
! 101: ARG_URL=$1
! 102: shift;;
! 103: # -s)
! 104: # ARG_FILETYPES=$1
! 105: # shift;;
! 106: -d)
! 107: ARG_DIR=$1
! 108: shift;;
! 109: # -e)
! 110: # ARG_EXIF=$1
! 111: # shift;;
! 112: -C)
! 113: ARG_COPYRIGHT=$1
! 114: shift;;
! 115: # -F)
! 116: # ARG_MAILFROM=$1
! 117: # shift;;
! 118: -I)
! 119: ARG_INFOFILE=$1
! 120: shift;;
! 121: # -T)
! 122: # ARG_MAILTO=$1
! 123: # shift;;
! 124: # -U)
! 125: # ARG_UPDATE=0;;
! 126: -v)
! 127: echo $VERSION
! 128: exit;;
! 129: *)
! 130: echo "unknown argument $arg"
! 131: exit
! 132: esac
! 133: done
! 134:
! 135: # go to gallery directory
! 136: MY=$(get_my_path)
! 137: cd "$ARG_DIR" || exit 1
! 138:
! 139: # parese info file
! 140: if [ "$ARG_INFOFILE" != "" ]
! 141: then
! 142: test -f $ARG_INFOFILE || err "info file not found \`\`$ARG_INFOFILE''"
! 143: for n in TITLE INDEX URL COPYRIGHT
! 144: do
! 145: v=$(make -f $ARG_INFOFILE -V$n)
! 146: test "$v" = "" && continue
! 147: eval "ARG_$n='$v'"
! 148: done
! 149: fi
! 150:
! 151: # paras from iso to utf-8
! 152: for n in $(set | awk -F= '{print $1}')
! 153: do
! 154: echo "$n" | grep -q '^ARG_' || continue
! 155: eval "$n=\"\$(echo \"\$$n\" | iconv -f ISO-8859-1 -t UTF-8)\""
! 156: done
! 157:
! 158: # fix url
! 159: if [ "$ARG_URL" != "" ]
! 160: then
! 161: echo "$ARG_URL" | grep -q '/$' || ARG_URL="${ARG_URL}/"
! 162: fi
! 163:
! 164: title="$ARG_TITLE"
! 165: cr="$ARG_COPYRIGHT"
! 166:
! 167: DIRS=
! 168: for dir in $(find . -type d -maxdepth 1 -mindepth 1)
! 169: do
! 170: test -f "$dir/$ARGFILE" || continue
! 171: . "$dir/$ARGFILE"
! 172: test "$ARG_INDEXIMG" = "" && continue
! 173: DIRS="$DIRS $dir"
! 174: done
! 175:
! 176: test "$DIRS" = "" && err "no pgallery found"
! 177:
! 178: DIRS=$(
! 179: (
! 180: for dir in $DIRS
! 181: do
! 182: . "$dir/$ARGFILE"
! 183: echo "$(get_exif_ts ${dir}/${ARG_INDEXIMG}) $dir"
! 184: done
! 185: ) | sort -nr | awk '{print $2}'
! 186: )
! 187:
! 188: # create index
! 189: ARG_TITLE="$title"
! 190: ARG_COPYRIGHT="$cr"
! 191: (
! 192: html_header
! 193: for dir in $DIRS
! 194: do
! 195: test -f "$dir/$ARGFILE" || continue
! 196: . "$dir/$ARGFILE"
! 197: test "$ARG_INDEXIMG" = "" && continue
! 198: tn="$dir/${ARG_INDEXIMG}.tn.jpg"
! 199: imglink="${dir}/${ARG_INDEX}"
! 200: html_tn $tn $imglink "$ARG_TITLE"
! 201: done
! 202: echo "<div class='clear'></div>"
! 203: echo "<div class='c'>$ARG_COPYRIGHT</div>"
! 204: html_footer
! 205: ) > $ARG_INDEX