diff --git a/install-script.sh b/install-script.sh index f1d152f..4862e2c 100755 --- a/install-script.sh +++ b/install-script.sh @@ -1190,8 +1190,69 @@ else echo -e "${GREEN}Local Transmission selected.${NC}" fi -# Create a direct environment file for the main installer -echo "export TRANSMISSION_REMOTE=$TRANSMISSION_REMOTE" > "${SCRIPT_DIR}/.env.install" +# If remote mode is selected, collect remote details here and pass to main installer +if [ "$TRANSMISSION_REMOTE" = "true" ]; then + # Get remote transmission details + if [ ! -t 0 ]; then + # Non-interactive mode - try to read from stdin with defaults + TRANSMISSION_HOST=$(head -n 1 || echo "localhost") + TRANSMISSION_PORT=$(head -n 1 || echo "9091") + TRANSMISSION_USER=$(head -n 1 || echo "") + TRANSMISSION_PASS=$(head -n 1 || echo "") + TRANSMISSION_RPC_PATH=$(head -n 1 || echo "/transmission/rpc") + REMOTE_DOWNLOAD_DIR=$(head -n 1 || echo "/var/lib/transmission-daemon/downloads") + LOCAL_DOWNLOAD_DIR=$(head -n 1 || echo "/mnt/transmission-downloads") + echo "DEBUG: Non-interactive mode with remote details:" + echo "DEBUG: Host: $TRANSMISSION_HOST, Port: $TRANSMISSION_PORT" + echo "DEBUG: Remote dir: $REMOTE_DOWNLOAD_DIR, Local dir: $LOCAL_DOWNLOAD_DIR" + else + # Interactive mode - ask for details + read -p "Remote Transmission host [localhost]: " TRANSMISSION_HOST + TRANSMISSION_HOST=${TRANSMISSION_HOST:-"localhost"} + + read -p "Remote Transmission port [9091]: " TRANSMISSION_PORT + TRANSMISSION_PORT=${TRANSMISSION_PORT:-"9091"} + + read -p "Remote Transmission username []: " TRANSMISSION_USER + TRANSMISSION_USER=${TRANSMISSION_USER:-""} + + read -s -p "Remote Transmission password []: " TRANSMISSION_PASS + echo # Add a newline after password input + TRANSMISSION_PASS=${TRANSMISSION_PASS:-""} + + read -p "Remote Transmission RPC path [/transmission/rpc]: " TRANSMISSION_RPC_PATH + TRANSMISSION_RPC_PATH=${TRANSMISSION_RPC_PATH:-"/transmission/rpc"} + + # Configure directory mapping for remote setup + echo + echo -e "${YELLOW}Directory Mapping Configuration${NC}" + echo -e "When using a remote Transmission server, you need to map paths between servers." + echo -e "For each directory on the remote server, specify the corresponding local directory." + echo + + read -p "Remote Transmission download directory [/var/lib/transmission-daemon/downloads]: " REMOTE_DOWNLOAD_DIR + REMOTE_DOWNLOAD_DIR=${REMOTE_DOWNLOAD_DIR:-"/var/lib/transmission-daemon/downloads"} + + read -p "Local directory that corresponds to the remote download directory [/mnt/transmission-downloads]: " LOCAL_DOWNLOAD_DIR + LOCAL_DOWNLOAD_DIR=${LOCAL_DOWNLOAD_DIR:-"/mnt/transmission-downloads"} + fi + + # Create the environment file with all remote details + cat > "${SCRIPT_DIR}/.env.install" << EOF +export TRANSMISSION_REMOTE=$TRANSMISSION_REMOTE +export TRANSMISSION_HOST="$TRANSMISSION_HOST" +export TRANSMISSION_PORT="$TRANSMISSION_PORT" +export TRANSMISSION_USER="$TRANSMISSION_USER" +export TRANSMISSION_PASS="$TRANSMISSION_PASS" +export TRANSMISSION_RPC_PATH="$TRANSMISSION_RPC_PATH" +export REMOTE_DOWNLOAD_DIR="$REMOTE_DOWNLOAD_DIR" +export LOCAL_DOWNLOAD_DIR="$LOCAL_DOWNLOAD_DIR" +EOF +else + # Local mode - simpler environment file + echo "export TRANSMISSION_REMOTE=$TRANSMISSION_REMOTE" > "${SCRIPT_DIR}/.env.install" +fi + chmod +x "${SCRIPT_DIR}/.env.install" # Ensure the environment file is world-readable to avoid permission issues diff --git a/main-installer.sh b/main-installer.sh index 1346886..8d41128 100755 --- a/main-installer.sh +++ b/main-installer.sh @@ -143,40 +143,47 @@ if [ "$IS_UPDATE" = true ]; then # Update the config file directly to set remote mode if [ -f "$CONFIG_DIR/config.json" ]; then log "INFO" "Updating configuration file for remote Transmission..." - # Get and validate hostname - read -p "Remote Transmission host [localhost]: " input_trans_host - TRANSMISSION_HOST=${input_trans_host:-"localhost"} - # Get and validate port - read -p "Remote Transmission port [9091]: " input_trans_port - TRANSMISSION_PORT=${input_trans_port:-9091} - - # Get credentials - read -p "Remote Transmission username []: " input_trans_user - TRANSMISSION_USER=${input_trans_user:-""} - - # Use read -s for password to avoid showing it on screen - read -s -p "Remote Transmission password []: " input_trans_pass - echo # Add a newline after the password input - TRANSMISSION_PASS=${input_trans_pass:-""} - - read -p "Remote Transmission RPC path [/transmission/rpc]: " input_trans_path - TRANSMISSION_RPC_PATH=${input_trans_path:-"/transmission/rpc"} - - # Configure directory mapping for remote setup - echo - echo -e "${YELLOW}Directory Mapping Configuration${NC}" - echo -e "When using a remote Transmission server, you need to map paths between servers." - echo -e "For each directory on the remote server, specify the corresponding local directory." - echo - - # Get remote download directory - read -p "Remote Transmission download directory [/var/lib/transmission-daemon/downloads]: " REMOTE_DOWNLOAD_DIR - REMOTE_DOWNLOAD_DIR=${REMOTE_DOWNLOAD_DIR:-"/var/lib/transmission-daemon/downloads"} - - # Get local directory that corresponds to remote download directory - read -p "Local directory that corresponds to the remote download directory [/mnt/transmission-downloads]: " LOCAL_DOWNLOAD_DIR - LOCAL_DOWNLOAD_DIR=${LOCAL_DOWNLOAD_DIR:-"/mnt/transmission-downloads"} + # 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" + # Values are already set from the environment, no need to ask again + else + # Get and validate hostname + read -p "Remote Transmission host [localhost]: " input_trans_host + TRANSMISSION_HOST=${input_trans_host:-"localhost"} + + # Get and validate port + read -p "Remote Transmission port [9091]: " input_trans_port + TRANSMISSION_PORT=${input_trans_port:-9091} + + # Get credentials + read -p "Remote Transmission username []: " input_trans_user + TRANSMISSION_USER=${input_trans_user:-""} + + # Use read -s for password to avoid showing it on screen + read -s -p "Remote Transmission password []: " input_trans_pass + echo # Add a newline after the password input + TRANSMISSION_PASS=${input_trans_pass:-""} + + read -p "Remote Transmission RPC path [/transmission/rpc]: " input_trans_path + TRANSMISSION_RPC_PATH=${input_trans_path:-"/transmission/rpc"} + + # Configure directory mapping for remote setup + echo + echo -e "${YELLOW}Directory Mapping Configuration${NC}" + echo -e "When using a remote Transmission server, you need to map paths between servers." + echo -e "For each directory on the remote server, specify the corresponding local directory." + echo + + # Get remote download directory + read -p "Remote Transmission download directory [/var/lib/transmission-daemon/downloads]: " REMOTE_DOWNLOAD_DIR + REMOTE_DOWNLOAD_DIR=${REMOTE_DOWNLOAD_DIR:-"/var/lib/transmission-daemon/downloads"} + + # Get local directory that corresponds to remote download directory + read -p "Local directory that corresponds to the remote download directory [/mnt/transmission-downloads]: " LOCAL_DOWNLOAD_DIR + LOCAL_DOWNLOAD_DIR=${LOCAL_DOWNLOAD_DIR:-"/mnt/transmission-downloads"} + fi # Create mapping JSON TRANSMISSION_DIR_MAPPING=$(cat <