configure-linux 1.1 KB

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env bash
  2. # Check if the script is running on Linux
  3. if [[ "$OSTYPE" == "linux-gnu"* ]]; then
  4. # Get the IP address from the Docker container
  5. docker_ip=$(docker run --rm alpine ip route | awk 'NR==1 {print $3}')
  6. # Check if the IP address already exists in /etc/hosts
  7. if grep -q "$docker_ip host.docker.internal" /etc/hosts; then
  8. echo "The entry already exists in /etc/hosts. No action needed."
  9. else
  10. # Add a new entry to /etc/hosts
  11. echo "$docker_ip host.docker.internal" | sudo tee -a /etc/hosts
  12. echo "A new entry in the /etc/hosts file has been created"
  13. fi
  14. # Ask the user whether to execute the iptables command
  15. read -r -p "Do you want to open port 9003 for Xdebug? (y/n): " choice
  16. if [ "$choice" == "y" ]; then
  17. sudo iptables -A INPUT -p tcp --dport 9003 -j ACCEPT
  18. echo "Port 9003 has been opened for xdebug."
  19. fi
  20. elif [[ "$OSTYPE" == "darwin"* ]]; then
  21. echo "This script is designed for Linux and may not work properly on macOS."
  22. else
  23. echo "Unsupported operating system."
  24. fi
  25. echo "Tasks completed successfully"