setup: add support for performing factory reset

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>
This commit is contained in:
Joachim Wiberg
2023-02-21 22:28:42 +01:00
parent 9af4155a83
commit 6cf4a986f5
2 changed files with 56 additions and 0 deletions
+1
View File
@@ -61,6 +61,7 @@ menu:system:System:System Settings
exec:_Disable service:edit:initctl disable ~Enter name of service (filename) to disable:~
nop
exec:_Change Operating Mode::chom
exec:_Factory Reset::yorn "Reboot and factory reset device, are you sure?" factory -y
nop
exit:_Main menu..
+55
View File
@@ -0,0 +1,55 @@
#!/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