mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-03 06:13:02 +02:00
Now that we have dialog on target we can add a user-friendly factory reset dialog. The new `yorn` script handles any form of yes-or-no question, with or without dialog, to call a command. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
56 lines
760 B
Bash
Executable File
56 lines
760 B
Bash
Executable File
#!/bin/sh
|
|
#set -x
|
|
|
|
usage()
|
|
{
|
|
cat <<EOF
|
|
usage:
|
|
yorn [-h] ["Do you want to run command?" command]
|
|
|
|
options:
|
|
-h Show this help text
|
|
-p Show plain output, no bells or whistles
|
|
|
|
Displays the yes-or-no question and runs command on yes.
|
|
EOF
|
|
}
|
|
|
|
if [ -z "$1" ]; then
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
case $1 in
|
|
-h)
|
|
usage
|
|
exit 0
|
|
;;
|
|
-p)
|
|
plain=1
|
|
shift
|
|
;;
|
|
*)
|
|
;;
|
|
esac
|
|
|
|
question=$1
|
|
shift
|
|
command=$*
|
|
if [ -z "$command" ]; then
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "$plain" ]; then
|
|
if dialog --erase-on-exit --colors --defaultno --yesno "\Zb$question\ZB" 0 0; then
|
|
yorn=y
|
|
fi
|
|
else
|
|
# shellcheck disable=SC2162,SC3045
|
|
read -n 1 -p "$question (y/N): " yorn
|
|
fi
|
|
|
|
if [ "$yorn" = "y" ] || [ "$yorn" = "Y" ]; then
|
|
$command
|
|
fi
|