Files
proxmox/scripts/archive/consolidated/fix/fix-npmplus-mappings-via-ssh.sh
defiQUG fbda1b4beb
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
docs: Ledger Live integration, contract deploy learnings, NEXT_STEPS updates
- 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>
2026-02-12 15:46:57 -08:00

209 lines
7.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Fix incorrect NPMplus proxy host mappings via SSH
# Corrects Sankofa and test domain entries that are pointing to wrong services
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
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$PROJECT_ROOT"
# Source .env
if [ -f .env ]; then
set +euo pipefail
source .env 2>/dev/null || true
set -euo pipefail
fi
NPM_URL="${NPM_URL:-https://${IP_NPMPLUS_ETH0:-192.168.11.166}:81}"
NPM_EMAIL="${NPM_EMAIL:-nsatoshi2007@hotmail.com}"
NPM_PASSWORD="${NPM_PASSWORD:-}"
NPMPLUS_VMID="${NPMPLUS_VMID:-10233}"
NPMPLUS_HOST="${NPMPLUS_HOST:-192.168.11.11}"
if [ -z "$NPM_PASSWORD" ]; then
echo "Error: NPM_PASSWORD not set in .env"
exit 1
fi
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[⚠]${NC} $1"; }
log_error() { echo -e "${RED}[✗]${NC} $1"; }
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🔧 Fixing Incorrect NPMplus Proxy Host Mappings"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Create update script to run inside container
UPDATE_SCRIPT=$(cat <<'EOFSCRIPT'
#!/usr/bin/env node
const Database = require('better-sqlite3');
const db = new Database('/data/npmplus/database.sqlite');
// Correct mappings
const correctMappings = {
'sankofa.nexus': { ip: '${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-192.168.11.51}}}}', port: 3000 },
'www.sankofa.nexus': { ip: '${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-192.168.11.51}}}}', port: 3000 },
'phoenix.sankofa.nexus': { ip: '${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-192.168.11.50}}}}', port: 4000 },
'www.phoenix.sankofa.nexus': { ip: '${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-192.168.11.50}}}}', port: 4000 }
};
// Test domains to delete
const testDomains = ['test-minimal.example.com', 'test-ws.example.com'];
try {
// Get all proxy hosts
const hosts = db.prepare('SELECT id, domain_names, forward_host, forward_port FROM proxy_host').all();
let updated = 0;
let deleted = 0;
let errors = [];
for (const host of hosts) {
const domainNames = JSON.parse(host.domain_names);
const primaryDomain = domainNames[0];
// Check if needs update
if (correctMappings[primaryDomain]) {
const correct = correctMappings[primaryDomain];
if (host.forward_host !== correct.ip || host.forward_port !== correct.port) {
try {
db.prepare('UPDATE proxy_host SET forward_host = ?, forward_port = ? WHERE id = ?')
.run(correct.ip, correct.port, host.id);
console.log(`✓ Updated ${primaryDomain} (ID: ${host.id}) → ${correct.ip}:${correct.port}`);
updated++;
} catch (err) {
errors.push(`Failed to update ${primaryDomain}: ${err.message}`);
}
}
}
// Check if test domain to delete
if (testDomains.includes(primaryDomain)) {
try {
db.prepare('DELETE FROM proxy_host WHERE id = ?').run(host.id);
console.log(`✓ Deleted test domain ${primaryDomain} (ID: ${host.id})`);
deleted++;
} catch (err) {
errors.push(`Failed to delete ${primaryDomain}: ${err.message}`);
}
}
}
console.log(`\nSummary: ${updated} updated, ${deleted} deleted`);
if (errors.length > 0) {
console.error('\nErrors:');
errors.forEach(e => console.error(` - ${e}`));
}
db.close();
} catch (err) {
console.error(`Error: ${err.message}`);
process.exit(1);
}
EOFSCRIPT
)
log_info "Running update script in NPMplus container..."
# Execute Node.js code directly via stdin
ssh -o StrictHostKeyChecking=no root@"$NPMPLUS_HOST" "pct exec $NPMPLUS_VMID -- docker exec -i npmplus node" <<'EOFNODE'
const Database = require('better-sqlite3');
const db = new Database('/data/npmplus/database.sqlite');
// Correct mappings
const correctMappings = {
'sankofa.nexus': { ip: '${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-192.168.11.51}}}}', port: 3000 },
'www.sankofa.nexus': { ip: '${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-192.168.11.51}}}}', port: 3000 },
'phoenix.sankofa.nexus': { ip: '${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-192.168.11.50}}}}', port: 4000 },
'www.phoenix.sankofa.nexus': { ip: '${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-192.168.11.50}}}}', port: 4000 }
};
// Test domains to delete
const testDomains = ['test-minimal.example.com', 'test-ws.example.com'];
try {
// Get all proxy hosts
const hosts = db.prepare('SELECT id, domain_names, forward_host, forward_port FROM proxy_host').all();
let updated = 0;
let deleted = 0;
let errors = [];
for (const host of hosts) {
const domainNames = JSON.parse(host.domain_names);
const primaryDomain = domainNames[0];
// Check if needs update
if (correctMappings[primaryDomain]) {
const correct = correctMappings[primaryDomain];
if (host.forward_host !== correct.ip || host.forward_port !== correct.port) {
try {
db.prepare('UPDATE proxy_host SET forward_host = ?, forward_port = ? WHERE id = ?')
.run(correct.ip, correct.port, host.id);
console.log(`✓ Updated ${primaryDomain} (ID: ${host.id}) → ${correct.ip}:${correct.port}`);
updated++;
} catch (err) {
errors.push(`Failed to update ${primaryDomain}: ${err.message}`);
}
}
}
// Check if test domain to delete
if (testDomains.includes(primaryDomain)) {
try {
db.prepare('DELETE FROM proxy_host WHERE id = ?').run(host.id);
console.log(`✓ Deleted test domain ${primaryDomain} (ID: ${host.id})`);
deleted++;
} catch (err) {
errors.push(`Failed to delete ${primaryDomain}: ${err.message}`);
}
}
}
console.log(`\nSummary: ${updated} updated, ${deleted} deleted`);
if (errors.length > 0) {
console.error('\nErrors:');
errors.forEach(e => console.error(` - ${e}`));
}
db.close();
} catch (err) {
console.error(`Error: ${err.message}`);
process.exit(1);
}
EOFNODE
UPDATE_RESULT=$?
# Clean up
ssh -o StrictHostKeyChecking=no root@"$NPMPLUS_HOST" "pct exec $NPMPLUS_VMID -- rm -f /tmp/fix-mappings.js" 2>&1 >/dev/null
if [ $UPDATE_RESULT -eq 0 ]; then
log_success "Proxy host mappings updated successfully!"
echo ""
log_info "Note: the-order.sankofa.nexus is marked as TBD in documentation and was not changed"
echo ""
log_info "Verifying changes..."
bash "$SCRIPT_DIR/list-npmplus-mappings.sh" 2>&1 | grep -E "(sankofa|test-)" || true
else
log_error "Update failed. Please check the errors above."
exit 1
fi