]> git.plutz.net Git - serve0/blob - multitag.sh
allow manual grouping
[serve0] / multitag.sh
1 #!/bin/sh
2
3 . "$_EXEC/db_meta.sh"
4 . "$_EXEC/cgilite/session.sh" nocookie
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 newtagn |tr -d '\r' |tr , '\n')${BR}${newtags}"
11
12 if [ "$(POST makegroup)" = true ]; then
13   group="$(timeid)"
14 fi
15
16 while [ "${newtags#${BR}}" != "${newtags}" ]; do newtags="${newtags#${BR}}"; done
17 while [ "${newtags%${BR}}" != "${newtags}" ]; do newtags="${newtags%${BR}}"; done
18
19 [ "$(POST op)" = del ] && deltags="$newtags"
20
21 for select in $(seq 1 $(POST_COUNT select)); do
22   file="$(POST select $select)"
23
24   read_meta "${file%.*}" || continue
25   tags="$(printf %s\\n "$META_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   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' ,)"
41   fi
42   tags="${tags#,}"; tags="${tags%,}"
43
44   if [ "$group" ]; then
45     update_meta "$META_NAME" tags="${tags}" group="${group}"
46   else
47     update_meta "$META_NAME" tags="${tags}"
48   fi
49 done