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:
parent
4e4fd09811
commit
a3924912f1
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user