#!/bin/bash
echo "π Discord MCP - Safe GitHub Publication Script"
echo "=============================================="
# Step 1: Critical Security Check
echo ""
echo "π¨ STEP 1: CRITICAL SECURITY CHECK"
if [ -f ".env" ]; then
echo "β οΈ .env file exists - checking for real tokens..."
if grep -qE "MTM[A-Za-z0-9_-]{70,}" ".env" 2>/dev/null; then
echo "β Real Discord token found in .env file!"
echo " You MUST regenerate your Discord bot token before publishing!"
echo " Go to: https://discord.com/developers/applications"
echo ""
read -p "Have you regenerated your Discord token? (y/N): " token_regenerated
if [[ $token_regenerated != "y" && $token_regenerated != "Y" ]]; then
echo "π STOPPING: Please regenerate your token first!"
exit 1
fi
else
echo "β
No real tokens found in .env file"
fi
fi
# Step 2: Clean sensitive files
echo ""
echo "π§Ή STEP 2: CLEANING SENSITIVE FILES"
if [ -f "URGENT_TOKEN_SECURITY.md" ]; then
rm URGENT_TOKEN_SECURITY.md
echo "β
Removed security warning file"
fi
# Remove any remaining sensitive files
find . -name "*.log" -delete 2>/dev/null || true
echo "β
Cleaned up sensitive files"
# Step 3: Verify .gitignore
echo ""
echo "π STEP 3: VERIFYING .gitignore"
if grep -q "\.env$" .gitignore; then
echo "β
.env is properly ignored"
else
echo "β .env is NOT in .gitignore!"
exit 1
fi
# Step 4: Check for real secrets in staged files (not templates)
echo ""
echo "π STEP 4: SCANNING FOR REAL SECRETS"
if git diff --cached | grep -qE "(MTM[A-Za-z0-9_-]{70,}|[A-Za-z0-9_-]{50,}\.[A-Za-z0-9_-]{6}\.[A-Za-z0-9_-]{25,})"; then
echo "π¨ ERROR: Real Discord tokens detected in staged changes!"
git diff --cached | grep -E "(MTM[A-Za-z0-9_-]{70,}|[A-Za-z0-9_-]{50,}\.[A-Za-z0-9_-]{6}\.[A-Za-z0-9_-]{25,})" || true
exit 1
else
echo "β
No real secrets detected in staged changes"
fi
# Step 5: Build test
echo ""
echo "ποΈ STEP 5: BUILD TEST"
if npm run build > /dev/null 2>&1; then
echo "β
Build successful"
else
echo "β Build failed! Fix errors before publishing."
npm run build
exit 1
fi
# Step 6: Final confirmation
echo ""
echo "β
ALL SECURITY CHECKS PASSED!"
echo ""
echo "π FINAL CHECKLIST:"
echo " β
No real tokens in code"
echo " β
Sensitive files removed"
echo " β
.gitignore configured"
echo " β
No secrets in staged changes"
echo " β
Build successful"
echo ""
echo "π Ready to publish to GitHub!"
echo ""
echo "Next steps:"
echo "1. git add ."
echo "2. git commit -m 'feat: secure Discord MCP server with comprehensive security setup'"
echo "3. git push origin main"
echo ""
echo "π After publishing, enable these GitHub features:"
echo " - Branch protection rules"
echo " - Required reviews for PRs"
echo " - Secret scanning (GitHub Advanced Security)"
echo " - Dependabot security updates"