1
0
mirror of synced 2024-11-21 20:46:10 +03:00

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:
hwdsl2 2022-10-04 22:52:37 -05:00
parent 6e596825e2
commit 3bf17a75db
2 changed files with 15 additions and 0 deletions

View File

@ -107,6 +107,12 @@ EOF
}
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 '[^ ]*$')
[ -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)

View File

@ -96,6 +96,15 @@ check_os() {
}
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 '[^ ]*$')
[ -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)