Files
proxmox/scripts/nginx-proxy-manager/delete-sankofa-proxy-hosts.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

124 lines
4.2 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
set -euo pipefail
# Delete sankofa.nexus and phoenix.sankofa.nexus proxy hosts from NPMplus
# These were incorrectly routing to Blockscout and need to be removed
set -e
# Load environment variables
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
if [ -f "$PROJECT_ROOT/.env" ]; then
export $(cat "$PROJECT_ROOT/.env" | grep -v '^#' | xargs)
fi
NPM_URL="${NPM_URL:-https://192.168.0.166:81}"
NPM_EMAIL="${NPM_EMAIL:-nsatoshi2007@hotmail.com}"
# NPM_PASSWORD should come from environment variable
if [ -z "${NPM_PASSWORD:-}" ]; then
log_error "NPM_PASSWORD environment variable is required"
log_info "Set it in ~/.env file: NPM_PASSWORD=your-password"
exit 1
fi
# Domains to delete
DOMAINS_TO_DELETE=(
"sankofa.nexus"
"phoenix.sankofa.nexus"
"the-order.sankofa.nexus"
"www.sankofa.nexus"
"www.phoenix.sankofa.nexus"
)
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🗑️ Deleting Sankofa Proxy Hosts from NPMplus"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Authenticate
echo "🔐 Authenticating to NPMplus..."
TOKEN_RESPONSE=$(curl -s -k -X POST "$NPM_URL/api/tokens" \
-H "Content-Type: application/json" \
-d "{\"identity\":\"$NPM_EMAIL\",\"secret\":\"$NPM_PASSWORD\"}")
TOKEN=$(echo "$TOKEN_RESPONSE" | jq -r '.token // empty' 2>/dev/null || echo "")
if [ -z "$TOKEN" ] || [ "$TOKEN" = "null" ]; then
ERROR_MSG=$(echo "$TOKEN_RESPONSE" | jq -r '.error.message // "Unknown error"' 2>/dev/null || echo "$TOKEN_RESPONSE")
echo "❌ Authentication failed: $ERROR_MSG"
exit 1
fi
echo "✅ Authentication successful"
echo ""
# Get all proxy hosts
echo "📋 Fetching proxy hosts..."
PROXY_HOSTS_JSON=$(curl -s -k -X GET "$NPM_URL/api/nginx/proxy-hosts" \
-H "Authorization: Bearer $TOKEN")
if [ $? -ne 0 ]; then
echo "❌ Failed to fetch proxy hosts"
exit 1
fi
# Delete each domain
deleted_count=0
not_found_count=0
failed_count=0
for domain in "${DOMAINS_TO_DELETE[@]}"; do
echo "🔍 Searching for proxy host: $domain"
# Find the host ID
HOST_ID=$(echo "$PROXY_HOSTS_JSON" | jq -r ".result[] | select(.domain_names[] == \"$domain\") | .id" 2>/dev/null | head -n1 || echo "")
if [ -z "$HOST_ID" ] || [ "$HOST_ID" = "null" ]; then
echo " ⚠️ Not found (may already be deleted)"
not_found_count=$((not_found_count + 1))
continue
fi
echo " 📍 Found (ID: $HOST_ID)"
# Delete the proxy host
DELETE_RESPONSE=$(curl -s -k -X DELETE "$NPM_URL/api/nginx/proxy-hosts/$HOST_ID" \
-H "Authorization: Bearer $TOKEN")
# Check if deletion was successful
if echo "$DELETE_RESPONSE" | jq -e '.success == true' > /dev/null 2>&1 || \
echo "$DELETE_RESPONSE" | jq -e '.id' > /dev/null 2>&1 || \
[ -z "$DELETE_RESPONSE" ] || [ "$DELETE_RESPONSE" = "{}" ]; then
echo " ✅ Deleted successfully"
deleted_count=$((deleted_count + 1))
else
ERROR=$(echo "$DELETE_RESPONSE" | jq -r '.error.message // .error // "Unknown error"' 2>/dev/null || echo "$DELETE_RESPONSE")
echo " ❌ Failed to delete: $ERROR"
failed_count=$((failed_count + 1))
fi
echo ""
sleep 1 # Rate limiting
done
# Summary
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📊 Summary"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✅ Deleted: $deleted_count"
echo "⚠️ Not found: $not_found_count"
echo "❌ Failed: $failed_count"
echo ""
if [ $deleted_count -gt 0 ] || [ $not_found_count -gt 0 ]; then
echo "✅ Sankofa proxy hosts have been removed from NPMplus"
echo ""
echo " These domains will no longer route to Blockscout."
echo " When Sankofa services are deployed, re-add them to"
echo " configure-npmplus-domains.js with the correct backend IPs."
else
echo "⚠️ No proxy hosts were deleted"
fi