From deb2f75eb928b4f7dce4ed520a28b82514f82659 Mon Sep 17 00:00:00 2001 From: hwdsl2 Date: Fri, 10 Jun 2016 22:05:26 -0500 Subject: [PATCH] Improve eth0 detection --- vpnsetup.sh | 3 ++- vpnsetup_centos.sh | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/vpnsetup.sh b/vpnsetup.sh index d5da22d..76f9cf2 100755 --- a/vpnsetup.sh +++ b/vpnsetup.sh @@ -53,7 +53,8 @@ if [ "$(id -u)" != 0 ]; then exit 1 fi -if [ ! -f /sys/class/net/eth0/operstate ]; then +eth0_state=$(cat /sys/class/net/eth0/operstate 2>/dev/null) +if [ -z "$eth0_state" ] || [ "$eth0_state" = "down" ]; then cat 1>&2 <<'EOF' Network interface 'eth0' is not available. Aborting. diff --git a/vpnsetup_centos.sh b/vpnsetup_centos.sh index 626ae03..3704164 100755 --- a/vpnsetup_centos.sh +++ b/vpnsetup_centos.sh @@ -57,7 +57,8 @@ if [ "$(id -u)" != 0 ]; then exit 1 fi -if [ ! -f /sys/class/net/eth0/operstate ]; then +eth0_state=$(cat /sys/class/net/eth0/operstate 2>/dev/null) +if [ -z "$eth0_state" ] || [ "$eth0_state" = "down" ]; then cat 1>&2 <<'EOF' Network interface 'eth0' is not available. Aborting.