65 lines
2.1 KiB
Bash
65 lines
2.1 KiB
Bash
|
|
#!/usr/bin/env bash
|
|||
|
|
# OMNL Fineract — Remove the 15 clients (ids 1–15) 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
|