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.
This commit is contained in:
Pig Monkey 2025-01-24 17:47:28 -08:00
parent 86ccff0e37
commit 50ff2246ed

View file

@ -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