diff --git a/lib/ui_remotes.sh b/lib/ui_remotes.sh index a8fa5dd..5996dfa 100644 --- a/lib/ui_remotes.sh +++ b/lib/ui_remotes.sh @@ -98,6 +98,24 @@ _ui_remote_add_ssh() { local bwlimit; bwlimit=$(ui_inputbox "SSH Remote" "Bandwidth limit (KB/s, 0=unlimited):" "$DEFAULT_BWLIMIT") || bwlimit="$DEFAULT_BWLIMIT" local retention; retention=$(ui_inputbox "SSH Remote" "Retention count:" "$DEFAULT_RETENTION_COUNT") || retention="$DEFAULT_RETENTION_COUNT" + # Test connection before saving + if ui_yesno "Test connection to ${user}@${host}:${port} before saving?"; then + local test_result + local -a ssh_cmd=(ssh -o BatchMode=yes -o ConnectTimeout=10 -p "$port") + if [[ "$auth_method" == "key" && -n "$key" ]]; then + ssh_cmd+=(-i "$key") + fi + ssh_cmd+=("${user}@${host}" "echo OK") + if test_result=$("${ssh_cmd[@]}" 2>&1); then + ui_msgbox "Connection successful!" + else + ui_msgbox "Connection failed:\n\n$test_result" + if ! ui_yesno "Save remote anyway?"; then + return 0 + fi + fi + fi + cat > "$conf" < "$conf" </dev/null && ui_yesno "Test S3 connection before saving?"; then + # Set globals temporarily for test_rclone_connection + REMOTE_TYPE="s3" S3_BUCKET="$bucket" S3_REGION="$region" \ + S3_ENDPOINT="$endpoint" S3_ACCESS_KEY_ID="$access_key" \ + S3_SECRET_ACCESS_KEY="$secret_key" REMOTE_BASE="$base" + local test_result + if test_result=$(test_rclone_connection 2>&1); then + ui_msgbox "S3 connection successful!" + else + ui_msgbox "S3 connection failed:\n\n$test_result" + if ! ui_yesno "Save remote anyway?"; then + return 0 + fi + fi + fi + cat > "$conf" </dev/null && ui_yesno "Test Google Drive connection before saving?"; then + REMOTE_TYPE="gdrive" GDRIVE_SERVICE_ACCOUNT_FILE="$sa_file" \ + GDRIVE_ROOT_FOLDER_ID="$folder_id" REMOTE_BASE="$base" + local test_result + if test_result=$(test_rclone_connection 2>&1); then + ui_msgbox "Google Drive connection successful!" + else + ui_msgbox "Google Drive connection failed:\n\n$test_result" + if ! ui_yesno "Save remote anyway?"; then + return 0 + fi + fi + fi + cat > "$conf" <