configure-linux 996 B

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