vhost-manager/share/bin/form_yes_no

46 lines
721 B
Plaintext
Raw Normal View History

2019-07-30 23:34:41 +02:00
#!/bin/sh
TITLE=
LABEL=
ERROR=0
HEIGHT=8
WIDTH=50
PARAMS=
2021-02-21 16:17:45 +01:00
DEFAULT=
2019-07-30 23:34:41 +02:00
while getopts "t:l:d:h:w:rn" option; do
2019-07-30 23:34:41 +02:00
case "$option" in
l) LABEL="$OPTARG";;
t) TITLE="$OPTARG";;
h) HEIGHT="$OPTARG";;
w) WIDTH="$OPTARG";;
n) PARAMS="$PARAMS --defaultno";;
2021-02-21 16:17:45 +01:00
d)
if [ -n "$OPTARG" ]; then
if [ "$OPTARG" = "no" ]; then
PARAMS="$PARAMS --defaultno"
DEFAULT="no"
elif [ "$OPTARG" = "yes" ]; then
DEFAULT="yes"
fi
fi
;;
2019-07-30 23:34:41 +02:00
:) ERROR=1;;
?) ERROR=1;;
esac
done
if [ $ERROR -eq 1 ]; then
exit 1
fi
2021-02-21 16:17:45 +01:00
if [ $INTERACTIVE -eq 0 ]; then
printf "$DEFAULT"
2019-07-30 23:34:41 +02:00
else
2021-02-21 16:17:45 +01:00
if (whiptail --title "$TITLE" --yesno "$LABEL" $PARAMS $HEIGHT $WIDTH 3>&1 1>&2 2>&3) then
printf "yes"
else
printf "no"
fi
2019-07-30 23:34:41 +02:00
fi