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