X-Git-Url: https://git.plutz.net/?p=confetti;a=blobdiff_plain;f=categories%2Fupdate_categories.sh;fp=actions%2Fupdate_categories.sh;h=108c5d55f20859f8ae9fad66e363fd2da49faaa5;hp=c3b2e4c3f71dc9709b16b21322134e27cf31d0ef;hb=76c1e7bff1a8604ef2ef7da5d274d0db0e639139;hpb=90288ab07bb1ec83a91581fadc674a87a250a853 diff --git a/actions/update_categories.sh b/categories/update_categories.sh similarity index 54% rename from actions/update_categories.sh rename to categories/update_categories.sh index c3b2e4c..108c5d5 100755 --- a/actions/update_categories.sh +++ b/categories/update_categories.sh @@ -1,6 +1,6 @@ -#!/bin/zsh +#!/bin/sh -# Copyright 2016 Paul Hänsch +# Copyright 2016, 2021 Paul Hänsch # # This file is part of Confetti. # @@ -17,35 +17,25 @@ # You should have received a copy of the GNU Affero General Public License # along with Confetti. If not, see . -. "$_EXEC"/pages/categories.sh +. "$_EXEC"/cgilite/storage.sh +. "$_EXEC"/pdiread.sh catfile="${_DATA}/mappings/categories" -set_categories(){ - card="${_DATA}/vcard/$1" - cats="$2" - cardcats="$(sed -nr 's;^CATEGORIES(\;[^":]+|\;"[^"]+")*:([^\r]+)\r?$;\2;p' "$card")" +for card in "${_DATA}"/vcard/*.vcf; do + n='' postcats='' cardcats='' + vcf="$(pdi_load "$card")" - debug "CARD: $card" - debug "CATS: $cardcats" - debug "NEW: $cats" - if [ "$cats" != "$cardcats" ]; then - sed -ri ' + n=1; while postcats="${postcats}${postcats:+,}$(POST "${card##*/}" $n)"; do n=$((n+1)); done + n=1; while cardcats="${cardcats}${cardcats:+,}$(pdi_value "$vcf" CATEGORIES $n)"; do n=$((n+1)); done + + if [ "${postcats}" != "${cardcats}" ] && LOCK "$card"; then + sed -E -i ' /^CATEGORIES[;:]/d - /^END:VCARD *\r?$/iCATEGORIES:'"$cats"'\r + /^END;?:VCARD *\r?$/iCATEGORIES:'"${postcats%,}"'\r ' "${card}" + RELEASE "$card" fi -} - -listcards |while read card; do - cardcats='' - for n in "$card" "$card"{0..100}; do - if [ -z "${_POST[$n]}" ]; then - set_categories "$card" "$cardcats" - break - fi - cardcats="${cardcats}${cardcats:+,}${_POST[$n]}" - done done -redirect "?p=categories" +REDIRECT /categories/