Created
May 1, 2015 08:27
-
-
Save caelor/e98dc3d30d1ea17e34f5 to your computer and use it in GitHub Desktop.
OpenWRT mr3020 Switchable configs on boot
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 | |
# filename: /etc/init.d/modeswitch | |
START=15 | |
boot() { | |
# process user commands | |
[ -f /root/switchable_config.sh ] && { | |
sh /root/switchable_config.sh | |
} | |
} |
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
1) Create the files /root/switchable_config.sh and /etc/init.d/modeswitch | |
2) /etc/init.d/modeswitch enable to enable the 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 | |
# filename: /root/switchable_config.sh | |
# Mode GPIO18 GPIO20 | |
# sw1 sw2 | |
# 3G 1 0 | |
# WISP 0 1 | |
# AP 1 1 | |
dolog() { | |
echo "$1" | |
logger -t modeswitch "$1" | |
} | |
MODE="3g" | |
if grep -qe "sw2.*in hi" /sys/kernel/debug/gpio ; then | |
# sw2 is hi, so either WISP or AP mode | |
if grep -qe "sw1.*in hi" /sys/kernel/debug/gpio ; then | |
MODE="ap" | |
else | |
MODE="wisp" | |
fi | |
fi | |
dolog "Current switch mode: $MODE" | |
OLDMODE="unknown" | |
if [ -f /root/boot.switch_position ] ; then | |
OLDMODE=$(cat /root/boot.switch_position) | |
fi | |
if [ "$OLDMODE" == "$MODE" ] ; then | |
dolog "Mode is unchanged. Leaving configs unmodified." | |
else | |
dolog "Mode has changed $OLDMODE -> $MODE" | |
echo "$MODE" > /root/boot.switch_position | |
DESTFILE="/root/boot.backup_$OLDMODE.tgz" | |
dolog "Backing up old config to $DESTFILE" | |
sysupgrade -b $DESTFILE | |
ORIGINFILE="/root/boot.backup_$MODE.tgz" | |
if [ -f "$ORIGINFILE" ] ; then | |
dolog "Restoring previously saved config for $MODE ($ORIGINFILE)" | |
sysupgrade -r $ORIGINFILE | |
# needed to reapply potentially changed system level | |
/etc/init.d/system restart | |
else | |
dolog "No previously saved config for $MODE. Inheriting config from $OLDMODE" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment