Annotation of scripts/pgallery/src/pgalleryindex.sh, revision 1.5
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.5 ! as 9: # $Paefchen: scripts/pgallery/src/pgalleryindex.sh,v 1.4 2013/04/03 08:06:45 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
102: . "$dir/$ARGFILE"
103: test "$ARG_INDEXIMG" = "" && continue
104: DIRS="$DIRS $dir"
105: done
106:
107: test "$DIRS" = "" && err "no pgallery found"
108:
109: DIRS=$(
110: (
111: for dir in $DIRS
112: do
113: . "$dir/$ARGFILE"
114: echo "$(get_exif_ts ${dir}/${ARG_INDEXIMG}) $dir"
115: done
116: ) | sort -nr | awk '{print $2}'
117: )
118:
119: # create index
120: ARG_TITLE="$title"
121: ARG_COPYRIGHT="$cr"
122: (
123: html_header
124: for dir in $DIRS
125: do
126: test -f "$dir/$ARGFILE" || continue
127: . "$dir/$ARGFILE"
128: test "$ARG_INDEXIMG" = "" && continue
129: tn="$dir/${ARG_INDEXIMG}.tn.jpg"
130: imglink="${dir}/${ARG_INDEX}"
131: html_tn $tn $imglink "$ARG_TITLE"
132: done
133: echo "<div class='clear'></div>"
134: echo "<div class='c'>$ARG_COPYRIGHT</div>"
135: html_footer
136: ) > $ARG_INDEX