From a3924912f1c81d97f662f19e92645a0a17548fbf Mon Sep 17 00:00:00 2001 From: MasterDraco Date: Wed, 5 Mar 2025 09:59:41 +0000 Subject: [PATCH] Improve handling of non-interactive and piped input - Add detection for non-interactive terminal (piped input) - Properly read input from pipe in install-script.sh - Use pre-set environment variables when available - Add better fallbacks for script usage - Fix syntax error in main installer script - More detailed logging of input handling process This ensures the installer can be used both interactively and in scripts/automated setups. --- install-script.sh | 8 ++++++- main-installer.sh | 59 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/install-script.sh b/install-script.sh index f286254..f1d152f 100755 --- a/install-script.sh +++ b/install-script.sh @@ -1173,7 +1173,13 @@ echo -e "${BOLD}Transmission Configuration:${NC}" echo -e "Configure connection to your Transmission client:" echo -read -p "Is Transmission running on a remote server? (y/n) [n]: " input_remote +# If stdin is not a terminal (pipe or redirect), assume default +if [ ! -t 0 ]; then + input_remote=$(head -n 1) # Read first line from stdin + echo "DEBUG: Non-interactive mode detected, read input: '$input_remote'" +else + read -p "Is Transmission running on a remote server? (y/n) [n]: " input_remote +fi echo "DEBUG: Input received for remote in install-script.sh: '$input_remote'" # Explicitly check for "y" or "Y" response if [ "$input_remote" = "y" ] || [ "$input_remote" = "Y" ]; then diff --git a/main-installer.sh b/main-installer.sh index edcc938..1346886 100755 --- a/main-installer.sh +++ b/main-installer.sh @@ -113,15 +113,28 @@ export USER=${USER:-$(logname || echo $SUDO_USER)} if [ "$IS_UPDATE" = true ]; then log "INFO" "Running in update mode - preserving existing configuration..." - # First, let's directly ask about Transmission - # This is a direct approach that bypasses any potential sourcing issues - log "INFO" "Configuring Transmission connection..." - echo -e "${BOLD}Transmission Configuration:${NC}" - echo -e "Configure connection to your Transmission client:" - echo + # First, let's check if we already have this value from the environment + # This allows for non-interactive usage in scripts + if [ -n "$TRANSMISSION_REMOTE" ]; then + log "INFO" "Using Transmission mode from environment: $([ "$TRANSMISSION_REMOTE" = true ] && echo "Remote" || echo "Local")" + else + # Directly ask about Transmission + # This is a direct approach that bypasses any potential sourcing issues + log "INFO" "Configuring Transmission connection..." + echo -e "${BOLD}Transmission Configuration:${NC}" + echo -e "Configure connection to your Transmission client:" + echo + + # If stdin is not a terminal (pipe or redirect), assume default + if [ ! -t 0 ]; then + input_remote="n" # Default to no + log "INFO" "Non-interactive mode detected, using default: local Transmission" + else + read -p "Is Transmission running on a remote server? (y/n) [n]: " input_remote + fi + log "INFO" "DEBUG: Input received for remote: '$input_remote'" + fi - read -p "Is Transmission running on a remote server? (y/n) [n]: " input_remote - log "INFO" "DEBUG: Input received for remote: '$input_remote'" # More explicit check for "y" or "Y" input if [ "$input_remote" = "y" ] || [ "$input_remote" = "Y" ]; then export TRANSMISSION_REMOTE=true @@ -253,15 +266,27 @@ EOF else # This is a fresh installation - run all steps - # Step 1: First, let's directly ask about Transmission - # This is a direct approach that bypasses any potential sourcing issues - log "INFO" "Configuring Transmission connection..." - echo -e "${BOLD}Transmission Configuration:${NC}" - echo -e "Configure connection to your Transmission client:" - echo - - read -p "Is Transmission running on a remote server? (y/n) [n]: " input_remote - log "INFO" "DEBUG: Input received for remote: '$input_remote'" + # Step 1: First, let's check if we already have this value from the environment + # This allows for non-interactive usage in scripts + if [ -n "$TRANSMISSION_REMOTE" ]; then + log "INFO" "Using Transmission mode from environment: $([ "$TRANSMISSION_REMOTE" = true ] && echo "Remote" || echo "Local")" + else + # Directly ask about Transmission + # This is a direct approach that bypasses any potential sourcing issues + log "INFO" "Configuring Transmission connection..." + echo -e "${BOLD}Transmission Configuration:${NC}" + echo -e "Configure connection to your Transmission client:" + echo + + # If stdin is not a terminal (pipe or redirect), assume default + if [ ! -t 0 ]; then + input_remote="n" # Default to no + log "INFO" "Non-interactive mode detected, using default: local Transmission" + else + read -p "Is Transmission running on a remote server? (y/n) [n]: " input_remote + fi + log "INFO" "DEBUG: Input received for remote: '$input_remote'" + fi # More explicit check for "y" or "Y" input if [ "$input_remote" = "y" ] || [ "$input_remote" = "Y" ]; then export TRANSMISSION_REMOTE=true