From 7a9eff611387b46fa8faa309d436556944239f45 Mon Sep 17 00:00:00 2001 From: liuyu <> Date: Fri, 1 Nov 2024 20:19:11 +0800 Subject: [PATCH] fix: compatible with MacOS Bash and raspbian for the change ip --- build/installer/change_ip.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/build/installer/change_ip.sh b/build/installer/change_ip.sh index 01fb0203..6f8046af 100644 --- a/build/installer/change_ip.sh +++ b/build/installer/change_ip.sh @@ -101,9 +101,12 @@ precheck_os() { ensure_success $sh_c "hostname -i >/dev/null" local ip=$(ping -c 1 "$HOSTNAME" |awk -F '[()]' '/icmp_seq/{print $2}') - printf "%s\t%s\n\n" "$ip" "$HOSTNAME" + if [ x"$ip" == x"" ]; then + ip=$(ping -c 1 "$HOSTNAME" |awk -F '[()]' '/PING/{print $2}') + fi + printf "%s\t%s\n\n" "$ip" "$HOSTNAME" - if [[ x"$ip" == x"" || "$ip" == @("172.17.0.1"|"127.0.0.1"|"127.0.1.1") || ! "$ip" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + if [[ x"$ip" == x"" || "$ip" == "172.17.0.1" || "$ip" == "127.0.0.1" || "$ip" == "127.0.1.1" || ! "$ip" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then log_fatal "incorrect ip for hostname '$HOSTNAME', please check" fi @@ -131,6 +134,7 @@ is_wsl(){ } is_macos(){ + local os_type=$(uname -s) if [[ "$os_type" == "Darwin" ]]; then echo 1 return