From 82a76598fa836032a1d29f3319cf28aa5bedc2d5 Mon Sep 17 00:00:00 2001 From: Alexandre CATTEAU Date: Wed, 16 Mar 2022 18:22:50 +0100 Subject: [PATCH] Initial commit --- .gitignore | 1 + README.md | 12 ++++++++++++ auto-disable-wifi.sh | 15 +++++++++++++++ install.sh | 20 ++++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 auto-disable-wifi.sh create mode 100755 install.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a4603f7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.disabled diff --git a/README.md b/README.md new file mode 100644 index 0000000..915557c --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Auto-disable Wi-Fi + +Script for NetworkManager, which disables Wi-Fi when a wired connection comes up, and enables Wi-Fi when a wired +connection comed down. + +### Files +* `auto-disable-wifi` should be installed to NetworkManager directory. +#### Installation +* `install.sh` script copies above script to its destination. + +### TODO +* Nothing diff --git a/auto-disable-wifi.sh b/auto-disable-wifi.sh new file mode 100644 index 0000000..9153755 --- /dev/null +++ b/auto-disable-wifi.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +wired_interfaces="en.*|eth.*" +if [[ "$1" =~ $wired_interfaces ]]; then + case "$2" in + up) + #nmcli radio wifi off + rfkill block wifi + ;; + down) + #nmcli radio wifi on + rfkill unblock wifi + ;; + esac +fi diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..ea85e83 --- /dev/null +++ b/install.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +run_directory=$(dirname "$0") + +if [ -f $run_directory/.disabled ]; then + echo "Installation is disabled. Exiting..." + exit 0 +fi + +echo "Copying script to NetworkManager directory..." +sudo cp $run_directory/auto-disable-wifi.sh /etc/NetworkManager/dispatcher.d/99-auto-disable-wifi +sudo chown root:root /etc/NetworkManager/dispatcher.d/99-auto-disable-wifi +sudo chmod 744 /etc/NetworkManager/dispatcher.d/99-auto-disable-wifi + +if ! command -v rfkill &> /dev/null; then + echo "WARNING: rfkill is not installed." +fi + +echo "Finished install. Exiting..." +exit 0