mnemo_cards/tools/deploy/fix-code-domain-conflict.sh

93 lines
2.9 KiB
Bash
Raw Permalink Normal View History

2025-11-19 19:32:48 +00:00
#!/bin/bash
# Script to automatically fix code.mnemo-cards.online domain conflict
set -e
SERVER_IP="147.45.152.129"
SERVER_USER="root"
echo "🔧 Fixing code.mnemo-cards.online domain conflict..."
echo ""
ssh "$SERVER_USER@$SERVER_IP" << 'ENDSSH'
set -e
echo "📊 Searching for code.mnemo-cards.online in nginx configs..."
echo ""
# Find all files containing code.mnemo-cards.online
echo "Files containing code.mnemo-cards.online:"
grep -l "code.mnemo-cards.online" /etc/nginx/sites-available/* 2>/dev/null | sort | uniq || echo "None found"
echo ""
echo "=== Current server_name in forgejo config ==="
if [ -f /etc/nginx/sites-available/forgejo ]; then
grep "server_name" /etc/nginx/sites-available/forgejo | head -5 || true
fi
echo ""
echo "🔧 Removing code.mnemo-cards.online from Forgejo config..."
if [ -f /etc/nginx/sites-available/forgejo ]; then
# Backup forgejo config
cp /etc/nginx/sites-available/forgejo /etc/nginx/sites-available/forgejo.backup.$(date +%Y%m%d_%H%M%S)
# Remove code.mnemo-cards.online from server_name lines
# This will remove it but keep other domains
sed -i 's/code\.mnemo-cards\.online//g' /etc/nginx/sites-available/forgejo
# Clean up any double spaces
sed -i 's/ */ /g' /etc/nginx/sites-available/forgejo
# Clean up trailing spaces on server_name lines
sed -i '/server_name/s/ *;/;/g' /etc/nginx/sites-available/forgejo
echo "✅ Updated forgejo config"
echo ""
echo "=== New server_name in forgejo config ==="
grep "server_name" /etc/nginx/sites-available/forgejo | head -5 || true
else
echo "⚠️ Forgejo config not found"
fi
echo ""
echo "📊 Testing nginx configuration..."
if /usr/sbin/nginx -t 2>&1; then
echo "✅ nginx config is valid"
echo ""
echo "🔄 Reloading nginx..."
systemctl reload nginx
echo "✅ nginx reloaded"
else
echo "❌ nginx config is invalid, restoring backup..."
if [ -f /etc/nginx/sites-available/forgejo.backup.$(date +%Y%m%d_%H%M%S) ]; then
cp /etc/nginx/sites-available/forgejo.backup.$(date +%Y%m%d_%H%M%S) /etc/nginx/sites-available/forgejo
echo "✅ Backup restored"
fi
exit 1
fi
ENDSSH
echo ""
echo "✅ Done! Testing URLs..."
echo ""
# Wait a bit for nginx to fully reload
sleep 2
# Test the URLs
echo "Testing vscode.mnemo-cards.online..."
curl -I https://vscode.mnemo-cards.online 2>&1 | head -3 || echo "⚠️ Could not reach vscode.mnemo-cards.online"
echo ""
echo "Testing code.mnemo-cards.online..."
curl -I https://code.mnemo-cards.online 2>&1 | head -3 || echo "⚠️ Could not reach code.mnemo-cards.online"
echo ""
echo "✅ Complete!"