From 50ff2246ed233779829d23bd03ca1147f97aed3c Mon Sep 17 00:00:00 2001 From: Pig Monkey Date: Fri, 24 Jan 2025 17:47:28 -0800 Subject: [PATCH] do not enable wifi if an ethernet connection is still active The interface status and type of the up/down state change that triggers the script is irrelevant. --- .../networkmanager/files/wifi-wired-exclusive.sh | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) 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