Files
myceliumcloud-examples/examples/nginx-mycelium/update-mycelium-content.sh

130 lines
5.7 KiB
Bash
Executable File

#!/bin/bash
# Mycelium Cloud IPv6 Website - Direct Content Injection Script
# This script updates the nginx deployment to serve the dynamic content
set -e
echo "🔍 Discovering Mycelium IPv6 addresses..."
# Fetch IPv6 addresses from cluster nodes
IPV6_ADDRESSES=$(kubectl get nodes -o jsonpath='{range .items[*]}{range .status.addresses[?(@.type=="InternalIP")]}{.address}{"\n"}{end}{end}' | grep -E '^[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+$')
if [ -z "$IPV6_ADDRESSES" ]; then
echo "❌ No IPv6 addresses found!"
exit 1
fi
echo "✅ Found IPv6 addresses:"
echo "$IPV6_ADDRESSES"
# Create the dynamic HTML content
cat > /tmp/mycelium-index.html << HTML_EOF
<!DOCTYPE html>
<html>
<head>
<title>🌍 Mycelium Global Web Hosting</title>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="30">
<style>
body { font-family: Arial, sans-serif; margin: 50px; background: #f0f0f0; }
.container { background: white; padding: 40px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); max-width: 800px; margin: 0 auto; }
h1 { color: #2c3e50; text-align: center; }
.success { background: #e8f4fd; padding: 20px; border-radius: 8px; border-left: 4px solid #3498db; margin: 20px 0; }
.info { background: #f8f9fa; padding: 20px; border-radius: 8px; margin: 20px 0; }
.urls { background: #fff3cd; padding: 20px; border-radius: 8px; border-left: 4px solid #ffc107; margin: 20px 0; }
.test { background: #d4edda; padding: 20px; border-radius: 8px; border-left: 4px solid #28a745; margin: 20px 0; }
.dynamic { background: #f8d7da; padding: 20px; border-radius: 8px; border-left: 4px solid #dc3545; margin: 20px 0; }
code { background: #f8f9fa; padding: 2px 4px; border-radius: 3px; font-size: 12px; }
pre { background: #f8f9fa; padding: 10px; border-radius: 4px; font-size: 12px; color: #333; }
.timestamp { text-align: center; color: #6c757d; font-size: 14px; margin-top: 20px; }
</style>
</head>
<body>
<div class="container">
<h1>🌍 Mycelium Global Web Hosting</h1>
<div class="success">
<h2>✅ SUCCESS! Mycelium IPv6 Website is Live!</h2>
<p><strong>This website is globally accessible via Mycelium Cloud!</strong></p>
<p>This demonstrates real decentralized web hosting that anyone with Mycelium can access from anywhere in the world.</p>
</div>
<div class="dynamic">
<h2>🔄 Dynamic Discovery Active</h2>
<p><strong>IPv6 addresses automatically discovered from cluster!</strong></p>
<p>This page updates every 30 seconds to show the current cluster state.</p>
</div>
<div class="info">
<h3>🏗️ Technical Implementation</h3>
<ul>
<li><strong>Deployment:</strong> nginx pods with hostNetwork for direct IPv6 access</li>
<li><strong>Network:</strong> Direct binding to Mycelium IPv6 interfaces</li>
<li><strong>Global Access:</strong> Available on all cluster Mycelium IPv6 addresses</li>
<li><strong>Dynamic Discovery:</strong> IPv6 addresses fetched via kubectl automatically</li>
<li><strong>Content:</strong> Auto-generated with current cluster information</li>
</ul>
</div>
<div class="urls">
<h3>🌐 Global Access URLs</h3>
<p><strong>Your website is accessible via any Mycelium IPv6:</strong></p>
<ul>
HTML_EOF
# Add each IPv6 address to the HTML
while IFS= read -r ipv6; do
echo " <li><code>http://[$ipv6]:80</code></li>" >> /tmp/mycelium-index.html
done <<< "$IPV6_ADDRESSES"
cat >> /tmp/mycelium-index.html << HTML_EOF
</ul>
<p><em>Anyone with Mycelium can access your website from anywhere in the world!</em></p>
</div>
<div class="test">
<h3>🚀 IPv6 Connectivity Test</h3>
<p>Test if Mycelium IPv6 connectivity is working:</p>
<pre>curl http://[$(echo "$IPV6_ADDRESSES" | head -1)]:80</pre>
<p>All 6 IPv6 addresses should respond with this website content!</p>
</div>
<div class="timestamp">
<p>Last updated: $(date -u +"%Y-%m-%d %H:%M:%S UTC")</p>
<p>IPv6 addresses discovered: $(echo "$IPV6_ADDRESSES" | wc -l)</p>
<p>Status: 🟢 LIVE on Mycelium Cloud</p>
</div>
<div style="text-align: center; margin-top: 30px; padding-top: 20px; border-top: 1px solid #dee2e6;">
<p>
<strong>Mycelium Cloud</strong> • Decentralized Global Internet Infrastructure<br>
<em>Deploy once, access worldwide! 🌍</em><br>
<small>Peer-to-Peer IPv6 Website Hosting</small>
</p>
</div>
</div>
</body>
</html>
HTML_EOF
echo "📝 Generated dynamic HTML with $(echo "$IPV6_ADDRESSES" | wc -l) IPv6 addresses"
# Update all nginx pods with the new content
echo "🔄 Updating nginx containers with dynamic content..."
# Get all nginx-mycelium-global pods and inject the content
PODS=$(kubectl get pods -l app=nginx-mycelium-global -o name 2>/dev/null || true)
if [ -z "$PODS" ]; then
echo "⚠️ No nginx-mycelium-global pods found, you may need to deploy them first"
else
for pod in $PODS; do
echo "📤 Updating $pod..."
kubectl cp /tmp/mycelium-index.html $pod:/usr/share/nginx/html/index.html || echo "Failed to update $pod"
done
fi
echo "✅ Dynamic content update complete!"
echo "🌐 Your website is now live on Mycelium Cloud!"
echo "🌍 Test with: curl http://[$(echo "$IPV6_ADDRESSES | head -1)]:80"