Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace usage of outdated ifconfig with ip #129

Merged
merged 4 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 12 additions & 30 deletions bin/detect_ips.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,25 @@ if [[ -z "$PUBLIC_IP" || ! "$PUBLIC_IP" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]];
exit 1
fi

runOnMac=false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the fact that MacOS support was removed, but indeed it's out of node-installer scope

Copy link
Member

@HDauven HDauven Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the fact that MacOS support was removed, but indeed it's out of node-installer scope

There's a couple of pathways we can take. The easiest is to implement #27 if we use MacOS with the installer for dev purposes. Or we try to actually broaden support once everything is more "stable" in the future.

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]} )) ;}
$(($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)
[ "$a" = "0.0.0.0" ] && [ "$c" = "$a" ] && iFace=${d##* } gWay=$b
done < <(/sbin/route -n 2>&1)
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)
localIp="$($(which ip) -j -4 -br addr | jq -r ". | map(select(.ifname == \"$iFace\")) | .[].addr_info.[0].local")"
ip2int $localIp ip
mask="$($(which ipcalc) -n -b $localIp | grep Netmask | awk '{print $2}')"
ip2int $mask mask
(( ( ip & mask ) == ( gw & mask ) )) &&
int2ip $ip myIp && int2ip $mask netMask

echo "KADCAST_PUBLIC_ADDRESS=$PUBLIC_IP:9000"
if [ -z "$myIp" ]; then
echo "KADCAST_LISTEN_ADDRESS=$PUBLIC_IP:9000"
else
echo "KADCAST_LISTEN_ADDRESS=$myIp:9000"
fi

2 changes: 1 addition & 1 deletion node-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ update_pkg_database
check_installed unzip unzip
check_installed curl curl
check_installed route net-tools
check_installed ipcalc ipcalc
check_installed jq jq
check_installed logrotate logrotate
check_installed dig dnsutils

# Ensure dusk group and user exist
if ! id -u dusk >/dev/null 2>&1; then
Expand Down