vhost-manager/share/bin/form_input

51 lines
748 B
Plaintext
Raw Normal View History

2019-07-30 23:34:41 +02:00
#!/bin/sh
TITLE=
LABEL=
DEFAULT=
REQUIRED=0
ERROR=0
HEIGHT=8
WIDTH=50
while getopts "t:l:d:h:w:r" option; do
case "$option" in
t) TITLE="$OPTARG";;
l) LABEL="$OPTARG";;
d) DEFAULT="$OPTARG";;
h) HEIGHT="$OPTARG";;
w) WIDTH="$OPTARG";;
r) REQUIRED=1;;
:) 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 "%s" "$DEFAULT"
else
VALUE=
DO_ASK=1
2019-07-30 23:34:41 +02:00
2021-02-21 16:17:45 +01:00
while [ $DO_ASK -eq 1 ]; do
VALUE="$(whiptail --title "$TITLE" --inputbox "$LABEL" $HEIGHT $WIDTH "$DEFAULT" 3>&1 1>&2 2>&3)"
STATUS=$?
2019-07-30 23:34:41 +02:00
2021-02-21 16:17:45 +01:00
if [ $STATUS -eq 0 ]; then
if [ $REQUIRED -eq 1 ] && [ -z "$VALUE" ]; then
DO_ASK=1
else
DO_ASK=0
fi
2019-07-30 23:34:41 +02:00
else
2021-02-21 16:17:45 +01:00
exit $STATUS
2019-07-30 23:34:41 +02:00
fi
2021-02-21 16:17:45 +01:00
done
2019-07-30 23:34:41 +02:00
2021-02-21 16:17:45 +01:00
printf "%s" "$VALUE"
fi