From a5afa1bb8016d1186afb2b786d434d2679c11268 Mon Sep 17 00:00:00 2001 From: MasterDraco Date: Wed, 5 Mar 2025 10:02:23 +0000 Subject: [PATCH] Improve environment variable handling in main installer - Add logic to set input_remote based on TRANSMISSION_REMOTE from environment - Add detailed debug logging for environment variables - Ensure consistent behavior between direct mode and piped input - Fix issue where environment variables weren't correctly propagating This ensures that when remote mode is selected in install-script.sh, it's correctly respected in the main installer even when running in update mode. --- main-installer.sh | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/main-installer.sh b/main-installer.sh index 8d41128..6fbca46 100755 --- a/main-installer.sh +++ b/main-installer.sh @@ -116,7 +116,16 @@ if [ "$IS_UPDATE" = true ]; then # 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")" + is_remote=$([ "$TRANSMISSION_REMOTE" = true ] && echo "Remote" || echo "Local") + log "INFO" "Using Transmission mode from environment: $is_remote" + + # Set the input_remote variable based on the environment variable + # This ensures consistent behavior with the rest of the script + if [ "$TRANSMISSION_REMOTE" = true ]; then + input_remote="y" + else + input_remote="n" + fi else # Directly ask about Transmission # This is a direct approach that bypasses any potential sourcing issues @@ -144,6 +153,13 @@ if [ "$IS_UPDATE" = true ]; then if [ -f "$CONFIG_DIR/config.json" ]; then log "INFO" "Updating configuration file for remote Transmission..." + # Log all environment variables we have for debugging + log "INFO" "DEBUG: Environment variables for remote configuration:" + log "INFO" "DEBUG: TRANSMISSION_HOST=${TRANSMISSION_HOST:-'not set'}" + log "INFO" "DEBUG: TRANSMISSION_PORT=${TRANSMISSION_PORT:-'not set'}" + log "INFO" "DEBUG: REMOTE_DOWNLOAD_DIR=${REMOTE_DOWNLOAD_DIR:-'not set'}" + log "INFO" "DEBUG: LOCAL_DOWNLOAD_DIR=${LOCAL_DOWNLOAD_DIR:-'not set'}" + # Check if we already have the remote configuration details from the environment if [ -n "$TRANSMISSION_HOST" ] && [ -n "$TRANSMISSION_PORT" ] && [ -n "$REMOTE_DOWNLOAD_DIR" ] && [ -n "$LOCAL_DOWNLOAD_DIR" ]; then log "INFO" "Using remote Transmission configuration from environment" @@ -276,7 +292,16 @@ else # 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")" + is_remote=$([ "$TRANSMISSION_REMOTE" = true ] && echo "Remote" || echo "Local") + log "INFO" "Using Transmission mode from environment: $is_remote" + + # Set the input_remote variable based on the environment variable + # This ensures consistent behavior with the rest of the script + if [ "$TRANSMISSION_REMOTE" = true ]; then + input_remote="y" + else + input_remote="n" + fi else # Directly ask about Transmission # This is a direct approach that bypasses any potential sourcing issues