diff --git a/roles/networkmanager/files/wifi-wired-exclusive.sh b/roles/networkmanager/files/wifi-wired-exclusive.sh index 9d4cc8c..e47d160 100755 --- a/roles/networkmanager/files/wifi-wired-exclusive.sh +++ b/roles/networkmanager/files/wifi-wired-exclusive.sh @@ -10,7 +10,6 @@ if [ -f "$skip_filename" ]; then exit 0 fi -interface="$1" action="$2" # Bail out if the action is not either up or down. @@ -18,13 +17,10 @@ if [[ "$action" != "up" && "$action" != "down" ]]; then exit 0 fi -iface_type=$(nmcli dev | grep "^$interface" | tr -s ' ' | cut -d' ' -f2) -iface_state=$(nmcli dev | grep "^$interface" | tr -s ' ' | cut -d' ' -f3) - -echo "$syslog_tag: Interface $interface = $iface_state ($iface_type) is $action" +active_ethernet=$(nmcli conn show --active | tr -s ' ' | cut -d' ' -f3 | grep ethernet) enable_wifi() { - echo "$syslog_tag: Interface $interface ($iface_type) is down, enabling wifi." + echo "$syslog_tag: No active ethernet connections, enabling wifi." nmcli radio wifi on } @@ -33,8 +29,8 @@ disable_wifi() { nmcli radio wifi off } -if [[ "$iface_type" = "ethernet" || -z "$iface_type" ]] && [ "$action" = "down" ]; then - enable_wifi -elif [ "$iface_type" = "ethernet" ] && [ "$action" = "up" ] && [ "$iface_state" = "connected" ]; then - disable_wifi +if [ -z "$active_ethernet" ]; then + enable_wifi +else + disable_wifi fi