Improve interface check
- Install iproute (for the "ip" command) in the unlikely cases that both "route" and "ip" commands are unavailable.
This commit is contained in:
parent
6e596825e2
commit
3bf17a75db
@ -107,6 +107,12 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
check_iface() {
|
check_iface() {
|
||||||
|
if ! command -v route >/dev/null 2>&1 && ! command -v ip >/dev/null 2>&1; then
|
||||||
|
(
|
||||||
|
set -x
|
||||||
|
yum -y -q install iproute >/dev/null || yum -y -q install iproute >/dev/null
|
||||||
|
)
|
||||||
|
fi
|
||||||
def_iface=$(route 2>/dev/null | grep -m 1 '^default' | grep -o '[^ ]*$')
|
def_iface=$(route 2>/dev/null | grep -m 1 '^default' | grep -o '[^ ]*$')
|
||||||
[ -z "$def_iface" ] && def_iface=$(ip -4 route list 0/0 2>/dev/null | grep -m 1 -Po '(?<=dev )(\S+)')
|
[ -z "$def_iface" ] && def_iface=$(ip -4 route list 0/0 2>/dev/null | grep -m 1 -Po '(?<=dev )(\S+)')
|
||||||
def_state=$(cat "/sys/class/net/$def_iface/operstate" 2>/dev/null)
|
def_state=$(cat "/sys/class/net/$def_iface/operstate" 2>/dev/null)
|
||||||
|
@ -96,6 +96,15 @@ check_os() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
check_iface() {
|
check_iface() {
|
||||||
|
if ! command -v route >/dev/null 2>&1 && ! command -v ip >/dev/null 2>&1; then
|
||||||
|
wait_for_apt
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
(
|
||||||
|
set -x
|
||||||
|
apt-get -yqq update || apt-get -yqq update
|
||||||
|
apt-get -yqq install iproute2 >/dev/null
|
||||||
|
)
|
||||||
|
fi
|
||||||
def_iface=$(route 2>/dev/null | grep -m 1 '^default' | grep -o '[^ ]*$')
|
def_iface=$(route 2>/dev/null | grep -m 1 '^default' | grep -o '[^ ]*$')
|
||||||
[ -z "$def_iface" ] && def_iface=$(ip -4 route list 0/0 2>/dev/null | grep -m 1 -Po '(?<=dev )(\S+)')
|
[ -z "$def_iface" ] && def_iface=$(ip -4 route list 0/0 2>/dev/null | grep -m 1 -Po '(?<=dev )(\S+)')
|
||||||
def_state=$(cat "/sys/class/net/$def_iface/operstate" 2>/dev/null)
|
def_state=$(cat "/sys/class/net/$def_iface/operstate" 2>/dev/null)
|
||||||
|
Loading…
Reference in New Issue
Block a user