Last active
February 28, 2019 10:42
-
-
Save xymopen/ee2eb5d60edfb66069bf823cf2e0f52e to your computer and use it in GitHub Desktop.
Automatically switch on or off Wi-Fi according to an interface. Helpful if your mobile phone won't switch to mobile data if there is no internet access from Wi-Fi.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# wifi_switch.sh | |
# hotplug.d script | |
# Automatically switch on or off wifi according to an interface | |
# helpful if your mobile phone won't switch to mobile data if there is no internet access from wifi | |
# Version : 2.2.0 | |
# Author : xymopen <[email protected]> | |
# Licensed : BSD 2-clause License | |
logger -t "wifi_switch" -s "action=${ACTION} device=${DEVICE} network=${INTERFACE}" | |
disable_each_wifi_iface () { | |
local mode | |
config_get mode "$1" mode | |
if [ "$mode" = "ap" ]; then | |
uci_set wireless "$1" disabled 1 | |
fi | |
} | |
enable_each_wifi_iface () { | |
local mode | |
config_get mode "$1" mode | |
if [ "$mode" = "ap" ]; then | |
uci_set wireless "$1" disabled 0 | |
fi | |
} | |
WAN_IF="wan" | |
if [[ "${INTERFACE}" = "${WAN_IF}" ]]; then | |
. /lib/functions.sh | |
case "${ACTION}" in | |
"ifup") | |
logger -t "wifi_switch" -s "wan is up. bring up wifi..." | |
config_load wireless | |
config_foreach enable_each_wifi_iface wifi-iface | |
uci_commit wireless | |
/etc/init.d/network reload | |
;; | |
"ifdown") | |
logger -t "wifi_switch" -s "wan is down. shut down wifi..." | |
config_load wireless | |
config_foreach disable_each_wifi_iface wifi-iface | |
uci_commit wireless | |
/etc/init.d/network reload | |
;; | |
# use "connected" and "disconnected" for better | |
# Internet connection detection if you have mwan3 | |
esac | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment