]> git.plutz.net Git - serve0/blob - multitag.sh
altered groupmatch algorithm
[serve0] / multitag.sh
1 #!/bin/sh
2
3 . "$_EXEC/cgilite/storage.sh"
4 . "$_EXEC/indexmeta.sh"
5
6 newtags=''
7 for tn in $(seq 1 $(POST_COUNT tag)); do
8   newtags="$(POST tag $tn)${BR}${newtags}"
9 done
10 newtags="$(POST newtag |tr -d '\r' |tr , '\n')${BR}${newtags}"
11
12 while [ "${newtags#${BR}}" != "${newtags}" ]; do newtags="${newtags#${BR}}"; done
13 while [ "${newtags%${BR}}" != "${newtags}" ]; do newtags="${newtags%${BR}}"; done
14
15 [ "$(POST op)" = del ] && deltags="$newtags"
16
17 for select in $(seq 1 $(POST_COUNT select)); do
18   file="$_DATA/$ITEM/$(POST select $select |PATH)"
19   meta="${file%/*}/.index/meta"
20
21   read -r length width height tags comment fn <<-EOF
22         $(meta_info "$file")
23         EOF
24   tags="$(UNSTRING "${tags#tags=}" |tr , '\n')"
25
26   if [ ! "$deltags" ]; then
27     extags="$(printf '%s' "${newtags}" |grep -e "^-" |cut -d: -f1 )"
28     [ "$extags" ] && tags="$(printf %s\\n "$tags" |grep -vwFe "$extags")"
29     if printf %s "${newtags}" |grep -e "^-" |grep -qEe "^-[^:]+$"; then
30       tags="$(printf %s\\n "$tags" |grep -vEe '^-[^:]+$')"
31     fi
32     tags="$(printf '%s\n' "${tags},${newtags}" \
33             | tr , '\n' |sort -u |tr '\n' , \
34             | STRING)"
35   else
36     detag="${deltags}${BR}"; while [ "$detag" ]; do
37       tags="$(printf '%s\n' "$tags" |grep -vxFe "${detag%%${BR}*}")"
38       detag="${detag#*${BR}}"
39     done
40     tags="$(printf '%s\n' "$tags" |sort -u |tr '\n' , |STRING)"
41   fi
42   tags="${tags#,}"; tags="${tags%,}"
43
44   if LOCK "$meta"; then
45     grep -avF " $fn" "$meta" >"${meta}.tmp"
46
47     printf '%i  %i      %i      tags=%s comment=%s      %s\n' \
48            "$length" "$width" "$height" "$tags" \
49            "${comment#comment=}" "$fn" \
50       >>"${meta}.tmp"
51     mv "${meta}.tmp" "$meta"
52
53     RELEASE "$meta"
54   fi
55 done