]> git.plutz.net Git - serve0/blob - multitag.sh
improved time formatting
[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="${newtags},$(POST tag $tn)"
9 done
10 newtags="${newtags},$(POST newtag |tr -d '\r' |tr '\n' ,)"
11 [ "$(POST op)" = del ] && deltags="$newtags"
12
13 for select in $(seq 1 $(POST_COUNT select)); do
14   file="$_DATA/$ITEM/$(POST select $select |PATH)"
15   meta="${file%/*}/.index/meta"
16
17   read -r length width height tags comment fn <<-EOF
18         $(meta_info "$file")
19         EOF
20   tags="$(UNSTRING "${tags#tags=}" |tr , '\n')"
21
22   if [ ! "$deltags" ]; then
23     tags="$(printf '%s\n' "${tags},${newtags}" \
24             | tr , '\n' |sort -u |tr '\n' , \
25             | STRING)"
26   else
27     detag="${deltags},"; while [ "$detag" ]; do
28       tags="$(printf '%s\n' "$tags" |grep -vxFe "${detag%%,*}")"
29       detag="${detag#*,}"
30     done
31     tags="$(printf '%s\n' "$tags" |sort -u |tr '\n' , |STRING)"
32   fi
33   tags="${tags#,}"; tags="${tags%,}"
34
35   if LOCK "$meta"; then
36     grep -avF " $fn" "$meta" >"${meta}.tmp"
37
38     printf '%i  %i      %i      tags=%s comment=%s      %s\n' \
39            "$length" "$width" "$height" "$tags" \
40            "${comment#comment=}" "$fn" \
41       >>"${meta}.tmp"
42     mv "${meta}.tmp" "$meta"
43
44     RELEASE "$meta"
45   fi
46 done