Annotation of scripts/pgallery/src/pgalleryindex.sh, revision 1.6
1.4 as 1: #!/usr/local/libexec/pgallerysh
1.1 as 2: #
1.5 as 3: # THE BEER-WARE LICENSE 2012,13
4:
1.1 as 5: # <as@paefchen.net> wrote this file. As long as you retain this notice you
6: # can do whatever you want with this stuff. If we meet some day, and you think
7: # this stuff is worth it, you can buy me a beer in return Aron Schlesinger
8: #
1.6 ! as 9: # $Paefchen: scripts/pgallery/src/pgalleryindex.sh,v 1.5 2013/04/03 08:33:29 as Exp $
1.1 as 10: #
11:
1.3 as 12: . /usr/local/libexec/libpgallery
1.1 as 13:
14: ARG_TITLE="PGallery"
15: ARG_TNSIZE="180"
16: ARG_BIGSIZE="950"
17: ARG_INDEX="index.html"
18: ARG_DIR="."
19: ARG_COPYRIGHT="© $(date +%Y)"
20:
21: #
22: # usage()
23: #
24: usage()
25: {
26: cat <<USAGE
1.2 as 27: usage $0: ( [-d <dir>] [-n <name>] [-i <index>] [-C <copyright>] [-I <config>]
28: | -h | -v
1.1 as 29: Options:
30: -d dir gallery dir (default: $ARG_DIR)
31: -h this page
32: -i name index file name (default: $ARG_INDEX)
33: -n name page title (default: $ARG_TITLE)
34: -v print version
35: -C copyright copyright (html) string (default: $ARG_COPYRIGHT)
1.2 as 36: -I config info text file for pgallery. info file paras prefered.
1.1 as 37: the syntax of the file is MAKE(1)
1.2 as 38: supported variable: TITLE COPYRIGHT INDEX
1.1 as 39: USAGE
40: exit
41: }
42:
43: # parse args
44: while [ "$1" != "" ]
45: do
46: arg=$1
47: shift
48: case $arg in
49: -h)
50: usage;;
51: -n)
52: ARG_TITLE=$1
53: shift;;
54: -d)
55: ARG_DIR=$1
56: shift;;
57: -C)
58: ARG_COPYRIGHT=$1
59: shift;;
60: -I)
61: ARG_INFOFILE=$1
62: shift;;
63: -v)
64: echo $VERSION
65: exit;;
66: *)
67: echo "unknown argument $arg"
68: exit
69: esac
70: done
71:
72: # go to gallery directory
73: MY=$(get_my_path)
74: cd "$ARG_DIR" || exit 1
75:
76: # parese info file
77: if [ "$ARG_INFOFILE" != "" ]
78: then
79: test -f $ARG_INFOFILE || err "info file not found \`\`$ARG_INFOFILE''"
1.2 as 80: for n in TITLE INDEX COPYRIGHT
1.1 as 81: do
82: v=$(make -f $ARG_INFOFILE -V$n)
83: test "$v" = "" && continue
84: eval "ARG_$n='$v'"
85: done
86: fi
87:
88: # paras from iso to utf-8
89: for n in $(set | awk -F= '{print $1}')
90: do
91: echo "$n" | grep -q '^ARG_' || continue
1.4 as 92: eval "$n=\"\$(echo \"\$$n\" | $BIN_ICONV -f ISO-8859-1 -t UTF-8)\""
1.1 as 93: done
94:
95: title="$ARG_TITLE"
96: cr="$ARG_COPYRIGHT"
97:
98: DIRS=
99: for dir in $(find . -type d -maxdepth 1 -mindepth 1)
100: do
101: test -f "$dir/$ARGFILE" || continue
1.6 ! as 102: ARG_INDEXIMG=
! 103: ARG_NOINDEX=
1.1 as 104: . "$dir/$ARGFILE"
105: test "$ARG_INDEXIMG" = "" && continue
1.6 ! as 106: test "$ARG_NOINDEX" != "" && continue
1.1 as 107: DIRS="$DIRS $dir"
108: done
109:
110: test "$DIRS" = "" && err "no pgallery found"
111:
112: DIRS=$(
113: (
114: for dir in $DIRS
115: do
116: . "$dir/$ARGFILE"
117: echo "$(get_exif_ts ${dir}/${ARG_INDEXIMG}) $dir"
118: done
119: ) | sort -nr | awk '{print $2}'
120: )
121:
122: # create index
123: ARG_TITLE="$title"
124: ARG_COPYRIGHT="$cr"
125: (
126: html_header
127: for dir in $DIRS
128: do
129: test -f "$dir/$ARGFILE" || continue
130: . "$dir/$ARGFILE"
131: test "$ARG_INDEXIMG" = "" && continue
132: tn="$dir/${ARG_INDEXIMG}.tn.jpg"
133: imglink="${dir}/${ARG_INDEX}"
134: html_tn $tn $imglink "$ARG_TITLE"
135: done
136: echo "<div class='clear'></div>"
137: echo "<div class='c'>$ARG_COPYRIGHT</div>"
138: html_footer
139: ) > $ARG_INDEX