Skip to content

Commit bb53003

Browse files
authored
fix(ip): improvements to ip command usage (#3570)
1 parent ef3f752 commit bb53003

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

lgsm/functions/check_ip.sh

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,22 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
1010

1111
info_game.sh
1212

13-
if [ ! -f "/bin/ip" ]; then
14-
ipcommand="/sbin/ip"
15-
else
16-
ipcommand="ip"
17-
fi
13+
ip_commands_array=( "/bin/ip" "/usr/sbin/ip" "ip")
14+
for ip_command in "${ip_commands_array[@]}"; do
15+
if [ "$(command -v ${ip_command} 2>/dev/null)" ]; then
16+
ipcommand="${ip_command}"
17+
break
18+
fi
19+
done
20+
21+
ethtool_commands_array=( "/bin/ethtool" "/usr/sbin/ethtool" "ethtool")
22+
for ethtool_command in "${ethtool_commands_array[@]}"; do
23+
if [ "$(command -v ${ethtool_command} 2>/dev/null)" ]; then
24+
ethtoolcommand="${ethtool_command}"
25+
break
26+
fi
27+
done
28+
1829
getip=$(${ipcommand} -o -4 addr | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
1930
getipwc=$(${ipcommand} -o -4 addr | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -vc 127.0.0)
2031

lgsm/functions/info_distro.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ if [ -d "${backupdir}" ]; then
234234
fi
235235

236236
# Network Interface name
237-
netint=$(ip -o addr | grep "${ip}" | awk '{print $2}')
238-
netlink=$(ethtool "${netint}" 2>/dev/null| grep Speed | awk '{print $2}')
237+
netint=$(${ipcommand} -o addr | grep "${ip}" | awk '{print $2}')
238+
netlink=$(${ethtoolcommand} "${netint}" 2>/dev/null| grep Speed | awk '{print $2}')
239239

240240
# External IP address
241241
if [ -z "${extip}" ]; then

tests/tests_jc2server.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,10 +1070,10 @@ echo -e "================================="
10701070
echo -e "Description:"
10711071
echo -e "Inserting Travis IP in to config."
10721072
echo -e "Allows monitor to work"
1073-
if [ "$(ip -o -4 addr|grep eth0)" ]; then
1074-
travisip=$(ip -o -4 addr | grep eth0 | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | grep -v 127.0.0)
1073+
if [ "$(${ipcommand}-o -4 addr|grep eth0)" ]; then
1074+
travisip=$(${ipcommand}-o -4 addr | grep eth0 | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | grep -v 127.0.0)
10751075
else
1076-
travisip=$(ip -o -4 addr | grep ens | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
1076+
travisip=$(${ipcommand}-o -4 addr | grep ens | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
10771077
fi
10781078
sed -i "/BindIP/c\BindIP = \"${travisip}\"," "${serverfiles}/config.lua"
10791079
echo -e "IP: ${travisip}"

tests/tests_mcserver.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -933,10 +933,10 @@ echo -e "================================="
933933
echo -e "Description:"
934934
echo -e "Inserting Travis IP in to config."
935935
echo -e "Allows monitor to work"
936-
if [ "$(ip -o -4 addr|grep eth0)" ]; then
937-
travisip=$(ip -o -4 addr | grep eth0 | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | grep -v 127.0.0)
936+
if [ "$(${ipcommand}-o -4 addr|grep eth0)" ]; then
937+
travisip=$(${ipcommand}-o -4 addr | grep eth0 | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | grep -v 127.0.0)
938938
else
939-
travisip=$(ip -o -4 addr | grep ens | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
939+
travisip=$(${ipcommand}-o -4 addr | grep ens | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
940940
fi
941941
sed -i "/server-ip=/c\server-ip=${travisip}" "${serverfiles}/server.properties"
942942
echo -e "IP: ${travisip}"
@@ -1167,10 +1167,10 @@ echo -e "================================="
11671167
echo -e "Description:"
11681168
echo -e "Inserting Travis IP in to config."
11691169
echo -e "Allows monitor to work"
1170-
if [ "$(ip -o -4 addr|grep eth0)" ]; then
1171-
travisip=$(ip -o -4 addr | grep eth0 | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | grep -v 127.0.0)
1170+
if [ "$(${ipcommand}-o -4 addr|grep eth0)" ]; then
1171+
travisip=$(${ipcommand}-o -4 addr | grep eth0 | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | grep -v 127.0.0)
11721172
else
1173-
travisip=$(ip -o -4 addr | grep ens | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
1173+
travisip=$(${ipcommand}-o -4 addr | grep ens | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
11741174
fi
11751175
sed -i "/server-ip=/c\server-ip=${travisip}" "${serverfiles}/server.properties"
11761176
echo -e "IP: ${travisip}"

0 commit comments

Comments
 (0)