Selaa lähdekoodia

fix(ip): improvements to ip command usage (#3570)

Daniel Gibbs 4 vuotta sitten
vanhempi
commit
bb5300300c
4 muutettua tiedostoa jossa 27 lisäystä ja 16 poistoa
  1. 16 5
      lgsm/functions/check_ip.sh
  2. 2 2
      lgsm/functions/info_distro.sh
  3. 3 3
      tests/tests_jc2server.sh
  4. 6 6
      tests/tests_mcserver.sh

+ 16 - 5
lgsm/functions/check_ip.sh

@@ -10,11 +10,22 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
 info_game.sh
 
-if [ ! -f "/bin/ip" ]; then
-	ipcommand="/sbin/ip"
-else
-	ipcommand="ip"
-fi
+ip_commands_array=( "/bin/ip" "/usr/sbin/ip" "ip")
+for ip_command in "${ip_commands_array[@]}"; do
+	if [ "$(command -v ${ip_command} 2>/dev/null)" ]; then
+		ipcommand="${ip_command}"
+		break
+	fi
+done
+
+ethtool_commands_array=( "/bin/ethtool" "/usr/sbin/ethtool" "ethtool")
+for ethtool_command in "${ethtool_commands_array[@]}"; do
+	if [ "$(command -v ${ethtool_command} 2>/dev/null)" ]; then
+		ethtoolcommand="${ethtool_command}"
+		break
+	fi
+done
+
 getip=$(${ipcommand} -o -4 addr | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
 getipwc=$(${ipcommand} -o -4 addr | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -vc 127.0.0)
 

+ 2 - 2
lgsm/functions/info_distro.sh

@@ -234,8 +234,8 @@ if [ -d "${backupdir}" ]; then
 fi
 
 # Network Interface name
-netint=$(ip -o addr | grep "${ip}" | awk '{print $2}')
-netlink=$(ethtool "${netint}" 2>/dev/null| grep Speed | awk '{print $2}')
+netint=$(${ipcommand} -o addr | grep "${ip}" | awk '{print $2}')
+netlink=$(${ethtoolcommand} "${netint}" 2>/dev/null| grep Speed | awk '{print $2}')
 
 # External IP address
 if [ -z "${extip}" ]; then

+ 3 - 3
tests/tests_jc2server.sh

@@ -1070,10 +1070,10 @@ echo -e "================================="
 echo -e "Description:"
 echo -e "Inserting Travis IP in to config."
 echo -e "Allows monitor to work"
-if [ "$(ip -o -4 addr|grep eth0)" ]; then
-	travisip=$(ip -o -4 addr | grep eth0 | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | grep -v 127.0.0)
+if [ "$(${ipcommand}-o -4 addr|grep eth0)" ]; then
+	travisip=$(${ipcommand}-o -4 addr | grep eth0 | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | grep -v 127.0.0)
 else
-	travisip=$(ip -o -4 addr | grep ens | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
+	travisip=$(${ipcommand}-o -4 addr | grep ens | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
 fi
 sed -i "/BindIP/c\BindIP                      = \"${travisip}\"," "${serverfiles}/config.lua"
 echo -e "IP: ${travisip}"

+ 6 - 6
tests/tests_mcserver.sh

@@ -933,10 +933,10 @@ echo -e "================================="
 echo -e "Description:"
 echo -e "Inserting Travis IP in to config."
 echo -e "Allows monitor to work"
-if [ "$(ip -o -4 addr|grep eth0)" ]; then
-	travisip=$(ip -o -4 addr | grep eth0 | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | grep -v 127.0.0)
+if [ "$(${ipcommand}-o -4 addr|grep eth0)" ]; then
+	travisip=$(${ipcommand}-o -4 addr | grep eth0 | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | grep -v 127.0.0)
 else
-	travisip=$(ip -o -4 addr | grep ens | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
+	travisip=$(${ipcommand}-o -4 addr | grep ens | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
 fi
 sed -i "/server-ip=/c\server-ip=${travisip}" "${serverfiles}/server.properties"
 echo -e "IP: ${travisip}"
@@ -1167,10 +1167,10 @@ echo -e "================================="
 echo -e "Description:"
 echo -e "Inserting Travis IP in to config."
 echo -e "Allows monitor to work"
-if [ "$(ip -o -4 addr|grep eth0)" ]; then
-	travisip=$(ip -o -4 addr | grep eth0 | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | grep -v 127.0.0)
+if [ "$(${ipcommand}-o -4 addr|grep eth0)" ]; then
+	travisip=$(${ipcommand}-o -4 addr | grep eth0 | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | grep -v 127.0.0)
 else
-	travisip=$(ip -o -4 addr | grep ens | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
+	travisip=$(${ipcommand}-o -4 addr | grep ens | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
 fi
 sed -i "/server-ip=/c\server-ip=${travisip}" "${serverfiles}/server.properties"
 echo -e "IP: ${travisip}"