From a18e1921e733807c964973450751eff3ee3a16fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Wed, 3 Oct 2018 12:16:13 +0200 Subject: [PATCH] card-helpers.inc / selection-dialogs rework MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * do not rely on /tmp. BTW I tried the redirect of stderr thingy to get dialog selection into variable without temporary file but that did not work: dialogs were not displayed anymore. * cleanup menuitem to avoid confusion * SelectSuSudo stores selection in SuSudoSelection and does not open dialog in case SuSudoSelection is already set Signed-off-by: Andreas Müller --- scripts/include/card-helpers.inc | 42 +++++++++++++++++--------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/scripts/include/card-helpers.inc b/scripts/include/card-helpers.inc index cb13844..2538c3b 100644 --- a/scripts/include/card-helpers.inc +++ b/scripts/include/card-helpers.inc @@ -57,19 +57,20 @@ SelectCardDevice() { dialog --title 'Select card device'\ --menu 'Move using [UP] [DOWN],[Enter] to select' 10 100 $iCount\ "${menuitems[@]}"\ - 2>/tmp/menuitem.$$ + 2>"$base_tempdir/menuitem.$$" # get OK/Cancel sel=$? # get selected menuitem - menuitem=`cat /tmp/menuitem.$$` - rm -f /tmp/menuitem.$$ + menuitem=`cat "$base_tempdir/menuitem.$$"` + rm -f "$base_tempdir/menuitem.$$" # Cancel Button or if [ $sel -eq 1 -o $sel -eq 255 ] ; then ErrorOut 'Cancel selected at SelectCardDevice().' fi DevicePath=${DevicePathArr[$menuitem]} + unset menuitem fi } @@ -110,19 +111,20 @@ SelectDeployedFile() { dialog --title 'Select rootfs'\ --menu 'Move using [UP] [DOWN],[Enter] to select' 30 100 $iCount\ ${strSelection}\ - 2>/tmp/menuitem.$$ + 2>"$base_tempdir/menuitem.$$" # get OK/Cancel sel=$? # get selected menuitem - menuitem=`cat /tmp/menuitem.$$` - rm -f /tmp/menuitem.$$ + menuitem=`cat "$base_tempdir/menuitem.$$"` + rm -f "$base_tempdir/menuitem.$$" # Cancel Button or if [ $sel -eq 1 -o $sel -eq 255 ] ; then ErrorOut "Cancel selected at SelectDeployedFile()." fi DeployedFile=${RootFileNameArr[$menuitem]} + unset menuitem fi DeployFileDir=`dirname $DeployedFile` @@ -136,20 +138,22 @@ SelectDeployedFile() { # su -> 1 # sudo -> 2 SelectSuSudo() { - # Select su/sudo - dialog --title 'Select how you want to logon as root'\ - --menu 'Move using [UP] [DOWN],[Enter] to select' 10 100 2 1 su 2 sudo \ - 2>/tmp/menuitem.$$ + if [ -z "$SuSudoSelection" ]; then + # Select su/sudo + dialog --title 'Select how you want to logon as root'\ + --menu 'Move using [UP] [DOWN],[Enter] to select' 10 100 2 1 su 2 sudo \ + 2>"$base_tempdir/menuitem.$$" - # get OK/Cancel - sel=$? - # get selected menuitem - menuitem=`cat /tmp/menuitem.$$` - rm -f /tmp/menuitem.$$ + # get OK/Cancel + sel=$? + # get selected menuitem + SuSudoSelection=`cat "$base_tempdir/menuitem.$$"` + rm -f "$base_tempdir/menuitem.$$" - # Cancel Button or - if [ $sel -eq 1 -o $sel -eq 255 ] ; then - ErrorOut "Cancel selected at SelectSuSudo()." + # Cancel Button or + if [ $sel -eq 1 -o $sel -eq 255 ] ; then + ErrorOut "Cancel selected at SelectSuSudo()." + fi fi } @@ -222,7 +226,7 @@ RunUserStartRoot() { echo $1 | sed "s|\%DevicePath\%|$DevicePath|" fi - if [ $menuitem -eq 1 ]; then + if [ $SuSudoSelection -eq 1 ]; then echo -e "\nEnter valid root password if you are sure you want to continue" # Call this prog as root exec su -c "${0} $RootParams"