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.
This commit is contained in:
MasterDraco 2025-03-05 09:59:41 +00:00
parent 4e4fd09811
commit a3924912f1
2 changed files with 49 additions and 18 deletions

View File

@ -1173,7 +1173,13 @@ echo -e "${BOLD}Transmission Configuration:${NC}"
echo -e "Configure connection to your Transmission client:" echo -e "Configure connection to your Transmission client:"
echo 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'" echo "DEBUG: Input received for remote in install-script.sh: '$input_remote'"
# Explicitly check for "y" or "Y" response # Explicitly check for "y" or "Y" response
if [ "$input_remote" = "y" ] || [ "$input_remote" = "Y" ]; then if [ "$input_remote" = "y" ] || [ "$input_remote" = "Y" ]; then

View File

@ -113,15 +113,28 @@ export USER=${USER:-$(logname || echo $SUDO_USER)}
if [ "$IS_UPDATE" = true ]; then if [ "$IS_UPDATE" = true ]; then
log "INFO" "Running in update mode - preserving existing configuration..." log "INFO" "Running in update mode - preserving existing configuration..."
# First, let's directly ask about Transmission # 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 # This is a direct approach that bypasses any potential sourcing issues
log "INFO" "Configuring Transmission connection..." log "INFO" "Configuring Transmission connection..."
echo -e "${BOLD}Transmission Configuration:${NC}" echo -e "${BOLD}Transmission Configuration:${NC}"
echo -e "Configure connection to your Transmission client:" echo -e "Configure connection to your Transmission client:"
echo 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 read -p "Is Transmission running on a remote server? (y/n) [n]: " input_remote
fi
log "INFO" "DEBUG: Input received for remote: '$input_remote'" log "INFO" "DEBUG: Input received for remote: '$input_remote'"
fi
# More explicit check for "y" or "Y" input # More explicit check for "y" or "Y" input
if [ "$input_remote" = "y" ] || [ "$input_remote" = "Y" ]; then if [ "$input_remote" = "y" ] || [ "$input_remote" = "Y" ]; then
export TRANSMISSION_REMOTE=true export TRANSMISSION_REMOTE=true
@ -253,15 +266,27 @@ EOF
else else
# This is a fresh installation - run all steps # This is a fresh installation - run all steps
# Step 1: First, let's directly ask about Transmission # 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 # This is a direct approach that bypasses any potential sourcing issues
log "INFO" "Configuring Transmission connection..." log "INFO" "Configuring Transmission connection..."
echo -e "${BOLD}Transmission Configuration:${NC}" echo -e "${BOLD}Transmission Configuration:${NC}"
echo -e "Configure connection to your Transmission client:" echo -e "Configure connection to your Transmission client:"
echo 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 read -p "Is Transmission running on a remote server? (y/n) [n]: " input_remote
fi
log "INFO" "DEBUG: Input received for remote: '$input_remote'" log "INFO" "DEBUG: Input received for remote: '$input_remote'"
fi
# More explicit check for "y" or "Y" input # More explicit check for "y" or "Y" input
if [ "$input_remote" = "y" ] || [ "$input_remote" = "Y" ]; then if [ "$input_remote" = "y" ] || [ "$input_remote" = "Y" ]; then
export TRANSMISSION_REMOTE=true export TRANSMISSION_REMOTE=true