From b1178c2bc87febd140add14b5324ffd4c44effd1 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 2 Feb 2016 13:57:16 +0000 Subject: [PATCH] Improved user selection dialog during install --- src/freedombone-config | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/freedombone-config b/src/freedombone-config index d2ab8336..daa9c2a2 100755 --- a/src/freedombone-config +++ b/src/freedombone-config @@ -598,6 +598,34 @@ function interactive_select_language { update-locale LC_CTYPE=${DEFAULT_LANGUAGE} } +function select_user { + SELECTED_USERNAME= + + users_array=($(ls /home)) + + delete=(mirrors git) + for del in ${delete[@]} + do + users_array=(${users_array[@]/$del}) + done + + i=0 + W=() + name=() + for u in ${users_array[@]} + do + i=$((i+1)) + W+=($i "$u") + name+=("$u") + done + + user_index=$(dialog --backtitle $"Freedombone Configuration" --title $"Select User" --menu $"Select one of the following:" 24 40 17 "${W[@]}" 3>&2 2>&1 1>&3) + + if [ $? -eq 0 ]; then + SELECTED_USERNAME="${name[$((user_index-1))]}" + fi +} + function interactive_configuration { # create a temporary copy of the configuration file # which can be used to pre-populate selections @@ -832,17 +860,8 @@ function interactive_configuration { if [[ $SYSTEM_TYPE == "$VARIANT_MESH" && $DEFAULT_DOMAIN_NAME && -d /home/$DEFAULT_DOMAIN_NAME ]]; then MY_USERNAME=$DEFAULT_DOMAIN_NAME else - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 - dialog --title $"Select the user account to install as" \ - --backtitle $"Freedombone Configuration" \ - --dselect "/home/$(grep 'MY_USERNAME' temp.cfg | awk -F '=' '{print $2}')" 14 40 2> $data - sel=$? - case $sel in - 0) MY_USERNAME=$(cat $data | awk -F '/' '{print $3}');; - 1) exit 1;; - 255) exit 1;; - esac + select_user + MY_USERNAME=$SELECTED_USERNAME fi fi fi