Fix: Menu loop and incomplete target configuration display

This commit addresses two user-reported issues:

ISSUE 1: Menu exits after every action instead of looping
- Removed all `exit 0` calls from menu options (except Exit option)
- Wrapped menu in `while true` loop for continuous operation
- Changed error exits to `continue` to return to menu
- Users can now perform multiple actions without restarting script

ISSUE 2: Target list shows "unknown" values for server/datastore
- Root cause: Empty variables in config file (incomplete migration/setup)
- Improved show_targets_list() with better error handling:
  - Uses process substitution `< <(list_targets)` instead of pipe
  - Clears all variables before sourcing each config
  - Detects incomplete configs (missing PBS_SERVER/PBS_DATASTORE)
  - Shows warning: "⚠ Incomplete configuration"
  - Suggests: "Use option 3 (Edit target) to reconfigure"
- Only displays server/datastore when config is complete

USER EXPERIENCE:
Before:
- Script exits after listing targets (requires restart)
- Shows "unknown:8007" and confusing empty values

After:
- Menu loops continuously until user selects Exit
- Shows clear warning for incomplete configs with action steps
- Prevents variable carryover between target iterations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
zaphod-black 2025-11-01 22:23:00 -05:00
parent c51b5b03ee
commit 72ea543458
2 changed files with 108 additions and 88 deletions

View file

@ -120,6 +120,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Script version bumped to 1.1.0 for multi-target support - Script version bumped to 1.1.0 for multi-target support
### Fixed ### Fixed
- **Main menu now loops properly after actions**
- Removed `exit 0` calls from all menu options except Exit
- Menu now continues after listing targets, running backups, or other actions
- Users can perform multiple operations without restarting script
- **Target list display improved for incomplete configurations**
- Shows warning message when PBS_SERVER or PBS_DATASTORE are empty
- Suggests using "Edit target" option to fix incomplete configs
- Uses process substitution to avoid variable scoping issues
- Clears variables between iterations to prevent data carryover
- **CRITICAL**: SSL fingerprint prompt no longer causes authentication timeout - **CRITICAL**: SSL fingerprint prompt no longer causes authentication timeout
- Script now automatically accepts SSL fingerprints by piping 'y' to login - Script now automatically accepts SSL fingerprints by piping 'y' to login
- This was the root cause of "authentication hanging" issues - This was the root cause of "authentication hanging" issues

View file

@ -152,14 +152,28 @@ show_targets_list() {
return 1 return 1
fi fi
list_targets | while read -r target; do # Use process substitution to avoid subshell issues
while IFS= read -r target; do
local config_file="$(get_target_config_path "$target")" local config_file="$(get_target_config_path "$target")"
# Clear any previous variables
unset PBS_SERVER PBS_PORT PBS_DATASTORE PBS_REPOSITORY PBS_PASSWORD
unset BACKUP_TYPE BACKUP_PATHS EXCLUDE_PATTERNS BLOCK_DEVICE
unset TIMER_SCHEDULE TIMER_ONCALENDAR KEEP_LAST KEEP_DAILY KEEP_WEEKLY KEEP_MONTHLY
unset BLOCK_DEVICE_FREQUENCY BLOCK_DEVICE_DAY
if [ -f "$config_file" ]; then if [ -f "$config_file" ]; then
source "$config_file" source "$config_file"
echo "Target: $target" echo "Target: $target"
echo " Server: ${PBS_SERVER:-unknown}:${PBS_PORT:-8007}"
echo " Datastore: ${PBS_DATASTORE:-unknown}" # Check if config seems incomplete
if [ -z "$PBS_SERVER" ] || [ -z "$PBS_DATASTORE" ]; then
echo " Status: ⚠ Incomplete configuration"
echo " Action: Use option 3 (Edit target) to reconfigure"
else
echo " Server: ${PBS_SERVER}:${PBS_PORT:-8007}"
echo " Datastore: ${PBS_DATASTORE}"
echo " Type: ${BACKUP_TYPE:-unknown}" echo " Type: ${BACKUP_TYPE:-unknown}"
echo " Schedule: ${TIMER_SCHEDULE:-unknown}" echo " Schedule: ${TIMER_SCHEDULE:-unknown}"
@ -173,9 +187,10 @@ show_targets_list() {
else else
echo " Status: ✗ Disabled" echo " Status: ✗ Disabled"
fi fi
fi
echo echo
fi fi
done done < <(list_targets)
} }
add_target() { add_target() {
@ -1908,6 +1923,9 @@ main() {
# Check if any targets exist # Check if any targets exist
if list_targets >/dev/null 2>&1; then if list_targets >/dev/null 2>&1; then
show_targets_list show_targets_list
# Main menu loop
while true; do
echo echo
echo "════════════════════════════════════════" echo "════════════════════════════════════════"
echo " Multi-Target Backup Management" echo " Multi-Target Backup Management"
@ -1922,24 +1940,20 @@ main() {
echo " 6) View target details" echo " 6) View target details"
echo " 7) Reinstall PBS client" echo " 7) Reinstall PBS client"
echo " 8) Exit" echo " 8) Exit"
ACTION=$(prompt "Select option [1-8]" "1") ACTION=$(prompt "Select option [1-8]" "8")
case "$ACTION" in case "$ACTION" in
1) 1)
show_targets_list show_targets_list
exit 0
;; ;;
2) 2)
add_target add_target
exit 0
;; ;;
3) 3)
edit_target edit_target
exit 0
;; ;;
4) 4)
delete_target delete_target
exit 0
;; ;;
5) 5)
echo echo
@ -1949,16 +1963,15 @@ main() {
TARGET_NAME=$(prompt "Enter target name to backup" "") TARGET_NAME=$(prompt "Enter target name to backup" "")
if ! validate_target_name "$TARGET_NAME"; then if ! validate_target_name "$TARGET_NAME"; then
exit 1 continue
fi fi
if ! target_exists "$TARGET_NAME"; then if ! target_exists "$TARGET_NAME"; then
error "Target '$TARGET_NAME' does not exist" error "Target '$TARGET_NAME' does not exist"
exit 1 continue
fi fi
run_backup_for_target "$TARGET_NAME" run_backup_for_target "$TARGET_NAME"
exit 0
;; ;;
6) 6)
echo echo
@ -1970,13 +1983,11 @@ main() {
if validate_target_name "$TARGET_NAME"; then if validate_target_name "$TARGET_NAME"; then
show_target_detail "$TARGET_NAME" show_target_detail "$TARGET_NAME"
fi fi
exit 0
;; ;;
7) 7)
info "Reinstalling PBS client..." info "Reinstalling PBS client..."
install_pbs_client install_pbs_client
log "PBS client reinstalled successfully" log "PBS client reinstalled successfully"
exit 0
;; ;;
8) 8)
info "Exiting" info "Exiting"
@ -1984,9 +1995,9 @@ main() {
;; ;;
*) *)
error "Invalid option" error "Invalid option"
exit 1
;; ;;
esac esac
done
else else
# PBS client installed but no targets configured # PBS client installed but no targets configured
info "No backup targets configured" info "No backup targets configured"