]> git.plutz.net Git - serve0/blob - helpers/genall.sh
78e079432be0752de965b5f21391964b50744883
[serve0] / helpers / genall.sh
1 #!/bin/zsh
2 # Copyright 2014 - 2016 Paul Hänsch
3 #
4 # This file is part of Serve0
5 #
6 # Serve0 is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Serve0 is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU Affero General Public License for more details.
15 #
16 # You should have received a copy of the GNU Affero General Public License
17 # along with Serve0  If not, see <http://www.gnu.org/licenses/>.
18
19 dir="$(dirname $0)"
20 genmeta="$dir/genmeta.sh"
21 genthumb="$dir/genthumb.sh"
22 . "$dir/../constants.sh"
23
24 addtag(){
25   meta="$1"
26   tag="$2"
27   
28   length=0; width=0; height=0;
29   if [ -r "$meta" ]; then
30     head -n1 "$meta" |read length width height info
31     tags="$(sed -n 2p "$meta" |sed -r 's:^\|(.*)$:\1:')"
32     description="$(sed -n '3,$p' "$meta")"
33   fi
34   
35   egrep -q "(^|.*\|)$tag(\|.*|$)" <<<"$tags" || tags="$tag|$tags"
36   
37   cat >"$meta" <<EOF
38 $length $width  $height $info
39 $tags
40 $description
41 EOF
42 }
43
44
45 for each in *; do
46 if (egrep -q "$file_pattern" <<<"$each"); then
47   printf %s "$each ... Thumb ..."
48   $genthumb "$each" "${each}.jpg" >/dev/null 2>/dev/null
49   printf %s ' Meta ...'
50   $genmeta "$each" "${each}.meta" >/dev/null 2>/dev/null
51   printf %s ' Tags ...'
52   for tag in $*; do
53     addtag "${each}.meta" "$tag"
54   done
55   printf 'Done!\n'
56 fi; done