Files
proxmox/scripts/omnl/omnl-clients-remove-15.sh
defiQUG b3a8fe4496
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
chore: sync all changes to Gitea
- Config, docs, scripts, and backup manifests
- Submodule refs unchanged (m = modified content in submodules)

Made-with: Cursor
2026-03-02 11:37:34 -08:00

65 lines
2.1 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# OMNL Fineract — Remove the 15 clients (ids 115) that were created as entities.
# Run this after populating the 15 entities as Offices (omnl-offices-populate-15.sh).
# Usage: run from repo root; sources omnl-fineract/.env or .env.
# CONFIRM_REMOVE=1 Required to actually delete (safety).
# DRY_RUN=1 print only, do not DELETE.
# Requires: curl, jq.
set -euo pipefail
REPO_ROOT="${REPO_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)}"
DRY_RUN="${DRY_RUN:-0}"
CONFIRM_REMOVE="${CONFIRM_REMOVE:-0}"
if [ -f "${REPO_ROOT}/omnl-fineract/.env" ]; then
set +u
source "${REPO_ROOT}/omnl-fineract/.env" 2>/dev/null || true
set -u
elif [ -f "${REPO_ROOT}/.env" ]; then
set +u
source "${REPO_ROOT}/.env" 2>/dev/null || true
set -u
fi
BASE_URL="${OMNL_FINERACT_BASE_URL:-}"
TENANT="${OMNL_FINERACT_TENANT:-omnl}"
USER="${OMNL_FINERACT_USER:-app.omnl}"
PASS="${OMNL_FINERACT_PASSWORD:-}"
if [ -z "$BASE_URL" ] || [ -z "$PASS" ]; then
echo "Set OMNL_FINERACT_BASE_URL and OMNL_FINERACT_PASSWORD (e.g. in omnl-fineract/.env)" >&2
exit 1
fi
if [ "$CONFIRM_REMOVE" != "1" ] && [ "$DRY_RUN" != "1" ]; then
echo "Safety: set CONFIRM_REMOVE=1 to actually delete the 15 clients." >&2
echo "Example: CONFIRM_REMOVE=1 bash scripts/omnl/omnl-clients-remove-15.sh" >&2
exit 1
fi
CURL_OPTS=(-s -S -H "Fineract-Platform-TenantId: ${TENANT}" -H "Content-Type: application/json" -u "${USER}:${PASS}")
removed=0
failed=0
# Delete in reverse order (15..1) in case of constraints
for id in 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1; do
if [ "$DRY_RUN" = "1" ]; then
echo " [DRY RUN] DELETE clients/$id" >&2
((removed++)) || true
continue
fi
if [ "$CONFIRM_REMOVE" != "1" ]; then
continue
fi
res=$(curl "${CURL_OPTS[@]}" -X DELETE "${BASE_URL}/clients/${id}" 2>/dev/null) || true
if echo "$res" | jq -e '.resourceId' >/dev/null 2>&1 || [ -z "$res" ]; then
echo " Deleted clientId=$id" >&2
((removed++)) || true
else
echo " Failed clientId=$id: $res" >&2
((failed++)) || true
fi
done
echo "Done: $removed deleted, $failed failed." >&2