]> git.plutz.net Git - serve0/blob - multitag.sh
Merge commit '00aa1675c49f23eb075d1fc7ceb69bac5e1ba83c'
[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   [ "$fn" ] || continue
25   tags="$(UNSTRING "${tags#tags=}" |tr , '\n')"
26
27   if [ ! "$deltags" ]; then
28     extags="$(printf '%s' "${newtags}" |grep -e "^-" |cut -d: -f1 )"
29     [ "$extags" ] && tags="$(printf %s\\n "$tags" |grep -vwFe "$extags")"
30     if printf %s "${newtags}" |grep -e "^-" |grep -qEe "^-[^:]+$"; then
31       tags="$(printf %s\\n "$tags" |grep -vEe '^-[^:]+$')"
32     fi
33     tags="$(printf '%s\n' "${tags},${newtags}" \
34             | tr , '\n' |sort -u |tr '\n' , \
35             | STRING)"
36   else
37     detag="${deltags}${BR}"; while [ "$detag" ]; do
38       tags="$(printf '%s\n' "$tags" |grep -vxFe "${detag%%${BR}*}")"
39       detag="${detag#*${BR}}"
40     done
41     tags="$(printf '%s\n' "$tags" |sort -u |tr '\n' , |STRING)"
42   fi
43   tags="${tags#,}"; tags="${tags%,}"
44
45   if LOCK "$meta"; then
46     grep -avF " $fn" "$meta" >"${meta}.tmp"
47
48     printf '%i  %i      %i      tags=%s comment=%s      %s\n' \
49            "$length" "$width" "$height" "$tags" \
50            "${comment#comment=}" "$fn" \
51       >>"${meta}.tmp"
52     mv "${meta}.tmp" "$meta"
53
54     RELEASE "$meta"
55   fi
56 done