From 3bf17a75db882da8c0a8ffd473aa25046a6a76e6 Mon Sep 17 00:00:00 2001 From: hwdsl2 Date: Tue, 4 Oct 2022 22:52:37 -0500 Subject: [PATCH] Improve interface check - Install iproute (for the "ip" command) in the unlikely cases that both "route" and "ip" commands are unavailable. --- vpnsetup_centos.sh | 6 ++++++ vpnsetup_ubuntu.sh | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/vpnsetup_centos.sh b/vpnsetup_centos.sh index dab8102..5f3a091 100755 --- a/vpnsetup_centos.sh +++ b/vpnsetup_centos.sh @@ -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) diff --git a/vpnsetup_ubuntu.sh b/vpnsetup_ubuntu.sh index 19b254e..87bcd83 100755 --- a/vpnsetup_ubuntu.sh +++ b/vpnsetup_ubuntu.sh @@ -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)