More case instead of if
Signed-off-by: Georg <georg@lysergic.dev>
This commit is contained in:
parent
800ecf65f1
commit
b8a9f8377e
79
pounceman.sh
79
pounceman.sh
@ -3,16 +3,8 @@
|
|||||||
DIALOG_CANCEL=1
|
DIALOG_CANCEL=1
|
||||||
DIALOG_ESC=255
|
DIALOG_ESC=255
|
||||||
DIALOG_EXTRA=3
|
DIALOG_EXTRA=3
|
||||||
HEIGHT=0
|
|
||||||
WIDTH=0
|
|
||||||
pouncedir="/var/lib/pounce"
|
pouncedir="/var/lib/pounce"
|
||||||
|
|
||||||
display_result() {
|
|
||||||
dialog --title "$1" \
|
|
||||||
--no-collapse \
|
|
||||||
--msgbox "$result" 0 0
|
|
||||||
}
|
|
||||||
|
|
||||||
menu() {
|
menu() {
|
||||||
exec 3>&1
|
exec 3>&1
|
||||||
selection=$(dialog \
|
selection=$(dialog \
|
||||||
@ -20,7 +12,7 @@ menu() {
|
|||||||
--title "Welcome!" \
|
--title "Welcome!" \
|
||||||
--clear \
|
--clear \
|
||||||
--cancel-label "Exit" \
|
--cancel-label "Exit" \
|
||||||
--menu "Please select:" $HEIGHT $WIDTH 4 \
|
--menu "Configure your IRC bouncer:" 0 0 8 \
|
||||||
"1" "Display active networks" \
|
"1" "Display active networks" \
|
||||||
"2" "Display disabled networks" \
|
"2" "Display disabled networks" \
|
||||||
"3" "Add new network" \
|
"3" "Add new network" \
|
||||||
@ -48,17 +40,35 @@ get_networks() {
|
|||||||
done
|
done
|
||||||
if [ $1 = "enabled" ]; then
|
if [ $1 = "enabled" ]; then
|
||||||
user_choice=$(dialog --ok-label "Edit" \
|
user_choice=$(dialog --ok-label "Edit" \
|
||||||
|
--extra-button \
|
||||||
|
--extra-label "Disable" \
|
||||||
--backtitle "LibertaCasa IRC Services - Pounce Division - https://liberta.casa/" \
|
--backtitle "LibertaCasa IRC Services - Pounce Division - https://liberta.casa/" \
|
||||||
--radiolist "Networks" 0 0 $COUNTER \
|
--radiolist "Networks" 0 0 $COUNTER \
|
||||||
$RADIOLIST \
|
$RADIOLIST \
|
||||||
2>&1 1>&3)
|
2>&1 1>&3)
|
||||||
|
exit_status=$?
|
||||||
|
case $exit_status in
|
||||||
|
0) edit_network "enabled"
|
||||||
|
;;
|
||||||
|
3) set_network "enabled"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
if [ $1 = "disabled" ]; then
|
if [ $1 = "disabled" ]; then
|
||||||
user_choice=$(dialog --ok-label "Edit" \
|
user_choice=$(dialog --ok-label "Edit" \
|
||||||
|
--extra-button \
|
||||||
|
--extra-label "Enable" \
|
||||||
--backtitle "LibertaCasa IRC Services - Pounce Division - https://liberta.casa/" \
|
--backtitle "LibertaCasa IRC Services - Pounce Division - https://liberta.casa/" \
|
||||||
--radiolist "Networks" 0 0 $COUNTER \
|
--radiolist "Networks" 0 0 $COUNTER \
|
||||||
$RADIOLIST \
|
$RADIOLIST \
|
||||||
2>&1 1>&3)
|
2>&1 1>&3)
|
||||||
|
exit_status=$?
|
||||||
|
case $exit_status in
|
||||||
|
0) edit_network "disabled"
|
||||||
|
;;
|
||||||
|
3) set_network "disabled"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
exec 3>&-
|
exec 3>&-
|
||||||
echo $user_choice > /tmp/userchoice
|
echo $user_choice > /tmp/userchoice
|
||||||
@ -79,7 +89,7 @@ edit_network() {
|
|||||||
nw_nickname=$(egrep '(^|\s)nick =' $tmpfile | sed 's/nick = //' - )
|
nw_nickname=$(egrep '(^|\s)nick =' $tmpfile | sed 's/nick = //' - )
|
||||||
nw_password=$(egrep '(^|\s)sasl-plain =' $tmpfile | sed 's/sasl-plain = //' - )
|
nw_password=$(egrep '(^|\s)sasl-plain =' $tmpfile | sed 's/sasl-plain = //' - )
|
||||||
nw_channels=$(egrep '(^|\s)join =' $tmpfile | sed 's/join = //' - )
|
nw_channels=$(egrep '(^|\s)join =' $tmpfile | sed 's/join = //' - )
|
||||||
nw_away=$(grep 'away' $tmpfile | sed 's/away = //' -)
|
nw_away=$(egrep '(^|\s)away =' $tmpfile | sed 's/away = //' -)
|
||||||
echo "$nw_hostname\n$nw_nickname\n$nw_password\n$nw_channels\n$nw_away" > /tmp/nwvars
|
echo "$nw_hostname\n$nw_nickname\n$nw_password\n$nw_channels\n$nw_away" > /tmp/nwvars
|
||||||
exec 3>&1
|
exec 3>&1
|
||||||
user_input=$(dialog --ok-label "Save" \
|
user_input=$(dialog --ok-label "Save" \
|
||||||
@ -100,12 +110,12 @@ edit_network() {
|
|||||||
echo $user_input > /tmp/userinput
|
echo $user_input > /tmp/userinput
|
||||||
case $exit_status in
|
case $exit_status in
|
||||||
0)
|
0)
|
||||||
tmp_name=$(echo "$user_input" | sed -n 1p)
|
#tmp_name=$(echo "$user_input" | sed -n 1p)
|
||||||
tmp_hostname=$(echo "$user_input" | sed -n 2p)
|
tmp_hostname=$(echo "$user_input" | sed -n 1p)
|
||||||
tmp_nickname=$(echo "$user_input" | sed -n 3p)
|
tmp_nickname=$(echo "$user_input" | sed -n 2p)
|
||||||
tmp_password=$(echo "$user_input" | sed -n 4p)
|
tmp_password=$(echo "$user_input" | sed -n 3p)
|
||||||
tmp_channels=$(echo "$user_input" | sed -n 5p)
|
tmp_channels=$(echo "$user_input" | sed -n 4p)
|
||||||
tmp_away=$(echo "$user_input" | sed -n 6p)
|
tmp_away=$(echo "$user_input" | sed -n 5p)
|
||||||
echo "$tmp_name\n$tmp_nickname\n$tmp_password\n$tmp_channels\n$tmp_away" > /tmp/tmpvars
|
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)host =' $tmpfile)/host = $tmp_hostname/" -i $tmpfile
|
||||||
sed -e "s/$(egrep '(^|\s)nick =' $tmpfile)/nick = $tmp_nickname/" -i $tmpfile
|
sed -e "s/$(egrep '(^|\s)nick =' $tmpfile)/nick = $tmp_nickname/" -i $tmpfile
|
||||||
@ -113,13 +123,16 @@ edit_network() {
|
|||||||
sed -e "s/$(egrep '(^|\s)user =' $tmpfile)/user = $tmp_nickname/" -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)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)join =' $tmpfile)/join = $tmp_channels/" -i $tmpfile
|
||||||
sed -e "s/$(egrep '(^|\s)away =' $tmpfile)/away = $tmp_away/" -i $tmpfile
|
sed -e "s+$(egrep '(^|\s)away =' $tmpfile)+away = $tmp_away+" -i $tmpfile
|
||||||
DIFF=$(diff $pouncedir/users/$USER/$1/$user_choice $tmpfile)
|
DIFF=$(diff $pouncedir/users/$USER/$1/$user_choice $tmpfile)
|
||||||
if [ ! "$DIFF" = "" ]; then
|
if [ ! "$DIFF" = "" ]; then
|
||||||
cp $tmpfile $pouncedir/users/$USER/$1/$user_choice
|
cp $tmpfile $pouncedir/users/$USER/$1/$user_choice
|
||||||
fi
|
fi
|
||||||
rm $tmpfile
|
rm $tmpfile
|
||||||
;;
|
;;
|
||||||
|
3)
|
||||||
|
remove_network
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
nw_name=""
|
nw_name=""
|
||||||
nw_hostname=""
|
nw_hostname=""
|
||||||
@ -181,10 +194,10 @@ add_network() {
|
|||||||
tmp_away=$(echo "$user_input" | sed -n 6p)
|
tmp_away=$(echo "$user_input" | sed -n 6p)
|
||||||
if [ ! $tmp_name = "TEMPLATE" ]; then
|
if [ ! $tmp_name = "TEMPLATE" ]; then
|
||||||
cp $pouncedir/TEMPLATE $pouncedir/users/$USER/disabled/$tmp_name
|
cp $pouncedir/TEMPLATE $pouncedir/users/$USER/disabled/$tmp_name
|
||||||
sed -e "s/%%POUNCEDIR%%/$pouncedir/" -i $pouncedir/users/$USER/disabled/$tmp_name
|
sed -e "s+%%POUNCEDIR%%+$pouncedir+" -i $pouncedir/users/$USER/disabled/$tmp_name
|
||||||
sed -e "s/%%USER%%/$USER/" -i $pouncedir/users/$USER/disabled/$tmp_name
|
sed -e "s/%%USER%%/$USER/" -i $pouncedir/users/$USER/disabled/$tmp_name
|
||||||
sed -e "s/%%NAME%%/$tmp_name/" -i $pouncedir/users/$USER/disabled/$tmp_name
|
sed -e "s/%%NAME%%/$tmp_name/" -i $pouncedir/users/$USER/disabled/$tmp_name
|
||||||
sed -e "s/%%PASSWORD%%/$tmp_password/" -i $pouncedir/users/$USER/disabled/$tmp_name
|
sed -e "s:%%PASSWORD%%:$tmp_password:" -i $pouncedir/users/$USER/disabled/$tmp_name
|
||||||
sed -e "s/%%HOSTNAME%%/$tmp_hostname/" -i $pouncedir/users/$USER/disabled/$tmp_name
|
sed -e "s/%%HOSTNAME%%/$tmp_hostname/" -i $pouncedir/users/$USER/disabled/$tmp_name
|
||||||
sed -e "s/%%CHANNELS%%/$tmp_channels/" -i $pouncedir/users/$USER/disabled/$tmp_name
|
sed -e "s/%%CHANNELS%%/$tmp_channels/" -i $pouncedir/users/$USER/disabled/$tmp_name
|
||||||
sed -e "s/%%USERNAME%%/$tmp_nickname/" -i $pouncedir/users/$USER/disabled/$tmp_name
|
sed -e "s/%%USERNAME%%/$tmp_nickname/" -i $pouncedir/users/$USER/disabled/$tmp_name
|
||||||
@ -208,26 +221,22 @@ while true; do
|
|||||||
esac
|
esac
|
||||||
case $selection in
|
case $selection in
|
||||||
1 )
|
1 )
|
||||||
#result=$(ls $pouncedir/users/$USER/enabled/)
|
|
||||||
#display_result "Enabled networks:"
|
|
||||||
get_networks "enabled"
|
get_networks "enabled"
|
||||||
if [ ! -z "$user_choice" ]; then
|
# if [ ! -z "$user_choice" ]; then
|
||||||
edit_network "enabled"
|
# edit_network "enabled"
|
||||||
if [ $exit_status = $DIALOG_EXTRA ]; then
|
# if [ $exit_status = $DIALOG_EXTRA ]; then
|
||||||
remove_network
|
# remove_network
|
||||||
fi
|
# fi
|
||||||
fi
|
# fi
|
||||||
;;
|
;;
|
||||||
2 )
|
2 )
|
||||||
#result=$(ls $pouncedir/users/$USER/disabled/)
|
|
||||||
#display_result "Disabled networks:"
|
|
||||||
get_networks "disabled"
|
get_networks "disabled"
|
||||||
if [ ! -z "$user_choice" ]; then
|
# if [ ! -z "$user_choice" ]; then
|
||||||
edit_network "disabled"
|
# edit_network "disabled"
|
||||||
if [ $exit_status = $DIALOG_EXTRA ]; then
|
# if [ $exit_status = $DIALOG_EXTRA ]; then
|
||||||
remove_network
|
# remove_network
|
||||||
fi
|
# fi
|
||||||
fi
|
# fi
|
||||||
;;
|
;;
|
||||||
3 )
|
3 )
|
||||||
add_network
|
add_network
|
||||||
|
Loading…
Reference in New Issue
Block a user