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:
parent
c51b5b03ee
commit
72ea543458
2 changed files with 108 additions and 88 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -152,30 +152,45 @@ 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}"
|
|
||||||
echo " Type: ${BACKUP_TYPE:-unknown}"
|
|
||||||
echo " Schedule: ${TIMER_SCHEDULE:-unknown}"
|
|
||||||
|
|
||||||
# Check if timer is active
|
# Check if config seems incomplete
|
||||||
if systemctl is-enabled "pbs-backup-${target}.timer" &>/dev/null; then
|
if [ -z "$PBS_SERVER" ] || [ -z "$PBS_DATASTORE" ]; then
|
||||||
if systemctl is-active "pbs-backup-${target}.timer" &>/dev/null; then
|
echo " Status: ⚠ Incomplete configuration"
|
||||||
echo " Status: ✓ Active"
|
echo " Action: Use option 3 (Edit target) to reconfigure"
|
||||||
else
|
|
||||||
echo " Status: ✗ Inactive"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo " Status: ✗ Disabled"
|
echo " Server: ${PBS_SERVER}:${PBS_PORT:-8007}"
|
||||||
|
echo " Datastore: ${PBS_DATASTORE}"
|
||||||
|
echo " Type: ${BACKUP_TYPE:-unknown}"
|
||||||
|
echo " Schedule: ${TIMER_SCHEDULE:-unknown}"
|
||||||
|
|
||||||
|
# Check if timer is active
|
||||||
|
if systemctl is-enabled "pbs-backup-${target}.timer" &>/dev/null; then
|
||||||
|
if systemctl is-active "pbs-backup-${target}.timer" &>/dev/null; then
|
||||||
|
echo " Status: ✓ Active"
|
||||||
|
else
|
||||||
|
echo " Status: ✗ Inactive"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo " Status: ✗ Disabled"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
done
|
done < <(list_targets)
|
||||||
}
|
}
|
||||||
|
|
||||||
add_target() {
|
add_target() {
|
||||||
|
|
@ -1908,85 +1923,81 @@ 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
|
||||||
echo
|
|
||||||
echo "════════════════════════════════════════"
|
|
||||||
echo " Multi-Target Backup Management"
|
|
||||||
echo "════════════════════════════════════════"
|
|
||||||
echo
|
|
||||||
echo "What would you like to do?"
|
|
||||||
echo " 1) List all backup targets"
|
|
||||||
echo " 2) Add new backup target"
|
|
||||||
echo " 3) Edit existing target"
|
|
||||||
echo " 4) Delete target"
|
|
||||||
echo " 5) Run backup now (select target)"
|
|
||||||
echo " 6) View target details"
|
|
||||||
echo " 7) Reinstall PBS client"
|
|
||||||
echo " 8) Exit"
|
|
||||||
ACTION=$(prompt "Select option [1-8]" "1")
|
|
||||||
|
|
||||||
case "$ACTION" in
|
# Main menu loop
|
||||||
1)
|
while true; do
|
||||||
show_targets_list
|
echo
|
||||||
exit 0
|
echo "════════════════════════════════════════"
|
||||||
;;
|
echo " Multi-Target Backup Management"
|
||||||
2)
|
echo "════════════════════════════════════════"
|
||||||
add_target
|
echo
|
||||||
exit 0
|
echo "What would you like to do?"
|
||||||
;;
|
echo " 1) List all backup targets"
|
||||||
3)
|
echo " 2) Add new backup target"
|
||||||
edit_target
|
echo " 3) Edit existing target"
|
||||||
exit 0
|
echo " 4) Delete target"
|
||||||
;;
|
echo " 5) Run backup now (select target)"
|
||||||
4)
|
echo " 6) View target details"
|
||||||
delete_target
|
echo " 7) Reinstall PBS client"
|
||||||
exit 0
|
echo " 8) Exit"
|
||||||
;;
|
ACTION=$(prompt "Select option [1-8]" "8")
|
||||||
5)
|
|
||||||
echo
|
|
||||||
echo "Available targets:"
|
|
||||||
list_targets | nl
|
|
||||||
echo
|
|
||||||
TARGET_NAME=$(prompt "Enter target name to backup" "")
|
|
||||||
|
|
||||||
if ! validate_target_name "$TARGET_NAME"; then
|
case "$ACTION" in
|
||||||
exit 1
|
1)
|
||||||
fi
|
show_targets_list
|
||||||
|
;;
|
||||||
|
2)
|
||||||
|
add_target
|
||||||
|
;;
|
||||||
|
3)
|
||||||
|
edit_target
|
||||||
|
;;
|
||||||
|
4)
|
||||||
|
delete_target
|
||||||
|
;;
|
||||||
|
5)
|
||||||
|
echo
|
||||||
|
echo "Available targets:"
|
||||||
|
list_targets | nl
|
||||||
|
echo
|
||||||
|
TARGET_NAME=$(prompt "Enter target name to backup" "")
|
||||||
|
|
||||||
if ! target_exists "$TARGET_NAME"; then
|
if ! validate_target_name "$TARGET_NAME"; then
|
||||||
error "Target '$TARGET_NAME' does not exist"
|
continue
|
||||||
exit 1
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
run_backup_for_target "$TARGET_NAME"
|
if ! target_exists "$TARGET_NAME"; then
|
||||||
exit 0
|
error "Target '$TARGET_NAME' does not exist"
|
||||||
;;
|
continue
|
||||||
6)
|
fi
|
||||||
echo
|
|
||||||
echo "Available targets:"
|
|
||||||
list_targets | nl
|
|
||||||
echo
|
|
||||||
TARGET_NAME=$(prompt "Enter target name to view" "")
|
|
||||||
|
|
||||||
if validate_target_name "$TARGET_NAME"; then
|
run_backup_for_target "$TARGET_NAME"
|
||||||
show_target_detail "$TARGET_NAME"
|
;;
|
||||||
fi
|
6)
|
||||||
exit 0
|
echo
|
||||||
;;
|
echo "Available targets:"
|
||||||
7)
|
list_targets | nl
|
||||||
info "Reinstalling PBS client..."
|
echo
|
||||||
install_pbs_client
|
TARGET_NAME=$(prompt "Enter target name to view" "")
|
||||||
log "PBS client reinstalled successfully"
|
|
||||||
exit 0
|
if validate_target_name "$TARGET_NAME"; then
|
||||||
;;
|
show_target_detail "$TARGET_NAME"
|
||||||
8)
|
fi
|
||||||
info "Exiting"
|
;;
|
||||||
exit 0
|
7)
|
||||||
;;
|
info "Reinstalling PBS client..."
|
||||||
*)
|
install_pbs_client
|
||||||
error "Invalid option"
|
log "PBS client reinstalled successfully"
|
||||||
exit 1
|
;;
|
||||||
;;
|
8)
|
||||||
esac
|
info "Exiting"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
error "Invalid option"
|
||||||
|
;;
|
||||||
|
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"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue