From c775f7198ba7032b6733b167e52172992d956dfa Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Fri, 20 Aug 2021 22:26:50 +1200 Subject: [PATCH] select-de.sh: process --select-de with arg spike --- builder/startup/deb/select-de.sh | 41 ++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/builder/startup/deb/select-de.sh b/builder/startup/deb/select-de.sh index 0b56805..4513e34 100755 --- a/builder/startup/deb/select-de.sh +++ b/builder/startup/deb/select-de.sh @@ -54,6 +54,15 @@ Usage: $(basename "$0") [options] USAGE } +add_uppercase_desktop_environment_keys() { + local de_cmd + + for de in "${!all_desktop_environments[@]}"; do + de_cmd=${all_desktop_environments[$de]}; + all_desktop_environments[${de^^}]="$de_cmd" + done +} + process_cli_options "$@" manual_xstartup_choice="Manually edit xstartup" @@ -69,6 +78,7 @@ readarray -t sorted_desktop_environments < <(for de in "${!all_desktop_environme all_desktop_environments[$manual_xstartup_choice]="" sorted_desktop_environments+=("$manual_xstartup_choice") +add_uppercase_desktop_environment_keys detected_desktop_environments=() declare -A numbered_desktop_environments @@ -185,20 +195,47 @@ user_specified_de() { check_de_name_is_valid() { local selected_de="$1" - local de_cmd=${all_desktop_environments["$selected_de"]:-} + local de_cmd=${all_desktop_environments["${selected_de^^}"]:-} if [ -z "$de_cmd" ]; then echo >&2 "'$selected_de': not supported Desktop Environment" return 1 fi } +de_installed() { + local de_name="${1^^}" + + for de in "${detected_desktop_environments[@]}"; do + if [ "${de^^}" = "$de_name" ]; then + return 0 + fi + done + + return 1 +} + +check_de_installed() { + local de_name="$1" + + if ! de_installed "$de_name"; then + echo >&2 "'$de_name': Desktop Environment not installed" + return 1 + fi +} + if user_asked_to_select_de || ! de_was_selected_on_previous_run; then if user_specified_de; then check_de_name_is_valid "$selected_de" fi detect_desktop_environments - ask_user_to_choose_de + if user_specified_de; then + check_de_installed "$selected_de" + # set DE as in ask_user_to_choose_de + else + ask_user_to_choose_de + fi + debug "You selected $de_name desktop environment" if [[ "$de_name" != "$manual_xstartup_choice" ]]; then setup_de_to_run_via_xstartup