X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=therapy%2Fupdate_therapy.sh;fp=therapy%2Fupdate_therapy.sh;h=6ba06cbd41214d84efe623d7c640020cd049d191;hb=43e7c60df0632fd383306a2d3c6dc8c4213d4b9d;hp=0000000000000000000000000000000000000000;hpb=d40eb749c3b9766eb85d843e712f1b86543232d2;p=confetti diff --git a/therapy/update_therapy.sh b/therapy/update_therapy.sh new file mode 100755 index 0000000..6ba06cb --- /dev/null +++ b/therapy/update_therapy.sh @@ -0,0 +1,70 @@ +#!/bin/zsh + +# Copyright 2016 Paul Hänsch +# +# This file is part of Confetti. +# +# Confetti is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Confetti is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Confetti. If not, see . + +BR=' +' +tpy="${_POST[id]}" + +tpyfile="$_DATA/therapies/$tpy" +tempfile="$_DATA/temp/$tpy" + +# serialize POST array into file +for key in ${(k)_POST}; do + [ "$key" != imagedata ] && printf %s:%s\\n "$key" "${_POST[$key]//$BR/\\n}" +done >"$tempfile" + +if [ -n "$_POST[delete_session]" ]; then + n="$_POST[delete_session]" + sed -i -r '/^session'$n'[_:]/d' "$tempfile" + rm "${tpyfile%.tpy}_session${n}.png" + + while grep -Eq '^session'$(($n + 1))'_' "$tempfile"; do + sed -i -r 's;^session'$(($n + 1))'(_|:);session'$n'\1;' "$tempfile" + mv "${tpyfile%.tpy}_session$(($n+1)).png" "${tpyfile%.tpy}_session${n}.png" + n=$(($n+1)) + done + +elif [ -n "$_POST[new_session]" ]; then + sid="$_POST[new_session]" + + identify "$_EXEC/static/therapy_background.png" \ + | sed -r 's;^.* ([0-9]+x[0-9]+) .*$;\1;' \ + | read dim + + convert -size "$dim" xc:transparent "${tpyfile%.tpy}_${sid}.png" + + printf '%s:exists\n' "$sid" >>"$tempfile" + printf '%s_open:checked\n' "$sid" >>"$tempfile" + +elif [ -n "$_POST[imagedata]" ]; then + sed -rn 's;^(session[0-9]+)_open:checked$;\1;p' "$tempfile" \ + | sort -n \ + | tail -n1 \ + | read sid + + convert "${tpyfile%.tpy}_${sid}.png" \ + -strokewidth 2 -fill '#00000000' \ + -draw "${_POST[imagedata]}" -transparent white \ + "${tpyfile%.tpy}_${sid}.png" + sync +fi + +mv "$tempfile" "$tpyfile" + +redirect "?p=therapy&id=${tpy}"