diff --git a/lib/restore.sh b/lib/restore.sh index 5add19e..5c94a36 100644 --- a/lib/restore.sh +++ b/lib/restore.sh @@ -132,13 +132,21 @@ restore_full_account() { if [[ "$terminate" == "true" ]] && account_exists "$user"; then log_info "Terminating existing account $user before restore..." local removeacct_output - if ! removeacct_output=$(/scripts/removeacct "$user" --force 2>&1); then + if ! removeacct_output=$(whmapi1 removeacct user="$user" 2>&1); then log_error "Failed to terminate account $user" log_debug "removeacct output: $removeacct_output" rm -rf "$restore_dir" return 1 fi log_debug "removeacct output: $removeacct_output" + # Check whmapi1 result field for failure + if echo "$removeacct_output" | grep -q 'result: 0'; then + local reason + reason=$(echo "$removeacct_output" | grep 'reason:' | sed 's/.*reason: //') + log_error "Failed to terminate account $user: $reason" + rm -rf "$restore_dir" + return 1 + fi fi # Run restorepkg (--force to merge into existing account if present)