-
-
Save abstrask/6a65184ca52d4b0c3c98 to your computer and use it in GitHub Desktop.
Scripts for OpenWrt on TP-Link TL-MR3020 to change network configs using 3-position sliding switch. Configuration changes by UCI/LuCI overwrites the symbolic links used by original scripts. This version copies the scripts instead of using symbolic links. Added script attached to WPS button, to commit the updated config to the current config (3g,…
This file contains 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 | |
grep -qe "sw1.*in hi" /sys/kernel/debug/gpio |
This file contains 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 | |
grep -qe "sw2.*in hi" /sys/kernel/debug/gpio |
This file contains 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 | |
# Commits network config files to subfolder of current config (3g, ap or wisp) | |
ME=$(basename $0) | |
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin | |
if BTN_1_pressed ; then | |
if BTN_0_pressed ; then | |
CONFIG=ap | |
else | |
CONFIG=wisp | |
fi | |
else | |
CONFIG=3g | |
fi | |
SRC=/etc/config | |
DEST="/etc/config/$CONFIG" | |
logger -t "$ME" "Commited network config files to '$CONFIG'" | |
cp $SRC/network $DEST/network | |
cp $SRC/wireless $DEST/wireless | |
. /etc/diag.sh | |
get_status_led | |
status_led_on | |
sleep 2 | |
status_led_off |
This file contains 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 /etc/rc.common | |
START=15 | |
boot() { | |
/usr/local/sbin/set_network_config | |
} |
This file contains 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 | |
# based on https://forum.openwrt.org/viewtopic.php?pid=172111#p172111 | |
ME=$(basename $0) | |
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin | |
if BTN_1_pressed ; then | |
if BTN_0_pressed ; then | |
CONFIG=ap | |
else | |
CONFIG=wisp | |
fi | |
else | |
CONFIG=3g | |
fi | |
SRC="/etc/config/$CONFIG" | |
DEST=/etc/config | |
if [ ! -d "$SRC" ] ; then | |
logger -t "$ME" -p "user.warn" "$SRC is not a directory" | |
exit 1 | |
fi | |
logger -t "$ME" "Using $CONFIG config" | |
cp $SRC/network $DEST/network | |
cp $SRC/wireless $DEST/wireless |
This file contains 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
# Forked from https://gist.github.com/jefferyto/8010733 | |
# Configuration changes by UCI/LuCI overwrites the symbolic links used by original scripts. | |
# This version copies the scripts instead of using symbolic links. | |
# Added script attached to WPS button, to commit the updated config to the current config (3g, ap or wisp) subfolder. | |
# Instructions: | |
# 1. Copy all project files into /tmp, e.g. using SCP | |
# 2. Open a terminal session to the router | |
# 3. Run the commands below | |
#Prep files and sort them into appropriate folders | |
cd /tmp | |
chmod a+x BTN_0_pressed BTN_1_pressed set_network_config update_network_config network_config commit_config2folder | |
mkdir -p /usr/local/sbin | |
mv BTN_0_pressed BTN_1_pressed set_network_config update_network_config commit_config2folder /usr/local/sbin | |
mkdir -p /etc/hotplug.d/button | |
mv 00-button /etc/hotplug.d/button | |
mv network_config /etc/init.d | |
#Instal flock, needed for network config script | |
opkg update | |
opkg install flock | |
#Copy current 'network' and 'wireless' config into '3g', 'ap' and 'wisp' folders | |
cd /etc/config | |
mkdir /etc/config/3g | |
cp network wireless 3g | |
cp -r 3g wisp | |
cp -r 3g ap | |
/etc/init.d/network_config enable | |
#Add buttons for sliding switch | |
uci add system button | |
uci set system.@button[-1].button=3g | |
uci set system.@button[-1].action=pressed | |
uci set system.@button[-1].handler=update_network_config | |
uci add system button | |
uci set system.@button[-1].button=wisp | |
uci set system.@button[-1].action=pressed | |
uci set system.@button[-1].handler=update_network_config | |
uci add system button | |
uci set system.@button[-1].button=ap | |
uci set system.@button[-1].action=pressed | |
uci set system.@button[-1].handler=update_network_config | |
#Add WPS button to commit config to folder | |
uci add system button | |
uci set system.@button[-1].button=wps | |
uci set system.@button[-1].action=released | |
uci set system.@button[-1].handler=commit_config2folder | |
uci set system.@button[-1].min=1 | |
uci set system.@button[-1].max=3 | |
#Commit config and reboot | |
uci commit system | |
reboot |
This file contains 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 | |
ME=$(basename $0) | |
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin | |
( | |
flock -n 9 || exit 1 | |
( | |
sleep 1 | |
if set_network_config ; then | |
. /etc/diag.sh | |
get_status_led | |
status_led_set_timer 200 200 | |
logger -t "$ME" "Reloading network" | |
/etc/init.d/network restart | |
status_led_on | |
sleep 2 | |
status_led_off | |
fi | |
) 9>&- | |
) 9>/tmp/update_network_config.lock |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment