#!/bin/bash # Setup script for local development with market-data.local domain # This script automates the hosts file entry required for MT5 EA connectivity set -e DOMAIN="market-data.local" HOSTS_ENTRY="127.0.0.1 ${DOMAIN}" HOSTS_FILE="/etc/hosts" echo "🚀 Setting up local development environment for Market Data Service" echo "" # Check if running on macOS if [[ "$OSTYPE" == "darwin"* ]]; then OS="macOS" elif [[ "$OSTYPE" == "linux-gnu"* ]]; then OS="Linux" else echo "⚠️ Warning: Unsupported OS. Please manually add to hosts file:" echo " ${HOSTS_ENTRY}" exit 1 fi # Check if entry already exists if grep -q "${DOMAIN}" "${HOSTS_FILE}" 2>/dev/null; then echo "✅ Hosts entry for ${DOMAIN} already exists" echo "" echo "Current entry:" grep "${DOMAIN}" "${HOSTS_FILE}" | head -1 echo "" echo "✅ Setup complete! You can now use http://${DOMAIN}" exit 0 fi # Check if running as root (required for hosts file modification) if [ "$EUID" -ne 0 ]; then echo "📝 Adding ${DOMAIN} to hosts file requires administrator privileges" echo "" # Try to use osascript on macOS for interactive password prompt if [[ "$OSTYPE" == "darwin"* ]] && command -v osascript >/dev/null 2>&1; then echo " Prompting for administrator password..." echo "" # Use osascript to run the command with admin privileges osascript -e "do shell script \"echo '${HOSTS_ENTRY}' >> ${HOSTS_FILE}\" with administrator privileges" 2>&1 if [ $? -ne 0 ]; then echo "" echo "❌ Failed to add entry. Please run manually:" echo " sudo bash scripts/setup-local-dev.sh" echo "" echo "Or manually add this line to ${HOSTS_FILE}:" echo " ${HOSTS_ENTRY}" exit 1 fi else # Not macOS or osascript not available, require manual sudo echo "Please run this script with sudo:" echo " sudo bash scripts/setup-local-dev.sh" echo "" echo "Or manually add this line to ${HOSTS_FILE}:" echo " ${HOSTS_ENTRY}" exit 1 fi else # Already running as root, just add the entry echo "📝 Adding ${DOMAIN} to ${HOSTS_FILE}..." echo "${HOSTS_ENTRY}" >> "${HOSTS_FILE}" fi # Verify the entry was added if grep -q "${DOMAIN}" "${HOSTS_FILE}"; then echo "✅ Successfully added ${DOMAIN} to hosts file" echo "" echo "Added entry:" grep "${DOMAIN}" "${HOSTS_FILE}" | tail -1 echo "" echo "✅ Setup complete!" echo "" echo "Next steps:" echo " 1. Start Docker services: docker-compose up -d" echo " 2. Test the domain: curl http://${DOMAIN}/health" echo " 3. Configure MT5 EA with: ApiBaseUrl = \"http://${DOMAIN}\"" else echo "❌ Failed to add entry to hosts file" exit 1 fi