[PATCH v3 14/14] fff-network: Migrate old settings
Adrian Schmutzler
freifunk at adrianschmutzler.de
Mo Apr 22 23:01:45 CEST 2019
This patch will migrate the custom settings from network.config
to the new configuration system.
The uci-default script only writes to /etc/firstbootfff, as this
is evaluated later in the uci-defaults run; it does not directly
apply any settings.
By writing to /etc/firstbootfff, the settings are still kept in
an upgrade-safe way.
Signed-off-by: Adrian Schmutzler <freifunk at adrianschmutzler.de>
---
Changes in v3:
- Added this patch
This is now the correct version of this patch. Note that this is
completely untested so far.
---
.../files/etc/uci-defaults/25-migrate-network | 56 ++++++++++++++++++++++
1 file changed, 56 insertions(+)
create mode 100644 src/packages/fff/fff-network/files/etc/uci-defaults/25-migrate-network
diff --git a/src/packages/fff/fff-network/files/etc/uci-defaults/25-migrate-network b/src/packages/fff/fff-network/files/etc/uci-defaults/25-migrate-network
new file mode 100644
index 00000000..2c0309e5
--- /dev/null
+++ b/src/packages/fff/fff-network/files/etc/uci-defaults/25-migrate-network
@@ -0,0 +1,56 @@
+#!/bin/sh
+# License GPLv3
+
+setupPorts() {
+ # Add a single port to the *_PORTS config
+ # Usage: setupPorts <port id> <port mode>
+
+ local port=$1
+ local mode=$2
+
+ #default: BATMAN
+ if [ "$mode" = "WAN" ] ; then
+ WAN_PORTS="$WAN_PORTS $port"
+ elif [ "$mode" = "CLIENT" ] ; then
+ CLIENT_PORTS="$CLIENT_PORTS $port"
+ else
+ BATMAN_PORTS="$BATMAN_PORTS $port"
+ fi
+}
+
+if [ -s /etc/network.config ]; then
+ . /etc/network.config
+
+ if [ -n "$ETHMODE" ] && ! [ "$(uci get board.model.name)" = "gl-ar150" ] ; then
+ # real one-port
+ echo "# Migrated network config" >> "$firstbootscript"
+ echo ". /lib/functions/fff/networksetup" >> "$firstbootscript"
+ echo "setupOnePort 'eth0' '$ETHMODE'" >> "$firstbootscript"
+ else
+ # anything else will be switch-based
+ CLIENT_UCI="$(uci -q get network.vlan1.ports)"
+ BATMAN_UCI="$(uci -q get network.vlan3.ports)"
+
+ # GL-AR150
+ if [ -n "$ETHMODE" ]; then
+ setupPorts "1" "$ETHMODE"
+ WAN_PORTS=""
+ fi
+
+ # CPE210/510 v1
+ [ -n "$LAN0MODE" ] && setupPorts "5" "$LAN0MODE"
+ [ -n "$LAN1MODE" ] && setupPorts "4" "$LAN1MODE"
+
+ # Only create entry if setting actually differs
+ # But: if entries are created, create entries for all VLANs
+ if [ ! "$CLIENT_UCI" = "$CLIENT_PORTS" ] || [ ! "$BATMAN_UCI" = "$BATMAN_PORTS" ]; then
+ echo "# Migrated network config" >> "$firstbootscript"
+ echo "uci set network.vlan1.ports='$CLIENT_PORTS'" >> "$firstbootscript"
+ echo "uci set network.vlan3.ports='$BATMAN_PORTS'" >> "$firstbootscript"
+ [ -n "$WAN_PORTS" ] && echo "uci set network.vlan2.ports='$WAN_PORTS'" >> "$firstbootscript"
+ echo "uci commit network" >> "$firstbootscript"
+ fi
+ fi
+
+ rm /etc/network.config
+fi
--
2.11.0
Mehr Informationen über die Mailingliste franken-dev