From d711e2aee6e608449d90b196515f731b994d398d Mon Sep 17 00:00:00 2001 From: hwdsl2 Date: Wed, 17 May 2017 17:24:19 -0500 Subject: [PATCH] Improve network interfaces - Try to auto detect server's default network interface - Display a warning if the default interface is wlan* --- vpnsetup.sh | 32 ++++++++++++++++++++++++-------- vpnsetup_centos.sh | 32 ++++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/vpnsetup.sh b/vpnsetup.sh index c95b7d7..51a7435 100755 --- a/vpnsetup.sh +++ b/vpnsetup.sh @@ -68,20 +68,36 @@ if [ "$(id -u)" != 0 ]; then fi NET_IFACE=${VPN_NET_IFACE:-'eth0'} +DEF_IFACE="$(route | grep '^default' | grep -o '[^ ]*$')" -if_state=$(cat "/sys/class/net/$NET_IFACE/operstate" 2>/dev/null) -if [ -z "$if_state" ] || [ "$if_state" = "down" ] || [ "$NET_IFACE" = "lo" ]; then - printf "Error: Network interface '%s' is not available.\n\n" "$NET_IFACE" >&2 -cat 1>&2 <<'EOF' +if_state1=$(cat "/sys/class/net/$DEF_IFACE/operstate" 2>/dev/null) +if [ -z "$VPN_NET_IFACE" ] && [ -n "$if_state1" ] && [ "$if_state1" != "down" ]; then + case "$DEF_IFACE" in + wlan*) + printf "Error: Default network interface '%s' detected.\n\n" "$DEF_IFACE" >&2 +cat 1>&2 </dev/null) +if [ -z "$if_state2" ] || [ "$if_state2" = "down" ] || [ "$NET_IFACE" = "lo" ]; then + printf "Error: Network interface '%s' is not available.\n\n" "$NET_IFACE" >&2 + if [ -z "$VPN_NET_IFACE" ]; then cat 1>&2 </dev/null) -if [ -z "$if_state" ] || [ "$if_state" = "down" ] || [ "$NET_IFACE" = "lo" ]; then - printf "Error: Network interface '%s' is not available.\n\n" "$NET_IFACE" >&2 -cat 1>&2 <<'EOF' +if_state1=$(cat "/sys/class/net/$DEF_IFACE/operstate" 2>/dev/null) +if [ -z "$VPN_NET_IFACE" ] && [ -n "$if_state1" ] && [ "$if_state1" != "down" ]; then + case "$DEF_IFACE" in + wlan*) + printf "Error: Default network interface '%s' detected.\n\n" "$DEF_IFACE" >&2 +cat 1>&2 </dev/null) +if [ -z "$if_state2" ] || [ "$if_state2" = "down" ] || [ "$NET_IFACE" = "lo" ]; then + printf "Error: Network interface '%s' is not available.\n\n" "$NET_IFACE" >&2 + if [ -z "$VPN_NET_IFACE" ]; then cat 1>&2 <