From 800ecf65f1a9ab0b2b57c8225284a66f3107f5ff Mon Sep 17 00:00:00 2001 From: Georg Date: Sat, 25 Sep 2021 21:19:48 +0200 Subject: Less data loss, neater editor Signed-off-by: Georg --- pounceman.sh | 105 ++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 64 insertions(+), 41 deletions(-) diff --git a/pounceman.sh b/pounceman.sh index c64e4a1..180b36e 100755 --- a/pounceman.sh +++ b/pounceman.sh @@ -46,10 +46,20 @@ get_networks() { RADIOLIST="$RADIOLIST $FILENAME $FILENAME off" let COUNTER=COUNTER+1 done - user_choice=$(dialog --backtitle "LibertaCasa IRC Services - Pounce Division - https://liberta.casa/" \ - --radiolist "Networks" 0 0 $COUNTER \ - $RADIOLIST \ - 2>&1 1>&3) + if [ $1 = "enabled" ]; then + user_choice=$(dialog --ok-label "Edit" \ + --backtitle "LibertaCasa IRC Services - Pounce Division - https://liberta.casa/" \ + --radiolist "Networks" 0 0 $COUNTER \ + $RADIOLIST \ + 2>&1 1>&3) + fi + if [ $1 = "disabled" ]; then + user_choice=$(dialog --ok-label "Edit" \ + --backtitle "LibertaCasa IRC Services - Pounce Division - https://liberta.casa/" \ + --radiolist "Networks" 0 0 $COUNTER \ + $RADIOLIST \ + 2>&1 1>&3) + fi exec 3>&- echo $user_choice > /tmp/userchoice else @@ -66,52 +76,65 @@ edit_network() { cp $pouncedir/users/$USER/$1/$user_choice $tmpfile nw_name=$user_choice nw_hostname=$(egrep '(^|\s)host =' $tmpfile | sed 's/host = //' - ) - nw_nickname=$(grep 'nick' $tmpfile | sed 's/nick = //' - ) - nw_password=$(grep 'sasl-plain' $tmpfile | sed 's/sasl-plain = //' - ) - nw_channels=$(grep 'join' $tmpfile | sed 's/join = //' - ) + nw_nickname=$(egrep '(^|\s)nick =' $tmpfile | sed 's/nick = //' - ) + nw_password=$(egrep '(^|\s)sasl-plain =' $tmpfile | sed 's/sasl-plain = //' - ) + nw_channels=$(egrep '(^|\s)join =' $tmpfile | sed 's/join = //' - ) nw_away=$(grep 'away' $tmpfile | sed 's/away = //' -) + echo "$nw_hostname\n$nw_nickname\n$nw_password\n$nw_channels\n$nw_away" > /tmp/nwvars exec 3>&1 - user_input=$(dialog --ok-label "Submit" \ + user_input=$(dialog --ok-label "Save" \ --extra-button \ --extra-label "Delete" \ --backtitle "LibertaCasa IRC Services - Pounce Division - https://liberta.casa/" \ - --title "New IRC Network" \ - --form "Network specific details:" \ - 20 50 0 \ - "Arbitrary name:" 1 1 "$nw_name" 1 10 20 0 \ - "Hostname:" 2 1 "$nw_hostname" 2 10 20 0 \ - "Nickname:" 3 1 "$nw_nickname" 3 10 20 0 \ - "SASL Password:" 4 1 "$nw_password" 4 10 20 0 \ - "Channels:" 5 1 "$nw_channels" 5 10 20 0 \ - "Away message:" 6 1 "$nw_away" 6 10 20 0 \ + --title "Edit IRC Network" \ + --form "$USER/$nw_name:" \ + 15 60 0 \ + "Hostname:" 1 1 "$nw_hostname" 1 18 33 0 \ + "Nickname:" 2 1 "$nw_nickname" 2 18 33 0 \ + "SASL Password:" 3 1 "$nw_password" 3 18 33 0 \ + "Channels:" 4 1 "$nw_channels" 4 18 33 0 \ + "Away message:" 5 1 "$nw_away" 5 18 33 0 \ 2>&1 1>&3) exit_status=$? exec 3>&- echo $user_input > /tmp/userinput - tmp_name=$(echo "$user_input" | sed -n 1p) - tmp_hostname=$(echo "$user_input" | sed -n 2p) - tmp_nickname=$(echo "$user_input" | sed -n 3p) - tmp_password=$(echo "$user_input" | sed -n 4p) - tmp_channels=$(echo "$user_input" | sed -n 5p) - tmp_away=$(echo "$user_input" | sed -n 6p) - sed -e "s/$(egrep '(^|\s)host =' $tmpfile)/host = $tmp_hostname/" -i $tmpfile -# sed -e "s/$nw_name/$tmp_name/" -i $tmpfile -# sed -e "s/$nw_pasword/$tmp_password/" -i $tmpfile -# sed -e "s/$nw_hostname/$tmp_hostname/" -i $tmpfile -# sed -e "s/$nw_channels/$tmp_channels/" -i $tmpfile -# sed -e "s/$nw_nickname/$tmp_nickname/" -i $tmpfile -# sed -e "s/$nw_away/$tmp_away/" -i $tmpfile - DIFF=$(diff $pouncedir/users/$USER/$1/$user_choice $tmpfile) - if [ ! "$DIFF" = "" ]; then - cp $tmpfile $pouncedir/users/$USER/$1/$user_choice - fi - #rm $tmpfile + case $exit_status in + 0) + tmp_name=$(echo "$user_input" | sed -n 1p) + tmp_hostname=$(echo "$user_input" | sed -n 2p) + tmp_nickname=$(echo "$user_input" | sed -n 3p) + tmp_password=$(echo "$user_input" | sed -n 4p) + tmp_channels=$(echo "$user_input" | sed -n 5p) + tmp_away=$(echo "$user_input" | sed -n 6p) + echo "$tmp_name\n$tmp_nickname\n$tmp_password\n$tmp_channels\n$tmp_away" > /tmp/tmpvars + sed -e "s/$(egrep '(^|\s)host =' $tmpfile)/host = $tmp_hostname/" -i $tmpfile + sed -e "s/$(egrep '(^|\s)nick =' $tmpfile)/nick = $tmp_nickname/" -i $tmpfile + sed -e "s+$(egrep '(^|\s)real =' $tmpfile)+real = $tmp_nickname - https://liberta.casa/+" -i $tmpfile + sed -e "s/$(egrep '(^|\s)user =' $tmpfile)/user = $tmp_nickname/" -i $tmpfile + sed -e "s/$(egrep '(^|\s)sasl-plain =' $tmpfile)/sasl-plain = $tmp_password/" -i $tmpfile + sed -e "s/$(egrep '(^|\s)join =' $tmpfile)/join = $tmp_channels/" -i $tmpfile + sed -e "s/$(egrep '(^|\s)away =' $tmpfile)/away = $tmp_away/" -i $tmpfile + DIFF=$(diff $pouncedir/users/$USER/$1/$user_choice $tmpfile) + if [ ! "$DIFF" = "" ]; then + cp $tmpfile $pouncedir/users/$USER/$1/$user_choice + fi + rm $tmpfile + ;; + esac nw_name="" nw_hostname="" nw_nickname="" nw_password="" nw_channels="" nw_away="" + tmp_name="" + tmp_hostname="" + tmp_nickname="" + tmp_password="" + tmp_channels="" + tmp_away="" + tmpfile="" + DIFF="" } set_network() { @@ -140,12 +163,12 @@ add_network() { --title "New IRC Network" \ --form "Network specific details:" \ 20 50 0 \ - "Arbitrary name:" 1 1 "$nw_name" 1 10 20 0 \ - "Hostname:" 2 1 "$nw_hostname" 2 10 20 0 \ - "Nickname:" 3 1 "$nw_nickname" 3 10 20 0 \ - "SASL Password:" 4 1 "$nw_password" 4 10 20 0 \ - "Channels:" 5 1 "$nw_channels" 5 10 20 0 \ - "Away message:" 6 1 "$nw_away" 6 10 20 0 \ + "Arbitrary name:" 1 1 "$nw_name" 1 18 33 0 \ + "Hostname:" 2 1 "$nw_hostname" 2 18 33 0 \ + "Nickname:" 3 1 "$nw_nickname" 3 18 33 0 \ + "SASL Password:" 4 1 "$nw_password" 4 18 33 0 \ + "Channels:" 5 1 "$nw_channels" 5 18 33 0 \ + "Away message:" 6 1 "$nw_away" 6 18 33 0 \ 2>&1 1>&3) #3>&1 1>&2 2>&3 3>&-) exec 3>&- -- cgit v1.2.3