Explorar o código

Fix duplicate entries in the file

evgeniy hai 1 ano
pai
achega
e8011d7ee7
Modificáronse 1 ficheiros con 8 adicións e 3 borrados
  1. 8 3
      compose/bin/extra-settings

+ 8 - 3
compose/bin/extra-settings

@@ -3,9 +3,14 @@
 # Get the IP address from the Docker container
 # Get the IP address from the Docker container
 docker_ip=$(docker run --rm alpine ip route | awk 'NR==1 {print $3}')
 docker_ip=$(docker run --rm alpine ip route | awk 'NR==1 {print $3}')
 
 
-# Add a new entry to /etc/hosts
-echo "$docker_ip host.docker.internal" | sudo tee -a /etc/hosts
-echo "A new entry in the /etc/hosts file has been created"
+# Check if the IP address already exists in /etc/hosts
+if grep -q "$docker_ip host.docker.internal" /etc/hosts; then
+    echo "The entry already exists in /etc/hosts. No action needed."
+else
+    # Add a new entry to /etc/hosts
+    echo "$docker_ip host.docker.internal" | sudo tee -a /etc/hosts
+    echo "A new entry in the /etc/hosts file has been created"
+fi
 
 
 # Ask the user whether to execute the iptables command
 # Ask the user whether to execute the iptables command
 read -p "Do you want to open port 9003 for xdebug? (y/n): " choice
 read -p "Do you want to open port 9003 for xdebug? (y/n): " choice