Skip to content

Instantly share code, notes, and snippets.

@varqox
Last active April 4, 2019 00:27
Show Gist options
  • Save varqox/74c63347d47c135545039dcfff9b0fb5 to your computer and use it in GitHub Desktop.
Save varqox/74c63347d47c135545039dcfff9b0fb5 to your computer and use it in GitHub Desktop.
Network Manager enable wifi on ethernet (LAN) disconnect and disable it on ethernet (LAN) connect, works with openvpn (VPN) and disconnecting cable when laptop is suspended
#!/bin/sh
# Place in file: /etc/NetworkManager/dispatcher.d/pre-up.d/wlan_auto_block.sh
# Make the file safe for execution: sudo chmod 744 /etc/NetworkManager/dispatcher.d/pre-up.d/wlan_auto_block.sh
if [ "$1" = "enp3s0" ]; then
rfkill block wifi # rfkill is used for unblocking, so we have to use it for blocking
fi
#!/bin/sh
# Place in file: /etc/NetworkManager/dispatcher.d/wlan_auto_unblock.sh
# Make the file safe for execution: sudo chmod 744 /etc/NetworkManager/dispatcher.d/wlan_auto_unblock.sh
if [ "$1" = "enp3s0" ]; then
if [ "$2" = "down" ]; then
rfkill unblock wifi # nmcli radio wifi on does not work during suspending
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment