Fix non-interactive mode for remote Transmission configuration

- Save all piped input to a temporary file for sequential processing
- Read remote mode selection from first line of input
- Use remaining lines for remote Transmission configuration details
- Add proper handling of defaults for empty or missing values
- Improve debug output for configuration parameters

This allows users to pipe all configuration values to the installer in a single command, without requiring interactive prompt responses.
This commit is contained in:
MasterDraco 2025-03-05 10:01:27 +00:00
parent 588ba1ea01
commit 40878c7d3a

View File

@ -1173,10 +1173,19 @@ 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 stdin is not a terminal (pipe or redirect), read from stdin
if [ ! -t 0 ]; then if [ ! -t 0 ]; then
input_remote=$(head -n 1) # Read first line from stdin # Save all input to a temporary file
INPUT_FILE=$(mktemp)
cat > "$INPUT_FILE"
# Read the first line as the remote selection
input_remote=$(awk 'NR==1{print}' "$INPUT_FILE")
echo "DEBUG: Non-interactive mode detected, read input: '$input_remote'" echo "DEBUG: Non-interactive mode detected, read input: '$input_remote'"
# Keep the rest of the input for later use
tail -n +2 "$INPUT_FILE" > "${INPUT_FILE}.rest"
mv "${INPUT_FILE}.rest" "$INPUT_FILE"
else 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 fi
@ -1194,14 +1203,29 @@ fi
if [ "$TRANSMISSION_REMOTE" = "true" ]; then if [ "$TRANSMISSION_REMOTE" = "true" ]; then
# Get remote transmission details # Get remote transmission details
if [ ! -t 0 ]; then if [ ! -t 0 ]; then
# Non-interactive mode - try to read from stdin with defaults # Non-interactive mode - we already have input saved to INPUT_FILE
TRANSMISSION_HOST=$(head -n 1 || echo "localhost") # from the previous step
TRANSMISSION_PORT=$(head -n 1 || echo "9091")
TRANSMISSION_USER=$(head -n 1 || echo "") # Read each line from the input file
TRANSMISSION_PASS=$(head -n 1 || echo "") TRANSMISSION_HOST=$(awk 'NR==1{print}' "$INPUT_FILE")
TRANSMISSION_RPC_PATH=$(head -n 1 || echo "/transmission/rpc") TRANSMISSION_PORT=$(awk 'NR==2{print}' "$INPUT_FILE")
REMOTE_DOWNLOAD_DIR=$(head -n 1 || echo "/var/lib/transmission-daemon/downloads") TRANSMISSION_USER=$(awk 'NR==3{print}' "$INPUT_FILE")
LOCAL_DOWNLOAD_DIR=$(head -n 1 || echo "/mnt/transmission-downloads") TRANSMISSION_PASS=$(awk 'NR==4{print}' "$INPUT_FILE")
TRANSMISSION_RPC_PATH=$(awk 'NR==5{print}' "$INPUT_FILE")
REMOTE_DOWNLOAD_DIR=$(awk 'NR==6{print}' "$INPUT_FILE")
LOCAL_DOWNLOAD_DIR=$(awk 'NR==7{print}' "$INPUT_FILE")
# Use defaults for empty values
TRANSMISSION_HOST=${TRANSMISSION_HOST:-"localhost"}
TRANSMISSION_PORT=${TRANSMISSION_PORT:-"9091"}
TRANSMISSION_USER=${TRANSMISSION_USER:-""}
TRANSMISSION_PASS=${TRANSMISSION_PASS:-""}
TRANSMISSION_RPC_PATH=${TRANSMISSION_RPC_PATH:-"/transmission/rpc"}
REMOTE_DOWNLOAD_DIR=${REMOTE_DOWNLOAD_DIR:-"/var/lib/transmission-daemon/downloads"}
LOCAL_DOWNLOAD_DIR=${LOCAL_DOWNLOAD_DIR:-"/mnt/transmission-downloads"}
# Clean up
rm -f "$INPUT_FILE"
echo "DEBUG: Non-interactive mode with remote details:" echo "DEBUG: Non-interactive mode with remote details:"
echo "DEBUG: Host: $TRANSMISSION_HOST, Port: $TRANSMISSION_PORT" echo "DEBUG: Host: $TRANSMISSION_HOST, Port: $TRANSMISSION_PORT"
echo "DEBUG: Remote dir: $REMOTE_DOWNLOAD_DIR, Local dir: $LOCAL_DOWNLOAD_DIR" echo "DEBUG: Remote dir: $REMOTE_DOWNLOAD_DIR, Local dir: $LOCAL_DOWNLOAD_DIR"