From c2a676bb6741f022dead7d0cd9bc9e86e6dd4969 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Thu, 25 Jul 2024 01:34:03 -0600 Subject: [PATCH] refactor: update install.sh --- public/install.sh | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/public/install.sh b/public/install.sh index 0ec0e7f..fecb188 100644 --- a/public/install.sh +++ b/public/install.sh @@ -47,7 +47,21 @@ fi docker swarm leave --force 2>/dev/null -advertise_addr=$(curl -s ifconfig.me) +get_ip() { + # Try to get IPv4 + local ipv4=$(curl -4s https://ifconfig.io 2>/dev/null) + + if [ -n "$ipv4" ]; then + echo "$ipv4" + else + # Try to get IPv6 + local ipv6=$(curl -6s https://ifconfig.io 2>/dev/null) + if [ -n "$ipv6" ]; then + echo "$ipv6" + fi +} + +advertise_addr=$(get_ip) docker swarm init --advertise-addr $advertise_addr @@ -84,9 +98,20 @@ YELLOW="\033[1;33m" BLUE="\033[0;34m" NC="\033[0m" # No Color +format_ip_for_url() { + local ip="$1" + if [[ $ip =~ : ]]; then + # IPv6 + echo "[${ip}]" + else + # IPv4 + echo "${ip}" + fi +} +formatted_addr=$(format_ip_for_url "$advertise_addr") echo "" printf "${GREEN}Congratulations, Dokploy is installed!${NC}\n" printf "${BLUE}Wait 15 seconds for the server to start${NC}\n" -printf "${YELLOW}Please go to http://${advertise_addr}:3000${NC}\n\n" +printf "${YELLOW}Please go to http://${formatted_addr}:3000${NC}\n\n" echo ""