mirror of
https://github.com/pigmonkey/spark.git
synced 2026-01-22 18:14:16 +00:00
toggle wifi on ethernet via networkmanager
Required only for the brave new post-TLP world.
This commit is contained in:
parent
3cab47b5ba
commit
ea622e65c1
3 changed files with 48 additions and 0 deletions
|
|
@ -53,6 +53,7 @@ mail:
|
|||
|
||||
network:
|
||||
conn_check: False
|
||||
wifi_wired_exclusive: True
|
||||
trusted_uuid:
|
||||
- 39744b35-2f2f-4a18-9da4-7542a56c28c2
|
||||
- d2642f7e-9e58-4b00-82f8-26b4ef76a54e
|
||||
|
|
|
|||
40
roles/networkmanager/files/wifi-wired-exclusive.sh
Executable file
40
roles/networkmanager/files/wifi-wired-exclusive.sh
Executable file
|
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env bash
|
||||
# Stolen from Ilija Matoski:
|
||||
# https://www.matoski.com/article/wifi-ethernet-autoswitch/
|
||||
|
||||
name_tag="wifi-wired-exclusive"
|
||||
syslog_tag="$name_tag"
|
||||
skip_filename="/etc/NetworkManager/.$name_tag"
|
||||
|
||||
if [ -f "$skip_filename" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
interface="$1"
|
||||
action="$2"
|
||||
|
||||
# Bail out if the action is not either up or down.
|
||||
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"
|
||||
|
||||
enable_wifi() {
|
||||
echo "$syslog_tag: Interface $interface ($iface_type) is down, enabling wifi."
|
||||
nmcli radio wifi on
|
||||
}
|
||||
|
||||
disable_wifi() {
|
||||
echo "$syslog_tag: Disabling wifi, ethernet connection detected."
|
||||
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
|
||||
fi
|
||||
|
|
@ -19,6 +19,13 @@
|
|||
src: random_mac.conf.j2
|
||||
dest: /etc/NetworkManager/conf.d/20-random_mac.conf
|
||||
|
||||
- name: Push WiFi/Wired Exclusive dispatcher
|
||||
copy:
|
||||
src: wifi-wired-exclusive.sh
|
||||
dest: /etc/NetworkManager/dispatcher.d/70-wifi-wired-exclusive
|
||||
mode: 0755
|
||||
when: network.wifi_wired_exclusive is defined and network.wifi_wired_exclusive == True
|
||||
|
||||
- name: Enable and start NetworkManager
|
||||
service:
|
||||
name: NetworkManager.service
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue