diff --git a/ultroid_setup.sh b/ultroid_setup.sh index 09b18e1..2dc07c7 100644 --- a/ultroid_setup.sh +++ b/ultroid_setup.sh @@ -77,36 +77,17 @@ _prompt_user() { local prompt_message="$1" local var_name="$2" local default_value="${3:-}" - local current_value="${!var_name:-$default_value}" # Not used currently, but good for reference local input - local read_target_set_internally=false - # Check if stdin (fd 0) is a terminal - if ! [ -t 0 ]; then - # If stdin is not a terminal, check if /dev/tty is available - if [ -c /dev/tty ]; then - read_target_set_internally=true - else - _print_msg error "Cannot read user input: No TTY available. stdin is not a terminal and /dev/tty is not accessible." - # Exiting because user input is critical for this script. - # Alternatively, could return an error code: return 1 - exit 1 - fi + # Echo the prompt using color codes + if [ -n "$default_value" ]; then + echo -e -n "${YELLOW}${prompt_message}${NC} [Default: $default_value]: " + else + echo -e -n "${YELLOW}${prompt_message}${NC}: " fi - if [ -n "$default_value" ]; then - if $read_target_set_internally; then - read -p "$(echo -e "${YELLOW}$prompt_message${NC} [Default: $default_value]: ")" input < /dev/tty - else - read -p "$(echo -e "${YELLOW}$prompt_message${NC} [Default: $default_value]: ")" input - fi - else - if $read_target_set_internally; then - read -p "$(echo -e "${YELLOW}$prompt_message${NC}: ")" input < /dev/tty - else - read -p "$(echo -e "${YELLOW}$prompt_message${NC}: ")" input - fi - fi + # Read the input + read input if [ -z "$input" ] && [ -n "$default_value" ]; then eval "$var_name=\"$default_value\"" @@ -120,26 +101,13 @@ _prompt_user_sensitive() { local var_name="$2" local input - local read_target_set_internally=false - # Check if stdin (fd 0) is a terminal - if ! [ -t 0 ]; then - # If stdin is not a terminal, check if /dev/tty is available - if [ -c /dev/tty ]; then - read_target_set_internally=true - else - _print_msg error "Cannot read sensitive user input: No TTY available. stdin is not a terminal and /dev/tty is not accessible." - # Exiting because user input is critical for this script. - # Alternatively, could return an error code: return 1 - exit 1 - fi - fi + # Echo the prompt using color codes + echo -e -n "${YELLOW}${prompt_message}${NC}: " - if $read_target_set_internally; then - read -sp "$(echo -e "${YELLOW}$prompt_message${NC}: ")" input < /dev/tty - else - read -sp "$(echo -e "${YELLOW}$prompt_message${NC}: ")" input - fi + # Read the input silently + read -s input echo # Newline after sensitive input + eval "$var_name=\"$input\"" }