From 95e937b9643eb49e0e267fa0d20a2dbd4f9341f7 Mon Sep 17 00:00:00 2001 From: zaphod-black Date: Sat, 1 Nov 2025 23:10:03 -0500 Subject: [PATCH] Feature: Automatic authentication test for all targets at startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added automatic connection testing when the script starts up. All configured backup targets are now tested immediately, giving users instant feedback about which targets are accessible. NEW FUNCTIONS: - quick_test_target() (lines 127-145) - Lightweight auth test for a single target - 5 second timeout for quick feedback - Runs in subshell to avoid polluting environment - Returns 0 on success, 1 on failure - test_all_targets() (lines 148-176) - Tests all configured targets - Displays formatted status for each: - "✓ Connected" - Authentication successful - "✗ Failed" - Cannot authenticate - Shows warning if any targets fail - Suggests using "Edit target" option to fix issues INTEGRATION: - Called automatically after show_targets_list() at startup - Only runs if targets exist - Minimal performance impact (5s max per target) - Non-blocking - script continues regardless of results USER EXPERIENCE: Before: User had to manually test each target or discover issues when backups fail After: Immediate visual feedback on all target statuses at startup Example output: ════════════════════════════════════════ Testing Backup Target Connections ════════════════════════════════════════ default: ✗ Failed offsite: ✓ Connected [WARN] Some targets failed connection test [INFO] Use option 3 (Edit target) to fix connection issues 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- CHANGELOG.md | 9 +++++++ pbs-client-installer.sh | 53 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index da06ec6..38886fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -119,6 +119,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Manual backups always include block device even on non-Sunday - Script version bumped to 1.1.0 for multi-target support +### Added +- **Automatic connection testing at startup** + - All configured targets are automatically tested when script starts + - Quick authentication check (5 second timeout per target) + - Shows connection status: ✓ Connected or ✗ Failed + - Helps identify configuration issues before running backups + - Warns user if any targets have connection problems + - Runs in subshell to avoid environment pollution + ### Changed - **Improved menu flow for viewing target details** - "View target details" moved from main menu option 6 to sub-menu under "List all backup targets" diff --git a/pbs-client-installer.sh b/pbs-client-installer.sh index 1e3a596..2cb2708 100755 --- a/pbs-client-installer.sh +++ b/pbs-client-installer.sh @@ -123,6 +123,58 @@ resolve_target_input() { return 0 } +# Quick authentication test for a single target (minimal output) +quick_test_target() { + local target_name="$1" + local config_file="$(get_target_config_path "$target_name")" + + if [ ! -f "$config_file" ]; then + return 1 + fi + + # Source config in subshell to avoid polluting environment + ( + source "$config_file" + export PBS_REPOSITORY + export PBS_PASSWORD + + # Quick auth test - just try to login + echo "y" | timeout 5 proxmox-backup-client login >/dev/null 2>&1 + ) + return $? +} + +# Test all configured targets and display status +test_all_targets() { + if ! list_targets >/dev/null 2>&1; then + return 0 + fi + + echo + echo "════════════════════════════════════════" + echo " Testing Backup Target Connections" + echo "════════════════════════════════════════" + echo + + local all_ok=true + while IFS= read -r target; do + printf " %-20s " "$target:" + + if quick_test_target "$target"; then + echo "✓ Connected" + else + echo "✗ Failed" + all_ok=false + fi + done < <(list_targets) + + echo + if [ "$all_ok" = false ]; then + warn "Some targets failed connection test" + info "Use option 3 (Edit target) to fix connection issues" + fi +} + migrate_legacy_config() { # Check if old single-target config exists if [ -f "$CONFIG_DIR/config" ] && [ ! -d "$TARGETS_DIR" ]; then @@ -1965,6 +2017,7 @@ main() { # Check if any targets exist if list_targets >/dev/null 2>&1; then show_targets_list + test_all_targets # Main menu loop while true; do