mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-30 20:43:02 +02:00
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:
@@ -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..
|
||||
|
||||
|
||||
Executable
+55
@@ -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
|
||||
Reference in New Issue
Block a user