diff --git a/bin/detect_ips.sh b/bin/detect_ips.sh index ef00e9c..0964e6b 100644 --- a/bin/detect_ips.sh +++ b/bin/detect_ips.sh @@ -6,38 +6,56 @@ if [ -z "$PUBLIC_IP" ]; then PUBLIC_IP=`dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com | sed 's|"||g'` fi -runOnMac=false int2ip() { printf ${2+-v} $2 "%d.%d.%d.%d" \ $(($1>>24)) $(($1>>16&255)) $(($1>>8&255)) $(($1&255)) ;} ip2int() { local _a=(${1//./ }) ; printf ${2+-v} $2 "%u" $(( _a<<24 | ${_a[1]} << 16 | ${_a[2]} << 8 | ${_a[3]} )) ;} -while IFS=$' :\t\r\n' read a b c d; do - [ "$a" = "usage" ] && [ "$b" = "route" ] && runOnMac=true - if $runOnMac ;then - case $a in - gateway ) gWay=$b ;; - interface ) iFace=$b ;; - esac - else - [ "$a" = "0.0.0.0" ] && [ "$c" = "$a" ] && iFace=${d##* } gWay=$b - fi -done < <(/sbin/route -n 2>&1 || /sbin/route -n get 0.0.0.0/0) -ip2int $gWay gw -while read lhs rhs; do - [ "$lhs" ] && { - [ -z "${lhs#*:}" ] && iface=${lhs%:} - [ "$lhs" = "inet" ] && [ "$iface" = "$iFace" ] && { - mask=${rhs#*netmask } - mask=${mask%% *} - [ "$mask" ] && [ -z "${mask%0x*}" ] && - printf -v mask %u $mask || + +case "$(uname -s)" in + Darwin*) + while IFS=$' :\t\r\n' read a b c d; do + case $a in + gateway ) gWay=$b ;; + interface ) iFace=$b ;; + esac + done < <(/sbin/route -n get 0.0.0.0/0) + ip2int $gWay gw + + while read lhs rhs; do + [ "$lhs" ] && { + [ -z "${lhs#*:}" ] && iface=${lhs%:} + [ "$lhs" = "inet" ] && [ "$iface" = "$iFace" ] && { + mask=${rhs#*netmask } + mask=${mask%% *} + [ "$mask" ] && [ -z "${mask%0x*}" ] && + printf -v mask %u $mask || + ip2int $mask mask + ip2int ${rhs%% *} ip + (( ( ip & mask ) == ( gw & mask ) )) && + int2ip $ip myIp && int2ip $mask netMask + } + } + done < <(/sbin/ifconfig) + ;; + *) + while IFS=$' :\t\r\n' read a b c d; do + [ "$a" = "0.0.0.0" ] && [ "$c" = "$a" ] && iFace=${d##* } gWay=$b + done < <(/sbin/route -n 2>&1) + ip2int $gWay gw + + while IFS=$' :\t\r\n' read iface state rhs; do + [ "$iface" = "$iFace" ] && { + ip2int "$(echo $rhs | cut -d '/' -f1)" ip + while IFS=$' :\t\r\n' read before netmask after; do + mask=$netmask + done < <(/usr/bin/ipcalc -n -b $rhs | grep Netmask) ip2int $mask mask - ip2int ${rhs%% *} ip - (( ( ip & mask ) == ( gw & mask ) )) && - int2ip $ip myIp && int2ip $mask netMask - } - } -done < <(/sbin/ifconfig) + (( ( ip & mask ) == ( gw & mask ) )) && + int2ip $ip myIp && int2ip $mask netMask + } + done < <(ip -4 -c=never -br addr) + ;; +esac echo "KADCAST_PUBLIC_ADDRESS=$PUBLIC_IP:9000" if [ -z "$myIp" ]; then diff --git a/node-installer.sh b/node-installer.sh index 0d227bd..a3217d1 100644 --- a/node-installer.sh +++ b/node-installer.sh @@ -82,6 +82,7 @@ echo "Checking prerequisites" update_pkg_database check_installed unzip unzip check_installed curl curl +check_installed ipcalc ipcalc check_installed jq jq check_installed route net-tools check_installed logrotate logrotate