]> git.plutz.net Git - serve0/blob - multitag.sh
various code improvements (skip double sanitizing, bugfix in name handling, slight...
[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')"
11
12 for select in $(seq 1 $(POST_COUNT select)); do
13   file="$_DATA/$ITEM/$(POST select $select |PATH)"
14   meta="${file%/*}/.index/meta"
15
16   read -r length width height tags comment fn <<-EOF
17         $(meta_info "$file")
18         EOF
19
20   tags="$(UNSTRING "${tags#tags=}")"
21   tags="$(printf '%s\n' "${tags}" "${newtags}" |tr , '\n' |sort -u |tr '\n' , |STRING)"
22   tags="${tags#,}"; tags="${tags%,}"
23
24   if LOCK "$meta"; then
25     grep -avF " $fn" "$meta" >"${meta}.tmp"
26
27     printf '%i  %i      %i      tags=%s comment=%s      %s\n' \
28            "$length" "$width" "$height" "$tags" \
29            "${comment#comment=}" "$fn" \
30       >>"${meta}.tmp"
31     mv "${meta}.tmp" "$meta"
32
33     RELEASE "$meta"
34   fi
35 done