Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
- ADD_CHAIN138_TO_LEDGER_LIVE: Ledger form done; public code review repo bis-innovations/LedgerLive; init/push commands - CONTRACT_DEPLOYMENT_RUNBOOK: Chain 138 gas price 1 gwei, 36-addr check, TransactionMirror workaround - CONTRACT_*: AddressMapper, MirrorManager deployed 2026-02-12; 36-address on-chain check - NEXT_STEPS_FOR_YOU: Ledger done; steps completable now (no LAN); run-completable-tasks-from-anywhere - MASTER_INDEX, OPERATOR_OPTIONAL, SMART_CONTRACTS_INVENTORY_SIMPLE: updates - LEDGER_BLOCKCHAIN_INTEGRATION_COMPLETE: bis-innovations/LedgerLive reference Co-authored-by: Cursor <cursoragent@cursor.com>
123 lines
4.2 KiB
Bash
Executable File
123 lines
4.2 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
# Load IP configuration
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
|
|
|
|
|
|
# Update Sankofa NPMplus proxy hosts via API
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
|
|
# Load environment variables
|
|
if [ -f "$PROJECT_ROOT/.env" ]; then
|
|
export $(cat "$PROJECT_ROOT/.env" | grep -v '^#' | xargs)
|
|
fi
|
|
|
|
NPM_URL="${NPM_URL:-https://${IP_NPMPLUS}:81}"
|
|
NPM_EMAIL="${NPM_EMAIL:-nsatoshi2007@hotmail.com}"
|
|
NPM_PASSWORD="${NPM_PASSWORD:-}"
|
|
|
|
# Sankofa proxy host mappings
|
|
declare -A PROXY_HOSTS=(
|
|
["21"]="sankofa.nexus|${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-192.168.11.51}}}}}}|3000"
|
|
["22"]="www.sankofa.nexus|${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-192.168.11.51}}}}}}|3000"
|
|
["23"]="phoenix.sankofa.nexus|${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-192.168.11.50}}}}}}|4000"
|
|
["24"]="www.phoenix.sankofa.nexus|${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-192.168.11.50}}}}}}|4000"
|
|
)
|
|
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo "🔄 Updating Sankofa NPMplus Proxy Hosts"
|
|
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
|
|
echo "❌ Authentication failed"
|
|
exit 1
|
|
fi
|
|
|
|
echo "✅ Authentication successful"
|
|
echo ""
|
|
|
|
# Function to update proxy host
|
|
update_proxy_host() {
|
|
local host_id=$1
|
|
local domain=$2
|
|
local target_ip=$3
|
|
local target_port=$4
|
|
|
|
echo "📝 Updating Proxy Host $host_id: $domain → $target_ip:$target_port"
|
|
|
|
# Get current proxy host
|
|
CURRENT_HOST=$(curl -s -k -X GET "$NPM_URL/api/nginx/proxy-hosts/$host_id" \
|
|
-H "Authorization: Bearer $TOKEN" 2>/dev/null || echo "{}")
|
|
|
|
if [ "$(echo "$CURRENT_HOST" | jq -r '.id // empty')" = "" ]; then
|
|
echo "❌ Proxy host $host_id not found"
|
|
return 1
|
|
fi
|
|
|
|
# Update proxy host
|
|
UPDATE_PAYLOAD=$(echo "$CURRENT_HOST" | jq --arg ip "$target_ip" --arg port "$target_port" \
|
|
'.forward_host = $ip | .forward_port = ($port | tonumber)')
|
|
|
|
RESPONSE=$(curl -s -k -X PUT "$NPM_URL/api/nginx/proxy-hosts/$host_id" \
|
|
-H "Authorization: Bearer $TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$UPDATE_PAYLOAD")
|
|
|
|
UPDATED_ID=$(echo "$RESPONSE" | jq -r '.id // empty' 2>/dev/null || echo "")
|
|
|
|
if [ -n "$UPDATED_ID" ] && [ "$UPDATED_ID" != "null" ]; then
|
|
echo "✅ Successfully updated proxy host $host_id"
|
|
return 0
|
|
else
|
|
echo "❌ Failed to update proxy host $host_id"
|
|
echo "$RESPONSE" | jq '.' 2>/dev/null || echo "$RESPONSE"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Update all proxy hosts
|
|
SUCCESS=0
|
|
FAILED=0
|
|
|
|
for host_id in "${!PROXY_HOSTS[@]}"; do
|
|
IFS='|' read -r domain target_ip target_port <<< "${PROXY_HOSTS[$host_id]}"
|
|
|
|
if update_proxy_host "$host_id" "$domain" "$target_ip" "$target_port"; then
|
|
((SUCCESS++))
|
|
else
|
|
((FAILED++))
|
|
fi
|
|
echo ""
|
|
done
|
|
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo "📊 Update Summary"
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo "✅ Successfully updated: $SUCCESS"
|
|
echo "❌ Failed: $FAILED"
|
|
echo ""
|
|
|
|
if [ $FAILED -eq 0 ]; then
|
|
echo "🎉 All proxy hosts updated successfully!"
|
|
exit 0
|
|
else
|
|
echo "⚠️ Some proxy hosts failed to update"
|
|
exit 1
|
|
fi
|