[v3,06/14] fff-network/-support/-web: Nice setup of special-port devices

Submitted by Adrian Schmutzler on April 22, 2019, 12:35 p.m.

Details

Message ID 20190422123537.5852-6-freifunk@adrianschmutzler.de
State Deferred
Headers show

Commit Message

Adrian Schmutzler April 22, 2019, 12:35 p.m.
This patch:
- provides scripts to easily change port configuration on the
  "special" devices
- provides a file to store upgrade-safe script lines run at
  first boot (to be used for port adjustments)
- fixes the port page in WebUI
- fixes show_info

With this patch, instead of specifying data in network.config
and then have a script to deal with it, we define a script
/etc/firstbootfff where COMMANDS can be stored. Thus, one can
just make switch ports permanent by putting the uci commands there.

To keep the convenient setup of one-port (and other special)
devices, we implement script, e.g.
setoneport "WAN"
will set the port of a one-port device to WAN mode. Those scripts
are used in the WebUI and may also be implemented manually in the
/etc/firstbootfff file.

This patch misses the selection of the current port mode in the
WebUI. It would have been too much additional code for this
tiny feature.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>

---

This patch is built to reintroduce as much of the previous
functionality as possible. One could however consider removing the
CPE and AR150 special cases and leave only the real one-ports in
the WebUI.

Changes in v2:
- Removed some -q
- Changed another PORTORDER in show_info
- Renamed "twoport" to "cpev1"
- Add ui.portsetup in 10-setup-fff
- Restart network in scripts, no reboot necessary
- Make 99-fff-sysupgrade append instead of overwrite

Changes in v3:
- Added variable port in setoneport
- Added uci commit fff at end of 22a-config-ports
- Use new generic names: vlan1 etc.
---
 .../fff-config/files/etc/uci-defaults/10-setup-fff |  3 +
 .../files/etc/uci-defaults/22a-config-ports        |  5 ++
 .../fff/fff-network/files/usr/sbin/set2ndport      | 30 +++++++++
 .../fff/fff-network/files/usr/sbin/setcpev1        | 46 +++++++++++++
 .../fff/fff-network/files/usr/sbin/setoneport      | 24 +++++++
 src/packages/fff/fff-support/Makefile              |  2 +-
 .../files/etc/uci-defaults/90-firstbootfff         | 13 ++++
 .../fff/fff-support/files/usr/sbin/show_info       | 13 ++--
 src/packages/fff/fff-sysupgrade/Makefile           |  2 +-
 .../files/etc/uci-defaults/99-fff-sysupgrade       |  2 +-
 src/packages/fff/fff-web/Makefile                  |  2 +-
 .../fff/fff-web/files/www/ssl/cgi-bin/ports.html   | 78 +++++++++-------------
 12 files changed, 162 insertions(+), 58 deletions(-)
 create mode 100755 src/packages/fff/fff-network/files/usr/sbin/set2ndport
 create mode 100755 src/packages/fff/fff-network/files/usr/sbin/setcpev1
 create mode 100755 src/packages/fff/fff-network/files/usr/sbin/setoneport
 create mode 100644 src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff

Patch hide | download patch | download mbox

diff --git a/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff b/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
index 3014f50d..a63ff6a9 100644
--- a/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
+++ b/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
@@ -11,4 +11,7 @@  if ! uci -q get fff.system > /dev/null ; then
 	uci set "fff.system.hostname=FFF"
 fi
 
+uci set fff.ui=fff
+uci -q get fff.ui.portsetup > /dev/null || uci set "fff.ui.portsetup=default"
+
 uci commit fff
diff --git a/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports b/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
index b8eaceab..cc7ab277 100644
--- a/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
+++ b/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
@@ -21,11 +21,13 @@  case "$BOARD" in
 		# Default: LAN0: WAN, LAN1: CLIENT
 		setupSwitch "eth0" "0t 4" "0t" "0t 5"
 		setupWan "eth0.2"
+		uci set "fff.ui.portsetup=cpev1"
 		;;
 	gl-ar150)
 		# Default: CLIENT
 		setupSwitch "eth1" "0t 1" "0t"
 		setupWan "eth0"
+		uci set "fff.ui.portsetup=2ndport"
 		;;
 	tl-wdr3500-v1|\
 	tl-wr741nd-v2|\
@@ -85,5 +87,8 @@  case "$BOARD" in
 	ubnt-unifiac-lite|\
 	ubnt-unifiac-mesh)
 		setupOnePort "eth0" "CLIENT"
+		uci set "fff.ui.portsetup=oneport"
 		;;
 esac
+
+uci commit fff
diff --git a/src/packages/fff/fff-network/files/usr/sbin/set2ndport b/src/packages/fff/fff-network/files/usr/sbin/set2ndport
new file mode 100755
index 00000000..84aa5a2c
--- /dev/null
+++ b/src/packages/fff/fff-network/files/usr/sbin/set2ndport
@@ -0,0 +1,30 @@ 
+#!/bin/sh
+
+# This sets the port mode on second port without switch
+
+if ! [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ] ; then
+	echo "Wrong device. This is for two-port devices without switch only!"
+	exit 1
+fi
+
+LAN0MODE=$1
+
+CLIENT_PORTS="0t"
+BATMAN_PORTS="0t"
+
+if [ "$LAN0MODE" = "CLIENT" ] ; then
+	CLIENT_PORTS="$CLIENT_PORTS 1"
+elif [ "$LAN0MODE" = "BATMAN" ] ; then
+	BATMAN_PORTS="$BATMAN_PORTS 1"
+else
+	echo "Wrong port mode. Choose one of: CLIENT, BATMAN"
+	exit 1
+fi
+
+uci set "network.vlan1.ports=$CLIENT_PORTS"
+uci set "network.vlan3.ports=$BATMAN_PORTS"
+uci commit network
+
+/etc/init.d/network restart
+
+echo "Port updated successfully."
diff --git a/src/packages/fff/fff-network/files/usr/sbin/setcpev1 b/src/packages/fff/fff-network/files/usr/sbin/setcpev1
new file mode 100755
index 00000000..5ed9a987
--- /dev/null
+++ b/src/packages/fff/fff-network/files/usr/sbin/setcpev1
@@ -0,0 +1,46 @@ 
+#!/bin/sh
+
+# This sets the port mode on CPE210 v1 and CPE510 v1
+
+if ! [ "$(uci -q get fff.ui.portsetup)" = "cpev1" ] ; then
+	echo "Wrong device. This is for CPE210 v1 or CPE510 v1 only!"
+	exit 1
+fi
+
+LAN0MODE=$1
+LAN1MODE=$2
+
+CLIENT_PORTS="0t"
+WAN_PORTS="0t"
+BATMAN_PORTS="0t"
+
+if [ "$LAN0MODE" = "WAN" ] ; then
+	WAN_PORTS="$WAN_PORTS 5"
+elif [ "$LAN0MODE" = "CLIENT" ] ; then
+	CLIENT_PORTS="$CLIENT_PORTS 5"
+elif [ "$LAN0MODE" = "BATMAN" ] ; then
+	BATMAN_PORTS="$BATMAN_PORTS 5"
+else
+	echo "Wrong port mode for 1st port. Choose one of: WAN, CLIENT, BATMAN"
+	exit 1
+fi
+
+if [ "$LAN1MODE" = "WAN" ] ; then
+	WAN_PORTS="$WAN_PORTS 4"
+elif [ "$LAN1MODE" = "CLIENT" ] ; then
+	CLIENT_PORTS="$CLIENT_PORTS 4"
+elif [ "$LAN1MODE" = "BATMAN" ] ; then
+	BATMAN_PORTS="$BATMAN_PORTS 4"
+else
+	echo "Wrong port mode for 2nd port. Choose one of: WAN, CLIENT, BATMAN"
+	exit 1
+fi
+
+uci set "network.vlan1.ports=$CLIENT_PORTS"
+uci set "network.vlan2.ports=$WAN_PORTS"
+uci set "network.vlan3.ports=$BATMAN_PORTS"
+uci commit network
+
+/etc/init.d/network restart
+
+echo "Ports updated successfully."
diff --git a/src/packages/fff/fff-network/files/usr/sbin/setoneport b/src/packages/fff/fff-network/files/usr/sbin/setoneport
new file mode 100755
index 00000000..37387827
--- /dev/null
+++ b/src/packages/fff/fff-network/files/usr/sbin/setoneport
@@ -0,0 +1,24 @@ 
+#!/bin/sh
+
+# This sets the port mode on one-port devices
+
+if ! [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] ; then
+	echo "Wrong device. This is for one-port devices only!"
+	exit 1
+fi
+
+. /lib/functions/fff/networksetup
+
+ETHMODE=$1
+DEV=$2
+
+[ -n "$DEV" ] || DEV="eth0"
+
+if [ "$ETHMODE" = "WAN" ] || [ "$ETHMODE" = "CLIENT" ] || [ "$ETHMODE" = "BATMAN" ]; then
+	setupOnePort "$DEV" "$ETHMODE"
+	/etc/init.d/network restart
+	echo "Port updated successfully."
+else
+	echo "Wrong port mode. Choose one of: WAN, CLIENT, BATMAN"
+	exit 1
+fi
diff --git a/src/packages/fff/fff-support/Makefile b/src/packages/fff/fff-support/Makefile
index 56e35740..2fc74b0c 100644
--- a/src/packages/fff/fff-support/Makefile
+++ b/src/packages/fff/fff-support/Makefile
@@ -1,7 +1,7 @@ 
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=fff-support
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
 
diff --git a/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff b/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff
new file mode 100644
index 00000000..30c5ab12
--- /dev/null
+++ b/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff
@@ -0,0 +1,13 @@ 
+#!/bin/sh
+# Copyright 2019 Adrian Schmutzler
+# License GPLv3
+
+LOCALUPGRADESCRIPT="/etc/firstbootfff"
+
+#add LOCALUPGRADESCRIPT to sysupgrade
+grep -q ^"${LOCALUPGRADESCRIPT}"$ /etc/sysupgrade.conf || echo "$LOCALUPGRADESCRIPT" >> /etc/sysupgrade.conf
+
+# process user commands
+[ -s "$LOCALCONFIGSCRIPT" ] && {
+	sh /etc/firstbootfff
+}
diff --git a/src/packages/fff/fff-support/files/usr/sbin/show_info b/src/packages/fff/fff-support/files/usr/sbin/show_info
index d7ec8247..fb7f7d25 100755
--- a/src/packages/fff/fff-support/files/usr/sbin/show_info
+++ b/src/packages/fff/fff-support/files/usr/sbin/show_info
@@ -3,6 +3,7 @@ 
 . /etc/firmware_release
 . /lib/functions/fff/evalhoodinfo
 . /lib/functions/fff/evalbytes
+. /lib/functions/fff/portorder
 . /lib/functions.sh # required for config_load and config_foreach
 
 board_name=$(uci -q get board.model.name)
@@ -187,13 +188,9 @@  fi
 echo "Download-Limit: $(uci -q get 'simple-tc.example.limit_ingress') kBit/s"
 echo "Upload-Limit: $(uci -q get 'simple-tc.example.limit_egress') kBit/s"
 
-if grep -q 'PORTORDER=' /etc/network.$board_name ; then
-	portorder=$(awk -F= '/PORTORDER=/ { print $2 }' /etc/network.$board_name | sed "s/\"//g")
-fi
-
 echo ""
 if swconfig list | grep -q switch0 ; then
-	if [ -n "$portorder" ] ; then
+	if [ -n "$PORTORDER" ] ; then
 		echo "-> SWITCH (tatsaechliche Portreihenfolge)"
 	else
 		echo "-> SWITCH (interne logische Portreihenfolge)"
@@ -218,7 +215,7 @@  if swconfig list | grep -q switch0 ; then
 		printf '%-10s%-5s%-13s%s\n' "WAN-Port: " "${link} " "- WAN " "@ $speed"
 	fi
 
-	for internalport in $portorder
+	for internalport in $PORTORDER
 	do
 		line=$(swconfig dev switch0 port "$internalport" show | tr -d '\n' | tr -d '\t')
 		port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')
@@ -230,9 +227,7 @@  if swconfig list | grep -q switch0 ; then
 	swconfig dev switch0 show | grep "\t*link:" | while read line ; do
 		line=$(echo "$line" | tr -d '\n' | tr -d '\t')
 		port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')
-		if echo "$portorder" | grep -q "$port" ; then
-			continue
-		fi
+		echo "$PORTORDER" | grep -q "$port" && continue
 		printf '%-10s' "Port #${port}: "
 		format_port "${line}"
 	done
diff --git a/src/packages/fff/fff-sysupgrade/Makefile b/src/packages/fff/fff-sysupgrade/Makefile
index 0e6c08ec..0f2e6a1e 100644
--- a/src/packages/fff/fff-sysupgrade/Makefile
+++ b/src/packages/fff/fff-sysupgrade/Makefile
@@ -1,7 +1,7 @@ 
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=fff-sysupgrade
-PKG_RELEASE:=10
+PKG_RELEASE:=11
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
 
diff --git a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysupgrade b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysupgrade
index f5783687..07f991e0 100644
--- a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysupgrade
+++ b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysupgrade
@@ -2,7 +2,7 @@ 
 # Copyright 2017 Tim Niemeyer
 # License GPLv3
 
-cat > /etc/sysupgrade.conf <<-__EOF__
+cat >> /etc/sysupgrade.conf <<-__EOF__
 /etc/shadow
 /etc/dropbear/dropbear_dss_host_key
 /etc/dropbear/dropbear_rsa_host_key
diff --git a/src/packages/fff/fff-web/Makefile b/src/packages/fff/fff-web/Makefile
index 9bb10f71..819644a5 100644
--- a/src/packages/fff/fff-web/Makefile
+++ b/src/packages/fff/fff-web/Makefile
@@ -1,7 +1,7 @@ 
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=fff-web
-PKG_RELEASE:=7
+PKG_RELEASE:=8
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
 
diff --git a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
index 01506fce..f990d4e4 100755
--- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
+++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
@@ -2,22 +2,27 @@ 
 
 <%
 board_name=$(uci -q get board.model.name)
+LOCALUPGRADESCRIPT="/etc/firstbootfff"
+
 # write
 if [ "$REQUEST_METHOD" = "POST" ] ; then
 	if [ "$POST_change_mode" != "" ] ; then
-		sed -i '/^.*# set via WebUI/d' /etc/network.config
-		echo "ETHMODE=\"${POST_mode}\" # set via WebUI" >> /etc/network.config
-		sed -i '/^FORCEPARSE/d' /etc/network.config
-		echo "FORCEPARSE='2'" >> /etc/network.config
+		if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ]; then
+			setoneport "${POST_mode}"
+			sed -i '/^setoneport.*/d' $LOCALUPGRADESCRIPT
+			echo "setoneport \"${POST_mode}\" # set via WebUI" >> $LOCALUPGRADESCRIPT
+		elif [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ]; then
+			set2ndport "${POST_mode}"
+			sed -i '/^set2ndport.*/d' $LOCALUPGRADESCRIPT
+			echo "set2ndport \"${POST_mode}\" # set via WebUI" >> $LOCALUPGRADESCRIPT
+		fi
 		do_reboot=1
 		MSG='<span class="green">Port Modus ge&auml;ndert! Router startet neu...</span>'
 	fi
 	if [ "$POST_change_twoport" != "" ] ; then
-		sed -i '/^.*# set via WebUI/d' /etc/network.config
-		echo "LAN0MODE=\"${POST_mode0}\" # set via WebUI" >> /etc/network.config
-		echo "LAN1MODE=\"${POST_mode1}\" # set via WebUI" >> /etc/network.config
-		sed -i '/^FORCEPARSE/d' /etc/network.config
-		echo "FORCEPARSE='2'" >> /etc/network.config
+		setcpev1 "${POST_mode0}" "${POST_mode1}"
+		sed -i '/^setcpev1.*/d' $LOCALUPGRADESCRIPT
+		echo "setcpev1 \"${POST_mode0}\" \"${POST_mode1}\" # set via WebUI" >> $LOCALUPGRADESCRIPT
 		do_reboot=1
 		MSG='<span class="green">Port Modus ge&auml;ndert! Router startet neu...</span>'
 	fi
@@ -108,11 +113,8 @@  format_port() {
 					echo "</td>"
 				fi
 				
-				if grep -q 'PORTORDER=' /etc/network.$board_name ; then
-					portorder=$(awk -F= '/PORTORDER=/ { print $2 }' /etc/network.$board_name | sed "s/\"//g")
-				fi
-				for internalport in $portorder
-				do
+				. /lib/functions/fff/portorder
+				for internalport in $PORTORDER ; do
 					line=$(swconfig dev switch0 port "$internalport" show | tr -d '\n' | tr -d '\t')
 					port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')
 					echo "<td class=\"swport\">"
@@ -120,16 +122,12 @@  format_port() {
 					format_port "${line}"
 					echo "</td>"
 				done
-				if [ -n "$portorder" ] ; then
-					echo "<td class=\"swport\" style=\"width:4em\"></td>"
-				fi
+				[ -n "$PORTORDER" ] && echo "<td class=\"swport\" style=\"width:4em\"></td>"
 				
 				swconfig dev switch0 show | grep "\t*link:" | while read line ; do
 					line=$(echo "$line" | tr -d '\n' | tr -d '\t')
 					port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')
-					if echo "$portorder" | grep -q "$port" ; then
-						continue
-					fi
+					echo "$PORTORDER" | grep -q "$port" && continue
 					echo "<td class=\"swport\">"
 					echo "<span class=\"port\">Port #${port}</span><br />"
 					format_port "${line}"
@@ -141,7 +139,7 @@  format_port() {
 		<table>
 			<tr><td></td></tr>
 			<tr><td>
-				<% if [ -n "$portorder" ] ; then %>
+				<% if [ -n "$PORTORDER" ] ; then %>
 				Dies zeigt die tats&auml;chliche Zuordnung der Ports, wobei der WAN Port auf der linken Seite liegt. Die Nummerierung entspricht der internen Zuordnung!<br />
 				<% else %>
 				Die Nummerierung und Reihenfolge der Ports entspricht nicht notwendigerweise der der Netzwerkanschl&uuml;sse am Router!<br />
@@ -152,12 +150,7 @@  format_port() {
 	</fieldset>
 	</td></tr>
 <% fi %>
-<% if grep -q "ONE_PORT" "/etc/network.$board_name" || grep -q "ETHPORT" "/etc/network.$board_name" ; then %>
-	<%
-		# Device has a port set by $ETHMODE
-		. /etc/network.mode
-		. /etc/network.config
-	%>
+<% if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] || [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ] ; then %>
 	<tr><td>
 	<fieldset>
 		<legend>Ethernet Anschluss</legend>
@@ -166,10 +159,10 @@  format_port() {
 				<th style="width: 1em;">Anschluss&nbsp;Modus:</th>
 				<td>
 					<select name="mode">
-						<option value="BATMAN" <% [ "$ETHMODE" = "BATMAN" ] && echo -n 'selected="selected" ' %>>BATMAN</option>
-						<option value="CLIENT" <% [ "$ETHMODE" = "CLIENT" ] && echo -n 'selected="selected" ' %>>CLIENT</option>
-						<% if grep -q "ONE_PORT" "/etc/network.$board_name" ; then %>
-						<option value="WAN" <% [ "$ETHMODE" = "WAN" ] && echo -n 'selected="selected" ' %>>WAN</option>
+						<option value="BATMAN">BATMAN</option>
+						<option value="CLIENT">CLIENT</option>
+						<% if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] ; then %>
+						<option value="WAN">WAN</option>
 						<% fi %>
 					</select>
 				</td>
@@ -178,7 +171,7 @@  format_port() {
 			<tr><td colspan="2"></td></tr>
 			<tr><td colspan="2">
 				WAN: Knoten stellt &uuml;ber Ethernet Anschluss Verbindung zum Internet her.<br />
-				Client: Normale Clients stellen &uuml;ber Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
+				CLIENT: Normale Clients stellen &uuml;ber Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
 				BATMAN: Knoten stellt &uuml;ber Ethernet Anschluss Verbindung zu anderen MESH Knoten her.<br /><br />
 
 				Wenn diese Einstellung ver&auml;ndert wird, wird eine evtl. vorhandene manuelle Netzwerkkonfiguration in der
@@ -189,12 +182,7 @@  format_port() {
 	</fieldset>
 	</td></tr>
 <% fi %>
-<% if grep -q "LAN0PORT" "/etc/network.$board_name" || grep -q "LAN1PORT" "/etc/network.$board_name" ; then %>
-	<%
-		# Device has two ports
-		. /etc/network.mode
-		. /etc/network.config
-	%>
+<% if [ "$(uci -q get fff.ui.portsetup)" = "cpev1" ] ; then %>
 	<tr><td>
 	<fieldset>
 		<legend>Ethernet Anschl&uuml;sse</legend>
@@ -207,16 +195,16 @@  format_port() {
 			<tr>
 				<td>
 					<select name="mode0">
-						<option value="BATMAN" <% [ "$LAN0MODE" = "BATMAN" ] && echo -n 'selected="selected" ' %>>BATMAN</option>
-						<option value="CLIENT" <% [ "$LAN0MODE" = "CLIENT" ] && echo -n 'selected="selected" ' %>>CLIENT</option>
-						<option value="WAN" <% [ "$LAN0MODE" = "WAN" ] && echo -n 'selected="selected" ' %>>WAN</option>
+						<option value="BATMAN">BATMAN</option>
+						<option value="CLIENT">CLIENT</option>
+						<option value="WAN">WAN</option>
 					</select>
 				</td>
 				<td>
 					<select name="mode1">
-						<option value="BATMAN" <% [ "$LAN1MODE" = "BATMAN" ] && echo -n 'selected="selected" ' %>>BATMAN</option>
-						<option value="CLIENT" <% [ "$LAN1MODE" = "CLIENT" ] && echo -n 'selected="selected" ' %>>CLIENT</option>
-						<option value="WAN" <% [ "$LAN1MODE" = "WAN" ] && echo -n 'selected="selected" ' %>>WAN</option>
+						<option value="BATMAN">BATMAN</option>
+						<option value="CLIENT">CLIENT</option>
+						<option value="WAN">WAN</option>
 					</select>
 				</td>
 				<td><input type="submit" name="change_twoport" /></td>
@@ -224,7 +212,7 @@  format_port() {
 			<tr><td colspan="3"></td></tr>
 			<tr><td colspan="3">
 				WAN: Knoten stellt &uuml;ber Ethernet Anschluss Verbindung zum Internet her.<br />
-				Client: Normale Clients stellen &uuml;ber Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
+				CLIENT: Normale Clients stellen &uuml;ber Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
 				BATMAN: Knoten stellt &uuml;ber Ethernet Anschluss Verbindung zu anderen MESH Knoten her.<br /><br />
 
 				Wenn diese Einstellung ver&auml;ndert wird, wird eine evtl. vorhandene manuelle Netzwerkkonfiguration in der

Comments

Robert Langhammer April 22, 2019, 9:07 p.m.
Hi Adrian,

ich war ja anfangs etwas skeptisch wegen den Skripten in sbin. Es ist
aber doch eine recht elegante Lösung, wenn man sich das im Ganzen anschaut.

Reviewed-by: Robert Langhammer <rlanghammer@web.de>

Am 22.04.19 um 14:35 schrieb Adrian Schmutzler:
> This patch:
> - provides scripts to easily change port configuration on the
>   "special" devices
> - provides a file to store upgrade-safe script lines run at
>   first boot (to be used for port adjustments)
> - fixes the port page in WebUI
> - fixes show_info
>
> With this patch, instead of specifying data in network.config
> and then have a script to deal with it, we define a script
> /etc/firstbootfff where COMMANDS can be stored. Thus, one can
> just make switch ports permanent by putting the uci commands there.
>
> To keep the convenient setup of one-port (and other special)
> devices, we implement script, e.g.
> setoneport "WAN"
> will set the port of a one-port device to WAN mode. Those scripts
> are used in the WebUI and may also be implemented manually in the
> /etc/firstbootfff file.
>
> This patch misses the selection of the current port mode in the
> WebUI. It would have been too much additional code for this
> tiny feature.
>
> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
>
> ---
>
> This patch is built to reintroduce as much of the previous
> functionality as possible. One could however consider removing the
> CPE and AR150 special cases and leave only the real one-ports in
> the WebUI.
>
> Changes in v2:
> - Removed some -q
> - Changed another PORTORDER in show_info
> - Renamed "twoport" to "cpev1"
> - Add ui.portsetup in 10-setup-fff
> - Restart network in scripts, no reboot necessary
> - Make 99-fff-sysupgrade append instead of overwrite
>
> Changes in v3:
> - Added variable port in setoneport
> - Added uci commit fff at end of 22a-config-ports
> - Use new generic names: vlan1 etc.
> ---
>  .../fff-config/files/etc/uci-defaults/10-setup-fff |  3 +
>  .../files/etc/uci-defaults/22a-config-ports        |  5 ++
>  .../fff/fff-network/files/usr/sbin/set2ndport      | 30 +++++++++
>  .../fff/fff-network/files/usr/sbin/setcpev1        | 46 +++++++++++++
>  .../fff/fff-network/files/usr/sbin/setoneport      | 24 +++++++
>  src/packages/fff/fff-support/Makefile              |  2 +-
>  .../files/etc/uci-defaults/90-firstbootfff         | 13 ++++
>  .../fff/fff-support/files/usr/sbin/show_info       | 13 ++--
>  src/packages/fff/fff-sysupgrade/Makefile           |  2 +-
>  .../files/etc/uci-defaults/99-fff-sysupgrade       |  2 +-
>  src/packages/fff/fff-web/Makefile                  |  2 +-
>  .../fff/fff-web/files/www/ssl/cgi-bin/ports.html   | 78 +++++++++-------------
>  12 files changed, 162 insertions(+), 58 deletions(-)
>  create mode 100755 src/packages/fff/fff-network/files/usr/sbin/set2ndport
>  create mode 100755 src/packages/fff/fff-network/files/usr/sbin/setcpev1
>  create mode 100755 src/packages/fff/fff-network/files/usr/sbin/setoneport
>  create mode 100644 src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff
>
> diff --git a/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff b/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
> index 3014f50d..a63ff6a9 100644
> --- a/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
> +++ b/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
> @@ -11,4 +11,7 @@ if ! uci -q get fff.system > /dev/null ; then
>  	uci set "fff.system.hostname=FFF"
>  fi
>  
> +uci set fff.ui=fff
> +uci -q get fff.ui.portsetup > /dev/null || uci set "fff.ui.portsetup=default"
> +
>  uci commit fff
> diff --git a/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports b/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
> index b8eaceab..cc7ab277 100644
> --- a/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
> +++ b/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
> @@ -21,11 +21,13 @@ case "$BOARD" in
>  		# Default: LAN0: WAN, LAN1: CLIENT
>  		setupSwitch "eth0" "0t 4" "0t" "0t 5"
>  		setupWan "eth0.2"
> +		uci set "fff.ui.portsetup=cpev1"
>  		;;
>  	gl-ar150)
>  		# Default: CLIENT
>  		setupSwitch "eth1" "0t 1" "0t"
>  		setupWan "eth0"
> +		uci set "fff.ui.portsetup=2ndport"
>  		;;
>  	tl-wdr3500-v1|\
>  	tl-wr741nd-v2|\
> @@ -85,5 +87,8 @@ case "$BOARD" in
>  	ubnt-unifiac-lite|\
>  	ubnt-unifiac-mesh)
>  		setupOnePort "eth0" "CLIENT"
> +		uci set "fff.ui.portsetup=oneport"
>  		;;
>  esac
> +
> +uci commit fff
> diff --git a/src/packages/fff/fff-network/files/usr/sbin/set2ndport b/src/packages/fff/fff-network/files/usr/sbin/set2ndport
> new file mode 100755
> index 00000000..84aa5a2c
> --- /dev/null
> +++ b/src/packages/fff/fff-network/files/usr/sbin/set2ndport
> @@ -0,0 +1,30 @@
> +#!/bin/sh
> +
> +# This sets the port mode on second port without switch
> +
> +if ! [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ] ; then
> +	echo "Wrong device. This is for two-port devices without switch only!"
> +	exit 1
> +fi
> +
> +LAN0MODE=$1
> +
> +CLIENT_PORTS="0t"
> +BATMAN_PORTS="0t"
> +
> +if [ "$LAN0MODE" = "CLIENT" ] ; then
> +	CLIENT_PORTS="$CLIENT_PORTS 1"
> +elif [ "$LAN0MODE" = "BATMAN" ] ; then
> +	BATMAN_PORTS="$BATMAN_PORTS 1"
> +else
> +	echo "Wrong port mode. Choose one of: CLIENT, BATMAN"
> +	exit 1
> +fi
> +
> +uci set "network.vlan1.ports=$CLIENT_PORTS"
> +uci set "network.vlan3.ports=$BATMAN_PORTS"
> +uci commit network
> +
> +/etc/init.d/network restart
> +
> +echo "Port updated successfully."
> diff --git a/src/packages/fff/fff-network/files/usr/sbin/setcpev1 b/src/packages/fff/fff-network/files/usr/sbin/setcpev1
> new file mode 100755
> index 00000000..5ed9a987
> --- /dev/null
> +++ b/src/packages/fff/fff-network/files/usr/sbin/setcpev1
> @@ -0,0 +1,46 @@
> +#!/bin/sh
> +
> +# This sets the port mode on CPE210 v1 and CPE510 v1
> +
> +if ! [ "$(uci -q get fff.ui.portsetup)" = "cpev1" ] ; then
> +	echo "Wrong device. This is for CPE210 v1 or CPE510 v1 only!"
> +	exit 1
> +fi
> +
> +LAN0MODE=$1
> +LAN1MODE=$2
> +
> +CLIENT_PORTS="0t"
> +WAN_PORTS="0t"
> +BATMAN_PORTS="0t"
> +
> +if [ "$LAN0MODE" = "WAN" ] ; then
> +	WAN_PORTS="$WAN_PORTS 5"
> +elif [ "$LAN0MODE" = "CLIENT" ] ; then
> +	CLIENT_PORTS="$CLIENT_PORTS 5"
> +elif [ "$LAN0MODE" = "BATMAN" ] ; then
> +	BATMAN_PORTS="$BATMAN_PORTS 5"
> +else
> +	echo "Wrong port mode for 1st port. Choose one of: WAN, CLIENT, BATMAN"
> +	exit 1
> +fi
> +
> +if [ "$LAN1MODE" = "WAN" ] ; then
> +	WAN_PORTS="$WAN_PORTS 4"
> +elif [ "$LAN1MODE" = "CLIENT" ] ; then
> +	CLIENT_PORTS="$CLIENT_PORTS 4"
> +elif [ "$LAN1MODE" = "BATMAN" ] ; then
> +	BATMAN_PORTS="$BATMAN_PORTS 4"
> +else
> +	echo "Wrong port mode for 2nd port. Choose one of: WAN, CLIENT, BATMAN"
> +	exit 1
> +fi
> +
> +uci set "network.vlan1.ports=$CLIENT_PORTS"
> +uci set "network.vlan2.ports=$WAN_PORTS"
> +uci set "network.vlan3.ports=$BATMAN_PORTS"
> +uci commit network
> +
> +/etc/init.d/network restart
> +
> +echo "Ports updated successfully."
> diff --git a/src/packages/fff/fff-network/files/usr/sbin/setoneport b/src/packages/fff/fff-network/files/usr/sbin/setoneport
> new file mode 100755
> index 00000000..37387827
> --- /dev/null
> +++ b/src/packages/fff/fff-network/files/usr/sbin/setoneport
> @@ -0,0 +1,24 @@
> +#!/bin/sh
> +
> +# This sets the port mode on one-port devices
> +
> +if ! [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] ; then
> +	echo "Wrong device. This is for one-port devices only!"
> +	exit 1
> +fi
> +
> +. /lib/functions/fff/networksetup
> +
> +ETHMODE=$1
> +DEV=$2
> +
> +[ -n "$DEV" ] || DEV="eth0"
> +
> +if [ "$ETHMODE" = "WAN" ] || [ "$ETHMODE" = "CLIENT" ] || [ "$ETHMODE" = "BATMAN" ]; then
> +	setupOnePort "$DEV" "$ETHMODE"
> +	/etc/init.d/network restart
> +	echo "Port updated successfully."
> +else
> +	echo "Wrong port mode. Choose one of: WAN, CLIENT, BATMAN"
> +	exit 1
> +fi
> diff --git a/src/packages/fff/fff-support/Makefile b/src/packages/fff/fff-support/Makefile
> index 56e35740..2fc74b0c 100644
> --- a/src/packages/fff/fff-support/Makefile
> +++ b/src/packages/fff/fff-support/Makefile
> @@ -1,7 +1,7 @@
>  include $(TOPDIR)/rules.mk
>  
>  PKG_NAME:=fff-support
> -PKG_RELEASE:=2
> +PKG_RELEASE:=3
>  
>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
>  
> diff --git a/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff b/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff
> new file mode 100644
> index 00000000..30c5ab12
> --- /dev/null
> +++ b/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +# Copyright 2019 Adrian Schmutzler
> +# License GPLv3
> +
> +LOCALUPGRADESCRIPT="/etc/firstbootfff"
> +
> +#add LOCALUPGRADESCRIPT to sysupgrade
> +grep -q ^"${LOCALUPGRADESCRIPT}"$ /etc/sysupgrade.conf || echo "$LOCALUPGRADESCRIPT" >> /etc/sysupgrade.conf
> +
> +# process user commands
> +[ -s "$LOCALCONFIGSCRIPT" ] && {
> +	sh /etc/firstbootfff
> +}
> diff --git a/src/packages/fff/fff-support/files/usr/sbin/show_info b/src/packages/fff/fff-support/files/usr/sbin/show_info
> index d7ec8247..fb7f7d25 100755
> --- a/src/packages/fff/fff-support/files/usr/sbin/show_info
> +++ b/src/packages/fff/fff-support/files/usr/sbin/show_info
> @@ -3,6 +3,7 @@
>  . /etc/firmware_release
>  . /lib/functions/fff/evalhoodinfo
>  . /lib/functions/fff/evalbytes
> +. /lib/functions/fff/portorder
>  . /lib/functions.sh # required for config_load and config_foreach
>  
>  board_name=$(uci -q get board.model.name)
> @@ -187,13 +188,9 @@ fi
>  echo "Download-Limit: $(uci -q get 'simple-tc.example.limit_ingress') kBit/s"
>  echo "Upload-Limit: $(uci -q get 'simple-tc.example.limit_egress') kBit/s"
>  
> -if grep -q 'PORTORDER=' /etc/network.$board_name ; then
> -	portorder=$(awk -F= '/PORTORDER=/ { print $2 }' /etc/network.$board_name | sed "s/\"//g")
> -fi
> -
>  echo ""
>  if swconfig list | grep -q switch0 ; then
> -	if [ -n "$portorder" ] ; then
> +	if [ -n "$PORTORDER" ] ; then
>  		echo "-> SWITCH (tatsaechliche Portreihenfolge)"
>  	else
>  		echo "-> SWITCH (interne logische Portreihenfolge)"
> @@ -218,7 +215,7 @@ if swconfig list | grep -q switch0 ; then
>  		printf '%-10s%-5s%-13s%s\n' "WAN-Port: " "${link} " "- WAN " "@ $speed"
>  	fi
>  
> -	for internalport in $portorder
> +	for internalport in $PORTORDER
>  	do
>  		line=$(swconfig dev switch0 port "$internalport" show | tr -d '\n' | tr -d '\t')
>  		port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')
> @@ -230,9 +227,7 @@ if swconfig list | grep -q switch0 ; then
>  	swconfig dev switch0 show | grep "\t*link:" | while read line ; do
>  		line=$(echo "$line" | tr -d '\n' | tr -d '\t')
>  		port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')
> -		if echo "$portorder" | grep -q "$port" ; then
> -			continue
> -		fi
> +		echo "$PORTORDER" | grep -q "$port" && continue
>  		printf '%-10s' "Port #${port}: "
>  		format_port "${line}"
>  	done
> diff --git a/src/packages/fff/fff-sysupgrade/Makefile b/src/packages/fff/fff-sysupgrade/Makefile
> index 0e6c08ec..0f2e6a1e 100644
> --- a/src/packages/fff/fff-sysupgrade/Makefile
> +++ b/src/packages/fff/fff-sysupgrade/Makefile
> @@ -1,7 +1,7 @@
>  include $(TOPDIR)/rules.mk
>  
>  PKG_NAME:=fff-sysupgrade
> -PKG_RELEASE:=10
> +PKG_RELEASE:=11
>  
>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
>  
> diff --git a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysupgrade b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysupgrade
> index f5783687..07f991e0 100644
> --- a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysupgrade
> +++ b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysupgrade
> @@ -2,7 +2,7 @@
>  # Copyright 2017 Tim Niemeyer
>  # License GPLv3
>  
> -cat > /etc/sysupgrade.conf <<-__EOF__
> +cat >> /etc/sysupgrade.conf <<-__EOF__
>  /etc/shadow
>  /etc/dropbear/dropbear_dss_host_key
>  /etc/dropbear/dropbear_rsa_host_key
> diff --git a/src/packages/fff/fff-web/Makefile b/src/packages/fff/fff-web/Makefile
> index 9bb10f71..819644a5 100644
> --- a/src/packages/fff/fff-web/Makefile
> +++ b/src/packages/fff/fff-web/Makefile
> @@ -1,7 +1,7 @@
>  include $(TOPDIR)/rules.mk
>  
>  PKG_NAME:=fff-web
> -PKG_RELEASE:=7
> +PKG_RELEASE:=8
>  
>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
>  
> diff --git a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
> index 01506fce..f990d4e4 100755
> --- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
> +++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
> @@ -2,22 +2,27 @@
>  
>  <%
>  board_name=$(uci -q get board.model.name)
> +LOCALUPGRADESCRIPT="/etc/firstbootfff"
> +
>  # write
>  if [ "$REQUEST_METHOD" = "POST" ] ; then
>  	if [ "$POST_change_mode" != "" ] ; then
> -		sed -i '/^.*# set via WebUI/d' /etc/network.config
> -		echo "ETHMODE=\"${POST_mode}\" # set via WebUI" >> /etc/network.config
> -		sed -i '/^FORCEPARSE/d' /etc/network.config
> -		echo "FORCEPARSE='2'" >> /etc/network.config
> +		if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ]; then
> +			setoneport "${POST_mode}"
> +			sed -i '/^setoneport.*/d' $LOCALUPGRADESCRIPT
> +			echo "setoneport \"${POST_mode}\" # set via WebUI" >> $LOCALUPGRADESCRIPT
> +		elif [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ]; then
> +			set2ndport "${POST_mode}"
> +			sed -i '/^set2ndport.*/d' $LOCALUPGRADESCRIPT
> +			echo "set2ndport \"${POST_mode}\" # set via WebUI" >> $LOCALUPGRADESCRIPT
> +		fi
>  		do_reboot=1
>  		MSG='<span class="green">Port Modus ge&auml;ndert! Router startet neu...</span>'
>  	fi
>  	if [ "$POST_change_twoport" != "" ] ; then
> -		sed -i '/^.*# set via WebUI/d' /etc/network.config
> -		echo "LAN0MODE=\"${POST_mode0}\" # set via WebUI" >> /etc/network.config
> -		echo "LAN1MODE=\"${POST_mode1}\" # set via WebUI" >> /etc/network.config
> -		sed -i '/^FORCEPARSE/d' /etc/network.config
> -		echo "FORCEPARSE='2'" >> /etc/network.config
> +		setcpev1 "${POST_mode0}" "${POST_mode1}"
> +		sed -i '/^setcpev1.*/d' $LOCALUPGRADESCRIPT
> +		echo "setcpev1 \"${POST_mode0}\" \"${POST_mode1}\" # set via WebUI" >> $LOCALUPGRADESCRIPT
>  		do_reboot=1
>  		MSG='<span class="green">Port Modus ge&auml;ndert! Router startet neu...</span>'
>  	fi
> @@ -108,11 +113,8 @@ format_port() {
>  					echo "</td>"
>  				fi
>  				
> -				if grep -q 'PORTORDER=' /etc/network.$board_name ; then
> -					portorder=$(awk -F= '/PORTORDER=/ { print $2 }' /etc/network.$board_name | sed "s/\"//g")
> -				fi
> -				for internalport in $portorder
> -				do
> +				. /lib/functions/fff/portorder
> +				for internalport in $PORTORDER ; do
>  					line=$(swconfig dev switch0 port "$internalport" show | tr -d '\n' | tr -d '\t')
>  					port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')
>  					echo "<td class=\"swport\">"
> @@ -120,16 +122,12 @@ format_port() {
>  					format_port "${line}"
>  					echo "</td>"
>  				done
> -				if [ -n "$portorder" ] ; then
> -					echo "<td class=\"swport\" style=\"width:4em\"></td>"
> -				fi
> +				[ -n "$PORTORDER" ] && echo "<td class=\"swport\" style=\"width:4em\"></td>"
>  				
>  				swconfig dev switch0 show | grep "\t*link:" | while read line ; do
>  					line=$(echo "$line" | tr -d '\n' | tr -d '\t')
>  					port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')
> -					if echo "$portorder" | grep -q "$port" ; then
> -						continue
> -					fi
> +					echo "$PORTORDER" | grep -q "$port" && continue
>  					echo "<td class=\"swport\">"
>  					echo "<span class=\"port\">Port #${port}</span><br />"
>  					format_port "${line}"
> @@ -141,7 +139,7 @@ format_port() {
>  		<table>
>  			<tr><td></td></tr>
>  			<tr><td>
> -				<% if [ -n "$portorder" ] ; then %>
> +				<% if [ -n "$PORTORDER" ] ; then %>
>  				Dies zeigt die tats&auml;chliche Zuordnung der Ports, wobei der WAN Port auf der linken Seite liegt. Die Nummerierung entspricht der internen Zuordnung!<br />
>  				<% else %>
>  				Die Nummerierung und Reihenfolge der Ports entspricht nicht notwendigerweise der der Netzwerkanschl&uuml;sse am Router!<br />
> @@ -152,12 +150,7 @@ format_port() {
>  	</fieldset>
>  	</td></tr>
>  <% fi %>
> -<% if grep -q "ONE_PORT" "/etc/network.$board_name" || grep -q "ETHPORT" "/etc/network.$board_name" ; then %>
> -	<%
> -		# Device has a port set by $ETHMODE
> -		. /etc/network.mode
> -		. /etc/network.config
> -	%>
> +<% if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] || [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ] ; then %>
>  	<tr><td>
>  	<fieldset>
>  		<legend>Ethernet Anschluss</legend>
> @@ -166,10 +159,10 @@ format_port() {
>  				<th style="width: 1em;">Anschluss&nbsp;Modus:</th>
>  				<td>
>  					<select name="mode">
> -						<option value="BATMAN" <% [ "$ETHMODE" = "BATMAN" ] && echo -n 'selected="selected" ' %>>BATMAN</option>
> -						<option value="CLIENT" <% [ "$ETHMODE" = "CLIENT" ] && echo -n 'selected="selected" ' %>>CLIENT</option>
> -						<% if grep -q "ONE_PORT" "/etc/network.$board_name" ; then %>
> -						<option value="WAN" <% [ "$ETHMODE" = "WAN" ] && echo -n 'selected="selected" ' %>>WAN</option>
> +						<option value="BATMAN">BATMAN</option>
> +						<option value="CLIENT">CLIENT</option>
> +						<% if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] ; then %>
> +						<option value="WAN">WAN</option>
>  						<% fi %>
>  					</select>
>  				</td>
> @@ -178,7 +171,7 @@ format_port() {
>  			<tr><td colspan="2"></td></tr>
>  			<tr><td colspan="2">
>  				WAN: Knoten stellt &uuml;ber Ethernet Anschluss Verbindung zum Internet her.<br />
> -				Client: Normale Clients stellen &uuml;ber Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
> +				CLIENT: Normale Clients stellen &uuml;ber Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
>  				BATMAN: Knoten stellt &uuml;ber Ethernet Anschluss Verbindung zu anderen MESH Knoten her.<br /><br />
>  
>  				Wenn diese Einstellung ver&auml;ndert wird, wird eine evtl. vorhandene manuelle Netzwerkkonfiguration in der
> @@ -189,12 +182,7 @@ format_port() {
>  	</fieldset>
>  	</td></tr>
>  <% fi %>
> -<% if grep -q "LAN0PORT" "/etc/network.$board_name" || grep -q "LAN1PORT" "/etc/network.$board_name" ; then %>
> -	<%
> -		# Device has two ports
> -		. /etc/network.mode
> -		. /etc/network.config
> -	%>
> +<% if [ "$(uci -q get fff.ui.portsetup)" = "cpev1" ] ; then %>
>  	<tr><td>
>  	<fieldset>
>  		<legend>Ethernet Anschl&uuml;sse</legend>
> @@ -207,16 +195,16 @@ format_port() {
>  			<tr>
>  				<td>
>  					<select name="mode0">
> -						<option value="BATMAN" <% [ "$LAN0MODE" = "BATMAN" ] && echo -n 'selected="selected" ' %>>BATMAN</option>
> -						<option value="CLIENT" <% [ "$LAN0MODE" = "CLIENT" ] && echo -n 'selected="selected" ' %>>CLIENT</option>
> -						<option value="WAN" <% [ "$LAN0MODE" = "WAN" ] && echo -n 'selected="selected" ' %>>WAN</option>
> +						<option value="BATMAN">BATMAN</option>
> +						<option value="CLIENT">CLIENT</option>
> +						<option value="WAN">WAN</option>
>  					</select>
>  				</td>
>  				<td>
>  					<select name="mode1">
> -						<option value="BATMAN" <% [ "$LAN1MODE" = "BATMAN" ] && echo -n 'selected="selected" ' %>>BATMAN</option>
> -						<option value="CLIENT" <% [ "$LAN1MODE" = "CLIENT" ] && echo -n 'selected="selected" ' %>>CLIENT</option>
> -						<option value="WAN" <% [ "$LAN1MODE" = "WAN" ] && echo -n 'selected="selected" ' %>>WAN</option>
> +						<option value="BATMAN">BATMAN</option>
> +						<option value="CLIENT">CLIENT</option>
> +						<option value="WAN">WAN</option>
>  					</select>
>  				</td>
>  				<td><input type="submit" name="change_twoport" /></td>
> @@ -224,7 +212,7 @@ format_port() {
>  			<tr><td colspan="3"></td></tr>
>  			<tr><td colspan="3">
>  				WAN: Knoten stellt &uuml;ber Ethernet Anschluss Verbindung zum Internet her.<br />
> -				Client: Normale Clients stellen &uuml;ber Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
> +				CLIENT: Normale Clients stellen &uuml;ber Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
>  				BATMAN: Knoten stellt &uuml;ber Ethernet Anschluss Verbindung zu anderen MESH Knoten her.<br /><br />
>  
>  				Wenn diese Einstellung ver&auml;ndert wird, wird eine evtl. vorhandene manuelle Netzwerkkonfiguration in der
Adrian Schmutzler April 23, 2019, 8:38 a.m.
Hallo,

hier ist mir noch ein Problem aufgefallen:

Um im WebUI gesetzte Ports für One-Port etc. upgradefest zu machen, verwende ich die Skripte in /usr/sbin (z.B. setoneport) und schreibe diese in die /etc/firstbootfff

In diesen Skripten steht jeweils aber ein /etc/init.d/network restart, die /etc/firstbootfff wird aber in den uci-defaults aufgerufen. Dies würde dann dazu führen, dass das Netzwerk beim nächsten Upgrade zu früh gestartet wird.

Ich sehe hier drei Lösungen:
1. Man wirft das /etc/init.d/network restart aus den Skripten in /usr/sbin raus und überlässt das dem User (ggf. per Echo darauf hinweisen). Die Skriptaufrufe können so im WebUI verbleiben.
   Diese Lösung wäre effektiv und einfach (und ist daher im Moment mein Favorit)
2. Man baut für die betroffenen Skripte nochmal eine kleine Funktion, die dann während uci-defaults aufgerufen werden kann. Die Funtionen kommen ins /etc/firstbootfff, die Skripte sind nur zum Aufruf während Laufzeit gedacht.
   (Nachteil: mehrfacher Code, include im /etc/firstbootfff nötig; Vorteil: Skriptnutzer in /usr/sbin muss nicht denken)
3. Man benutzt keine Funktionen und schreibt die relevanten paar Zeilen direkt in die /etc/firstbootfff (uci set dings, uci set bumms, uci commit)
   (Nachteil: man muss die bei jeder Änderung wieder irgendwie löschen (und dafür irgendwie matchen). D.h. wahrscheinlich alle Commands in eine Zeile ....)

So richtig geil finde ich nichts davon, wir können es aber nicht so lassen wie im Moment in diesem Patch.

Grüße

Adrian

> -----Original Message-----
> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf
> Of Adrian Schmutzler
> Sent: Montag, 22. April 2019 14:35
> To: franken-dev@freifunk.net
> Subject: [PATCH v3 06/14] fff-network/-support/-web: Nice setup of special-
> port devices
> 
> This patch:
> - provides scripts to easily change port configuration on the
>   "special" devices
> - provides a file to store upgrade-safe script lines run at
>   first boot (to be used for port adjustments)
> - fixes the port page in WebUI
> - fixes show_info
> 
> With this patch, instead of specifying data in network.config and then have a
> script to deal with it, we define a script /etc/firstbootfff where COMMANDS
> can be stored. Thus, one can just make switch ports permanent by putting
> the uci commands there.
> 
> To keep the convenient setup of one-port (and other special) devices, we
> implement script, e.g.
> setoneport "WAN"
> will set the port of a one-port device to WAN mode. Those scripts are used in
> the WebUI and may also be implemented manually in the /etc/firstbootfff
> file.
> 
> This patch misses the selection of the current port mode in the WebUI. It
> would have been too much additional code for this tiny feature.
> 
> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> 
> ---
> 
> This patch is built to reintroduce as much of the previous functionality as
> possible. One could however consider removing the CPE and AR150 special
> cases and leave only the real one-ports in the WebUI.
> 
> Changes in v2:
> - Removed some -q
> - Changed another PORTORDER in show_info
> - Renamed "twoport" to "cpev1"
> - Add ui.portsetup in 10-setup-fff
> - Restart network in scripts, no reboot necessary
> - Make 99-fff-sysupgrade append instead of overwrite
> 
> Changes in v3:
> - Added variable port in setoneport
> - Added uci commit fff at end of 22a-config-ports
> - Use new generic names: vlan1 etc.
> ---
>  .../fff-config/files/etc/uci-defaults/10-setup-fff |  3 +
>  .../files/etc/uci-defaults/22a-config-ports        |  5 ++
>  .../fff/fff-network/files/usr/sbin/set2ndport      | 30 +++++++++
>  .../fff/fff-network/files/usr/sbin/setcpev1        | 46 +++++++++++++
>  .../fff/fff-network/files/usr/sbin/setoneport      | 24 +++++++
>  src/packages/fff/fff-support/Makefile              |  2 +-
>  .../files/etc/uci-defaults/90-firstbootfff         | 13 ++++
>  .../fff/fff-support/files/usr/sbin/show_info       | 13 ++--
>  src/packages/fff/fff-sysupgrade/Makefile           |  2 +-
>  .../files/etc/uci-defaults/99-fff-sysupgrade       |  2 +-
>  src/packages/fff/fff-web/Makefile                  |  2 +-
>  .../fff/fff-web/files/www/ssl/cgi-bin/ports.html   | 78 +++++++++-------------
>  12 files changed, 162 insertions(+), 58 deletions(-)  create mode 100755
> src/packages/fff/fff-network/files/usr/sbin/set2ndport
>  create mode 100755 src/packages/fff/fff-network/files/usr/sbin/setcpev1
>  create mode 100755 src/packages/fff/fff-network/files/usr/sbin/setoneport
>  create mode 100644 src/packages/fff/fff-support/files/etc/uci-defaults/90-
> firstbootfff
> 
> diff --git a/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
> b/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
> index 3014f50d..a63ff6a9 100644
> --- a/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
> +++ b/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
> @@ -11,4 +11,7 @@ if ! uci -q get fff.system > /dev/null ; then
>  	uci set "fff.system.hostname=FFF"
>  fi
> 
> +uci set fff.ui=fff
> +uci -q get fff.ui.portsetup > /dev/null || uci set "fff.ui.portsetup=default"
> +
>  uci commit fff
> diff --git a/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-
> ports b/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
> index b8eaceab..cc7ab277 100644
> --- a/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
> +++ b/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-por
> +++ ts
> @@ -21,11 +21,13 @@ case "$BOARD" in
>  		# Default: LAN0: WAN, LAN1: CLIENT
>  		setupSwitch "eth0" "0t 4" "0t" "0t 5"
>  		setupWan "eth0.2"
> +		uci set "fff.ui.portsetup=cpev1"
>  		;;
>  	gl-ar150)
>  		# Default: CLIENT
>  		setupSwitch "eth1" "0t 1" "0t"
>  		setupWan "eth0"
> +		uci set "fff.ui.portsetup=2ndport"
>  		;;
>  	tl-wdr3500-v1|\
>  	tl-wr741nd-v2|\
> @@ -85,5 +87,8 @@ case "$BOARD" in
>  	ubnt-unifiac-lite|\
>  	ubnt-unifiac-mesh)
>  		setupOnePort "eth0" "CLIENT"
> +		uci set "fff.ui.portsetup=oneport"
>  		;;
>  esac
> +
> +uci commit fff
> diff --git a/src/packages/fff/fff-network/files/usr/sbin/set2ndport
> b/src/packages/fff/fff-network/files/usr/sbin/set2ndport
> new file mode 100755
> index 00000000..84aa5a2c
> --- /dev/null
> +++ b/src/packages/fff/fff-network/files/usr/sbin/set2ndport
> @@ -0,0 +1,30 @@
> +#!/bin/sh
> +
> +# This sets the port mode on second port without switch
> +
> +if ! [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ] ; then
> +	echo "Wrong device. This is for two-port devices without switch
> only!"
> +	exit 1
> +fi
> +
> +LAN0MODE=$1
> +
> +CLIENT_PORTS="0t"
> +BATMAN_PORTS="0t"
> +
> +if [ "$LAN0MODE" = "CLIENT" ] ; then
> +	CLIENT_PORTS="$CLIENT_PORTS 1"
> +elif [ "$LAN0MODE" = "BATMAN" ] ; then
> +	BATMAN_PORTS="$BATMAN_PORTS 1"
> +else
> +	echo "Wrong port mode. Choose one of: CLIENT, BATMAN"
> +	exit 1
> +fi
> +
> +uci set "network.vlan1.ports=$CLIENT_PORTS"
> +uci set "network.vlan3.ports=$BATMAN_PORTS"
> +uci commit network
> +
> +/etc/init.d/network restart
> +
> +echo "Port updated successfully."
> diff --git a/src/packages/fff/fff-network/files/usr/sbin/setcpev1
> b/src/packages/fff/fff-network/files/usr/sbin/setcpev1
> new file mode 100755
> index 00000000..5ed9a987
> --- /dev/null
> +++ b/src/packages/fff/fff-network/files/usr/sbin/setcpev1
> @@ -0,0 +1,46 @@
> +#!/bin/sh
> +
> +# This sets the port mode on CPE210 v1 and CPE510 v1
> +
> +if ! [ "$(uci -q get fff.ui.portsetup)" = "cpev1" ] ; then
> +	echo "Wrong device. This is for CPE210 v1 or CPE510 v1 only!"
> +	exit 1
> +fi
> +
> +LAN0MODE=$1
> +LAN1MODE=$2
> +
> +CLIENT_PORTS="0t"
> +WAN_PORTS="0t"
> +BATMAN_PORTS="0t"
> +
> +if [ "$LAN0MODE" = "WAN" ] ; then
> +	WAN_PORTS="$WAN_PORTS 5"
> +elif [ "$LAN0MODE" = "CLIENT" ] ; then
> +	CLIENT_PORTS="$CLIENT_PORTS 5"
> +elif [ "$LAN0MODE" = "BATMAN" ] ; then
> +	BATMAN_PORTS="$BATMAN_PORTS 5"
> +else
> +	echo "Wrong port mode for 1st port. Choose one of: WAN, CLIENT,
> BATMAN"
> +	exit 1
> +fi
> +
> +if [ "$LAN1MODE" = "WAN" ] ; then
> +	WAN_PORTS="$WAN_PORTS 4"
> +elif [ "$LAN1MODE" = "CLIENT" ] ; then
> +	CLIENT_PORTS="$CLIENT_PORTS 4"
> +elif [ "$LAN1MODE" = "BATMAN" ] ; then
> +	BATMAN_PORTS="$BATMAN_PORTS 4"
> +else
> +	echo "Wrong port mode for 2nd port. Choose one of: WAN, CLIENT,
> BATMAN"
> +	exit 1
> +fi
> +
> +uci set "network.vlan1.ports=$CLIENT_PORTS"
> +uci set "network.vlan2.ports=$WAN_PORTS"
> +uci set "network.vlan3.ports=$BATMAN_PORTS"
> +uci commit network
> +
> +/etc/init.d/network restart
> +
> +echo "Ports updated successfully."
> diff --git a/src/packages/fff/fff-network/files/usr/sbin/setoneport
> b/src/packages/fff/fff-network/files/usr/sbin/setoneport
> new file mode 100755
> index 00000000..37387827
> --- /dev/null
> +++ b/src/packages/fff/fff-network/files/usr/sbin/setoneport
> @@ -0,0 +1,24 @@
> +#!/bin/sh
> +
> +# This sets the port mode on one-port devices
> +
> +if ! [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] ; then
> +	echo "Wrong device. This is for one-port devices only!"
> +	exit 1
> +fi
> +
> +. /lib/functions/fff/networksetup
> +
> +ETHMODE=$1
> +DEV=$2
> +
> +[ -n "$DEV" ] || DEV="eth0"
> +
> +if [ "$ETHMODE" = "WAN" ] || [ "$ETHMODE" = "CLIENT" ] || [ "$ETHMODE"
> = "BATMAN" ]; then
> +	setupOnePort "$DEV" "$ETHMODE"
> +	/etc/init.d/network restart
> +	echo "Port updated successfully."
> +else
> +	echo "Wrong port mode. Choose one of: WAN, CLIENT, BATMAN"
> +	exit 1
> +fi
> diff --git a/src/packages/fff/fff-support/Makefile b/src/packages/fff/fff-
> support/Makefile
> index 56e35740..2fc74b0c 100644
> --- a/src/packages/fff/fff-support/Makefile
> +++ b/src/packages/fff/fff-support/Makefile
> @@ -1,7 +1,7 @@
>  include $(TOPDIR)/rules.mk
> 
>  PKG_NAME:=fff-support
> -PKG_RELEASE:=2
> +PKG_RELEASE:=3
> 
>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
> 
> diff --git a/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff
> b/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff
> new file mode 100644
> index 00000000..30c5ab12
> --- /dev/null
> +++ b/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootff
> +++ f
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +# Copyright 2019 Adrian Schmutzler
> +# License GPLv3
> +
> +LOCALUPGRADESCRIPT="/etc/firstbootfff"
> +
> +#add LOCALUPGRADESCRIPT to sysupgrade
> +grep -q ^"${LOCALUPGRADESCRIPT}"$ /etc/sysupgrade.conf || echo
> +"$LOCALUPGRADESCRIPT" >> /etc/sysupgrade.conf
> +
> +# process user commands
> +[ -s "$LOCALCONFIGSCRIPT" ] && {
> +	sh /etc/firstbootfff
> +}
> diff --git a/src/packages/fff/fff-support/files/usr/sbin/show_info
> b/src/packages/fff/fff-support/files/usr/sbin/show_info
> index d7ec8247..fb7f7d25 100755
> --- a/src/packages/fff/fff-support/files/usr/sbin/show_info
> +++ b/src/packages/fff/fff-support/files/usr/sbin/show_info
> @@ -3,6 +3,7 @@
>  . /etc/firmware_release
>  . /lib/functions/fff/evalhoodinfo
>  . /lib/functions/fff/evalbytes
> +. /lib/functions/fff/portorder
>  . /lib/functions.sh # required for config_load and config_foreach
> 
>  board_name=$(uci -q get board.model.name) @@ -187,13 +188,9 @@ fi
> echo "Download-Limit: $(uci -q get 'simple-tc.example.limit_ingress') kBit/s"
>  echo "Upload-Limit: $(uci -q get 'simple-tc.example.limit_egress') kBit/s"
> 
> -if grep -q 'PORTORDER=' /etc/network.$board_name ; then
> -	portorder=$(awk -F= '/PORTORDER=/ { print $2 }'
> /etc/network.$board_name | sed "s/\"//g")
> -fi
> -
>  echo ""
>  if swconfig list | grep -q switch0 ; then
> -	if [ -n "$portorder" ] ; then
> +	if [ -n "$PORTORDER" ] ; then
>  		echo "-> SWITCH (tatsaechliche Portreihenfolge)"
>  	else
>  		echo "-> SWITCH (interne logische Portreihenfolge)"
> @@ -218,7 +215,7 @@ if swconfig list | grep -q switch0 ; then
>  		printf '%-10s%-5s%-13s%s\n' "WAN-Port: " "${link} " "- WAN "
> "@ $speed"
>  	fi
> 
> -	for internalport in $portorder
> +	for internalport in $PORTORDER
>  	do
>  		line=$(swconfig dev switch0 port "$internalport" show | tr -d
> '\n' | tr -d '\t')
>  		port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/') @@ -
> 230,9 +227,7 @@ if swconfig list | grep -q switch0 ; then
>  	swconfig dev switch0 show | grep "\t*link:" | while read line ; do
>  		line=$(echo "$line" | tr -d '\n' | tr -d '\t')
>  		port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')
> -		if echo "$portorder" | grep -q "$port" ; then
> -			continue
> -		fi
> +		echo "$PORTORDER" | grep -q "$port" && continue
>  		printf '%-10s' "Port #${port}: "
>  		format_port "${line}"
>  	done
> diff --git a/src/packages/fff/fff-sysupgrade/Makefile b/src/packages/fff/fff-
> sysupgrade/Makefile
> index 0e6c08ec..0f2e6a1e 100644
> --- a/src/packages/fff/fff-sysupgrade/Makefile
> +++ b/src/packages/fff/fff-sysupgrade/Makefile
> @@ -1,7 +1,7 @@
>  include $(TOPDIR)/rules.mk
> 
>  PKG_NAME:=fff-sysupgrade
> -PKG_RELEASE:=10
> +PKG_RELEASE:=11
> 
>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
> 
> diff --git a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-
> sysupgrade b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-
> sysupgrade
> index f5783687..07f991e0 100644
> --- a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-
> sysupgrade
> +++ b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysu
> +++ pgrade
> @@ -2,7 +2,7 @@
>  # Copyright 2017 Tim Niemeyer
>  # License GPLv3
> 
> -cat > /etc/sysupgrade.conf <<-__EOF__
> +cat >> /etc/sysupgrade.conf <<-__EOF__
>  /etc/shadow
>  /etc/dropbear/dropbear_dss_host_key
>  /etc/dropbear/dropbear_rsa_host_key
> diff --git a/src/packages/fff/fff-web/Makefile b/src/packages/fff/fff-
> web/Makefile
> index 9bb10f71..819644a5 100644
> --- a/src/packages/fff/fff-web/Makefile
> +++ b/src/packages/fff/fff-web/Makefile
> @@ -1,7 +1,7 @@
>  include $(TOPDIR)/rules.mk
> 
>  PKG_NAME:=fff-web
> -PKG_RELEASE:=7
> +PKG_RELEASE:=8
> 
>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
> 
> diff --git a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
> b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
> index 01506fce..f990d4e4 100755
> --- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
> +++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
> @@ -2,22 +2,27 @@
> 
>  <%
>  board_name=$(uci -q get board.model.name)
> +LOCALUPGRADESCRIPT="/etc/firstbootfff"
> +
>  # write
>  if [ "$REQUEST_METHOD" = "POST" ] ; then
>  	if [ "$POST_change_mode" != "" ] ; then
> -		sed -i '/^.*# set via WebUI/d' /etc/network.config
> -		echo "ETHMODE=\"${POST_mode}\" # set via WebUI" >>
> /etc/network.config
> -		sed -i '/^FORCEPARSE/d' /etc/network.config
> -		echo "FORCEPARSE='2'" >> /etc/network.config
> +		if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ]; then
> +			setoneport "${POST_mode}"
> +			sed -i '/^setoneport.*/d' $LOCALUPGRADESCRIPT
> +			echo "setoneport \"${POST_mode}\" # set via
> WebUI" >> $LOCALUPGRADESCRIPT
> +		elif [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ]; then
> +			set2ndport "${POST_mode}"
> +			sed -i '/^set2ndport.*/d' $LOCALUPGRADESCRIPT
> +			echo "set2ndport \"${POST_mode}\" # set via
> WebUI" >> $LOCALUPGRADESCRIPT
> +		fi
>  		do_reboot=1
>  		MSG='<span class="green">Port Modus ge&auml;ndert!
> Router startet neu...</span>'
>  	fi
>  	if [ "$POST_change_twoport" != "" ] ; then
> -		sed -i '/^.*# set via WebUI/d' /etc/network.config
> -		echo "LAN0MODE=\"${POST_mode0}\" # set via WebUI" >>
> /etc/network.config
> -		echo "LAN1MODE=\"${POST_mode1}\" # set via WebUI" >>
> /etc/network.config
> -		sed -i '/^FORCEPARSE/d' /etc/network.config
> -		echo "FORCEPARSE='2'" >> /etc/network.config
> +		setcpev1 "${POST_mode0}" "${POST_mode1}"
> +		sed -i '/^setcpev1.*/d' $LOCALUPGRADESCRIPT
> +		echo "setcpev1 \"${POST_mode0}\" \"${POST_mode1}\" #
> set via WebUI"
> +>> $LOCALUPGRADESCRIPT
>  		do_reboot=1
>  		MSG='<span class="green">Port Modus ge&auml;ndert!
> Router startet neu...</span>'
>  	fi
> @@ -108,11 +113,8 @@ format_port() {
>  					echo "</td>"
>  				fi
> 
> -				if grep -q 'PORTORDER='
> /etc/network.$board_name ; then
> -					portorder=$(awk -F= '/PORTORDER=/
> { print $2 }' /etc/network.$board_name | sed "s/\"//g")
> -				fi
> -				for internalport in $portorder
> -				do
> +				. /lib/functions/fff/portorder
> +				for internalport in $PORTORDER ; do
>  					line=$(swconfig dev switch0 port
> "$internalport" show | tr -d '\n' | tr -d '\t')
>  					port=$(echo "$line" | sed 's/.*
> port:\([^ ]*\) .*/\1/')
>  					echo "<td class=\"swport\">"
> @@ -120,16 +122,12 @@ format_port() {
>  					format_port "${line}"
>  					echo "</td>"
>  				done
> -				if [ -n "$portorder" ] ; then
> -					echo "<td class=\"swport\"
> style=\"width:4em\"></td>"
> -				fi
> +				[ -n "$PORTORDER" ] && echo "<td
> class=\"swport\" style=\"width:4em\"></td>"
> 
>  				swconfig dev switch0 show | grep "\t*link:" |
> while read line ; do
>  					line=$(echo "$line" | tr -d '\n' | tr -d
> '\t')
>  					port=$(echo "$line" | sed 's/.*
> port:\([^ ]*\) .*/\1/')
> -					if echo "$portorder" | grep -q "$port" ;
> then
> -						continue
> -					fi
> +					echo "$PORTORDER" | grep -q "$port"
> && continue
>  					echo "<td class=\"swport\">"
>  					echo "<span class=\"port\">Port
> #${port}</span><br />"
>  					format_port "${line}"
> @@ -141,7 +139,7 @@ format_port() {
>  		<table>
>  			<tr><td></td></tr>
>  			<tr><td>
> -				<% if [ -n "$portorder" ] ; then %>
> +				<% if [ -n "$PORTORDER" ] ; then %>
>  				Dies zeigt die tats&auml;chliche Zuordnung
> der Ports, wobei der WAN Port auf der linken Seite liegt. Die Nummerierung
> entspricht der internen Zuordnung!<br />
>  				<% else %>
>  				Die Nummerierung und Reihenfolge der Ports
> entspricht nicht notwendigerweise der der Netzwerkanschl&uuml;sse am
> Router!<br /> @@ -152,12 +150,7 @@ format_port() {
>  	</fieldset>
>  	</td></tr>
>  <% fi %>
> -<% if grep -q "ONE_PORT" "/etc/network.$board_name" || grep -q
> "ETHPORT" "/etc/network.$board_name" ; then %>
> -	<%
> -		# Device has a port set by $ETHMODE
> -		. /etc/network.mode
> -		. /etc/network.config
> -	%>
> +<% if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] || [ "$(uci -q
> +get fff.ui.portsetup)" = "2ndport" ] ; then %>
>  	<tr><td>
>  	<fieldset>
>  		<legend>Ethernet Anschluss</legend>
> @@ -166,10 +159,10 @@ format_port() {
>  				<th style="width:
> 1em;">Anschluss&nbsp;Modus:</th>
>  				<td>
>  					<select name="mode">
> -						<option value="BATMAN" <%
> [ "$ETHMODE" = "BATMAN" ] && echo -n 'selected="selected" '
> %>>BATMAN</option>
> -						<option value="CLIENT" <% [
> "$ETHMODE" = "CLIENT" ] && echo -n 'selected="selected" '
> %>>CLIENT</option>
> -						<% if grep -q "ONE_PORT"
> "/etc/network.$board_name" ; then %>
> -						<option value="WAN" <% [
> "$ETHMODE" = "WAN" ] && echo -n 'selected="selected" '
> %>>WAN</option>
> +						<option
> value="BATMAN">BATMAN</option>
> +						<option
> value="CLIENT">CLIENT</option>
> +						<% if [ "$(uci -q get
> fff.ui.portsetup)" = "oneport" ] ; then %>
> +						<option
> value="WAN">WAN</option>
>  						<% fi %>
>  					</select>
>  				</td>
> @@ -178,7 +171,7 @@ format_port() {
>  			<tr><td colspan="2"></td></tr>
>  			<tr><td colspan="2">
>  				WAN: Knoten stellt &uuml;ber Ethernet
> Anschluss Verbindung zum Internet her.<br />
> -				Client: Normale Clients stellen &uuml;ber
> Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
> +				CLIENT: Normale Clients stellen &uuml;ber
> Ethernet Anschluss des
> +Knotens Verbindung zum Freifunk Netz her.<br />
>  				BATMAN: Knoten stellt &uuml;ber Ethernet
> Anschluss Verbindung zu anderen MESH Knoten her.<br /><br />
> 
>  				Wenn diese Einstellung ver&auml;ndert wird,
> wird eine evtl. vorhandene manuelle Netzwerkkonfiguration in der @@ -
> 189,12 +182,7 @@ format_port() {
>  	</fieldset>
>  	</td></tr>
>  <% fi %>
> -<% if grep -q "LAN0PORT" "/etc/network.$board_name" || grep -q
> "LAN1PORT" "/etc/network.$board_name" ; then %>
> -	<%
> -		# Device has two ports
> -		. /etc/network.mode
> -		. /etc/network.config
> -	%>
> +<% if [ "$(uci -q get fff.ui.portsetup)" = "cpev1" ] ; then %>
>  	<tr><td>
>  	<fieldset>
>  		<legend>Ethernet Anschl&uuml;sse</legend> @@ -207,16
> +195,16 @@ format_port() {
>  			<tr>
>  				<td>
>  					<select name="mode0">
> -						<option value="BATMAN" <%
> [ "$LAN0MODE" = "BATMAN" ] && echo -n 'selected="selected" '
> %>>BATMAN</option>
> -						<option value="CLIENT" <% [
> "$LAN0MODE" = "CLIENT" ] && echo -n 'selected="selected" '
> %>>CLIENT</option>
> -						<option value="WAN" <% [
> "$LAN0MODE" = "WAN" ] && echo -n 'selected="selected" '
> %>>WAN</option>
> +						<option
> value="BATMAN">BATMAN</option>
> +						<option
> value="CLIENT">CLIENT</option>
> +						<option
> value="WAN">WAN</option>
>  					</select>
>  				</td>
>  				<td>
>  					<select name="mode1">
> -						<option value="BATMAN" <%
> [ "$LAN1MODE" = "BATMAN" ] && echo -n 'selected="selected" '
> %>>BATMAN</option>
> -						<option value="CLIENT" <% [
> "$LAN1MODE" = "CLIENT" ] && echo -n 'selected="selected" '
> %>>CLIENT</option>
> -						<option value="WAN" <% [
> "$LAN1MODE" = "WAN" ] && echo -n 'selected="selected" '
> %>>WAN</option>
> +						<option
> value="BATMAN">BATMAN</option>
> +						<option
> value="CLIENT">CLIENT</option>
> +						<option
> value="WAN">WAN</option>
>  					</select>
>  				</td>
>  				<td><input type="submit"
> name="change_twoport" /></td> @@ -224,7 +212,7 @@ format_port() {
>  			<tr><td colspan="3"></td></tr>
>  			<tr><td colspan="3">
>  				WAN: Knoten stellt &uuml;ber Ethernet
> Anschluss Verbindung zum Internet her.<br />
> -				Client: Normale Clients stellen &uuml;ber
> Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
> +				CLIENT: Normale Clients stellen &uuml;ber
> Ethernet Anschluss des
> +Knotens Verbindung zum Freifunk Netz her.<br />
>  				BATMAN: Knoten stellt &uuml;ber Ethernet
> Anschluss Verbindung zu anderen MESH Knoten her.<br /><br />
> 
>  				Wenn diese Einstellung ver&auml;ndert wird,
> wird eine evtl. vorhandene manuelle Netzwerkkonfiguration in der
> --
> 2.11.0
Robert Langhammer April 23, 2019, 9:56 a.m.
Hi Adrian,

das ist mir gestern auch aufgefallen, habe aber den Skriptaufruf in den
uci-defaults nicht gefunden. Wo ist der denn?

Das Beste und Einfachste wäre wohl, das /etc/init.d/network raus zu nehmen.

Um den Restart kümmert sich dann procd. s.
https://openwrt.org/docs/guide-developer/procd-init-scripts

In init.d/network triggert procd auf network und wireless:

service_triggers()
{
        procd_add_reload_trigger network wireless

....


Robert



Am 23.04.19 um 10:38 schrieb mail@adrianschmutzler.de:
> Hallo,
>
> hier ist mir noch ein Problem aufgefallen:
>
> Um im WebUI gesetzte Ports für One-Port etc. upgradefest zu machen, verwende ich die Skripte in /usr/sbin (z.B. setoneport) und schreibe diese in die /etc/firstbootfff
>
> In diesen Skripten steht jeweils aber ein /etc/init.d/network restart, die /etc/firstbootfff wird aber in den uci-defaults aufgerufen. Dies würde dann dazu führen, dass das Netzwerk beim nächsten Upgrade zu früh gestartet wird.
>
> Ich sehe hier drei Lösungen:
> 1. Man wirft das /etc/init.d/network restart aus den Skripten in /usr/sbin raus und überlässt das dem User (ggf. per Echo darauf hinweisen). Die Skriptaufrufe können so im WebUI verbleiben.
>    Diese Lösung wäre effektiv und einfach (und ist daher im Moment mein Favorit)
> 2. Man baut für die betroffenen Skripte nochmal eine kleine Funktion, die dann während uci-defaults aufgerufen werden kann. Die Funtionen kommen ins /etc/firstbootfff, die Skripte sind nur zum Aufruf während Laufzeit gedacht.
>    (Nachteil: mehrfacher Code, include im /etc/firstbootfff nötig; Vorteil: Skriptnutzer in /usr/sbin muss nicht denken)
> 3. Man benutzt keine Funktionen und schreibt die relevanten paar Zeilen direkt in die /etc/firstbootfff (uci set dings, uci set bumms, uci commit)
>    (Nachteil: man muss die bei jeder Änderung wieder irgendwie löschen (und dafür irgendwie matchen). D.h. wahrscheinlich alle Commands in eine Zeile ....)
>
> So richtig geil finde ich nichts davon, wir können es aber nicht so lassen wie im Moment in diesem Patch.
>
> Grüße
>
> Adrian
>
>> -----Original Message-----
>> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf
>> Of Adrian Schmutzler
>> Sent: Montag, 22. April 2019 14:35
>> To: franken-dev@freifunk.net
>> Subject: [PATCH v3 06/14] fff-network/-support/-web: Nice setup of special-
>> port devices
>>
>> This patch:
>> - provides scripts to easily change port configuration on the
>>   "special" devices
>> - provides a file to store upgrade-safe script lines run at
>>   first boot (to be used for port adjustments)
>> - fixes the port page in WebUI
>> - fixes show_info
>>
>> With this patch, instead of specifying data in network.config and then have a
>> script to deal with it, we define a script /etc/firstbootfff where COMMANDS
>> can be stored. Thus, one can just make switch ports permanent by putting
>> the uci commands there.
>>
>> To keep the convenient setup of one-port (and other special) devices, we
>> implement script, e.g.
>> setoneport "WAN"
>> will set the port of a one-port device to WAN mode. Those scripts are used in
>> the WebUI and may also be implemented manually in the /etc/firstbootfff
>> file.
>>
>> This patch misses the selection of the current port mode in the WebUI. It
>> would have been too much additional code for this tiny feature.
>>
>> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
>>
>> ---
>>
>> This patch is built to reintroduce as much of the previous functionality as
>> possible. One could however consider removing the CPE and AR150 special
>> cases and leave only the real one-ports in the WebUI.
>>
>> Changes in v2:
>> - Removed some -q
>> - Changed another PORTORDER in show_info
>> - Renamed "twoport" to "cpev1"
>> - Add ui.portsetup in 10-setup-fff
>> - Restart network in scripts, no reboot necessary
>> - Make 99-fff-sysupgrade append instead of overwrite
>>
>> Changes in v3:
>> - Added variable port in setoneport
>> - Added uci commit fff at end of 22a-config-ports
>> - Use new generic names: vlan1 etc.
>> ---
>>  .../fff-config/files/etc/uci-defaults/10-setup-fff |  3 +
>>  .../files/etc/uci-defaults/22a-config-ports        |  5 ++
>>  .../fff/fff-network/files/usr/sbin/set2ndport      | 30 +++++++++
>>  .../fff/fff-network/files/usr/sbin/setcpev1        | 46 +++++++++++++
>>  .../fff/fff-network/files/usr/sbin/setoneport      | 24 +++++++
>>  src/packages/fff/fff-support/Makefile              |  2 +-
>>  .../files/etc/uci-defaults/90-firstbootfff         | 13 ++++
>>  .../fff/fff-support/files/usr/sbin/show_info       | 13 ++--
>>  src/packages/fff/fff-sysupgrade/Makefile           |  2 +-
>>  .../files/etc/uci-defaults/99-fff-sysupgrade       |  2 +-
>>  src/packages/fff/fff-web/Makefile                  |  2 +-
>>  .../fff/fff-web/files/www/ssl/cgi-bin/ports.html   | 78 +++++++++-------------
>>  12 files changed, 162 insertions(+), 58 deletions(-)  create mode 100755
>> src/packages/fff/fff-network/files/usr/sbin/set2ndport
>>  create mode 100755 src/packages/fff/fff-network/files/usr/sbin/setcpev1
>>  create mode 100755 src/packages/fff/fff-network/files/usr/sbin/setoneport
>>  create mode 100644 src/packages/fff/fff-support/files/etc/uci-defaults/90-
>> firstbootfff
>>
>> diff --git a/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
>> b/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
>> index 3014f50d..a63ff6a9 100644
>> --- a/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
>> +++ b/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
>> @@ -11,4 +11,7 @@ if ! uci -q get fff.system > /dev/null ; then
>>  	uci set "fff.system.hostname=FFF"
>>  fi
>>
>> +uci set fff.ui=fff
>> +uci -q get fff.ui.portsetup > /dev/null || uci set "fff.ui.portsetup=default"
>> +
>>  uci commit fff
>> diff --git a/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-
>> ports b/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
>> index b8eaceab..cc7ab277 100644
>> --- a/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
>> +++ b/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-por
>> +++ ts
>> @@ -21,11 +21,13 @@ case "$BOARD" in
>>  		# Default: LAN0: WAN, LAN1: CLIENT
>>  		setupSwitch "eth0" "0t 4" "0t" "0t 5"
>>  		setupWan "eth0.2"
>> +		uci set "fff.ui.portsetup=cpev1"
>>  		;;
>>  	gl-ar150)
>>  		# Default: CLIENT
>>  		setupSwitch "eth1" "0t 1" "0t"
>>  		setupWan "eth0"
>> +		uci set "fff.ui.portsetup=2ndport"
>>  		;;
>>  	tl-wdr3500-v1|\
>>  	tl-wr741nd-v2|\
>> @@ -85,5 +87,8 @@ case "$BOARD" in
>>  	ubnt-unifiac-lite|\
>>  	ubnt-unifiac-mesh)
>>  		setupOnePort "eth0" "CLIENT"
>> +		uci set "fff.ui.portsetup=oneport"
>>  		;;
>>  esac
>> +
>> +uci commit fff
>> diff --git a/src/packages/fff/fff-network/files/usr/sbin/set2ndport
>> b/src/packages/fff/fff-network/files/usr/sbin/set2ndport
>> new file mode 100755
>> index 00000000..84aa5a2c
>> --- /dev/null
>> +++ b/src/packages/fff/fff-network/files/usr/sbin/set2ndport
>> @@ -0,0 +1,30 @@
>> +#!/bin/sh
>> +
>> +# This sets the port mode on second port without switch
>> +
>> +if ! [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ] ; then
>> +	echo "Wrong device. This is for two-port devices without switch
>> only!"
>> +	exit 1
>> +fi
>> +
>> +LAN0MODE=$1
>> +
>> +CLIENT_PORTS="0t"
>> +BATMAN_PORTS="0t"
>> +
>> +if [ "$LAN0MODE" = "CLIENT" ] ; then
>> +	CLIENT_PORTS="$CLIENT_PORTS 1"
>> +elif [ "$LAN0MODE" = "BATMAN" ] ; then
>> +	BATMAN_PORTS="$BATMAN_PORTS 1"
>> +else
>> +	echo "Wrong port mode. Choose one of: CLIENT, BATMAN"
>> +	exit 1
>> +fi
>> +
>> +uci set "network.vlan1.ports=$CLIENT_PORTS"
>> +uci set "network.vlan3.ports=$BATMAN_PORTS"
>> +uci commit network
>> +
>> +/etc/init.d/network restart
>> +
>> +echo "Port updated successfully."
>> diff --git a/src/packages/fff/fff-network/files/usr/sbin/setcpev1
>> b/src/packages/fff/fff-network/files/usr/sbin/setcpev1
>> new file mode 100755
>> index 00000000..5ed9a987
>> --- /dev/null
>> +++ b/src/packages/fff/fff-network/files/usr/sbin/setcpev1
>> @@ -0,0 +1,46 @@
>> +#!/bin/sh
>> +
>> +# This sets the port mode on CPE210 v1 and CPE510 v1
>> +
>> +if ! [ "$(uci -q get fff.ui.portsetup)" = "cpev1" ] ; then
>> +	echo "Wrong device. This is for CPE210 v1 or CPE510 v1 only!"
>> +	exit 1
>> +fi
>> +
>> +LAN0MODE=$1
>> +LAN1MODE=$2
>> +
>> +CLIENT_PORTS="0t"
>> +WAN_PORTS="0t"
>> +BATMAN_PORTS="0t"
>> +
>> +if [ "$LAN0MODE" = "WAN" ] ; then
>> +	WAN_PORTS="$WAN_PORTS 5"
>> +elif [ "$LAN0MODE" = "CLIENT" ] ; then
>> +	CLIENT_PORTS="$CLIENT_PORTS 5"
>> +elif [ "$LAN0MODE" = "BATMAN" ] ; then
>> +	BATMAN_PORTS="$BATMAN_PORTS 5"
>> +else
>> +	echo "Wrong port mode for 1st port. Choose one of: WAN, CLIENT,
>> BATMAN"
>> +	exit 1
>> +fi
>> +
>> +if [ "$LAN1MODE" = "WAN" ] ; then
>> +	WAN_PORTS="$WAN_PORTS 4"
>> +elif [ "$LAN1MODE" = "CLIENT" ] ; then
>> +	CLIENT_PORTS="$CLIENT_PORTS 4"
>> +elif [ "$LAN1MODE" = "BATMAN" ] ; then
>> +	BATMAN_PORTS="$BATMAN_PORTS 4"
>> +else
>> +	echo "Wrong port mode for 2nd port. Choose one of: WAN, CLIENT,
>> BATMAN"
>> +	exit 1
>> +fi
>> +
>> +uci set "network.vlan1.ports=$CLIENT_PORTS"
>> +uci set "network.vlan2.ports=$WAN_PORTS"
>> +uci set "network.vlan3.ports=$BATMAN_PORTS"
>> +uci commit network
>> +
>> +/etc/init.d/network restart
>> +
>> +echo "Ports updated successfully."
>> diff --git a/src/packages/fff/fff-network/files/usr/sbin/setoneport
>> b/src/packages/fff/fff-network/files/usr/sbin/setoneport
>> new file mode 100755
>> index 00000000..37387827
>> --- /dev/null
>> +++ b/src/packages/fff/fff-network/files/usr/sbin/setoneport
>> @@ -0,0 +1,24 @@
>> +#!/bin/sh
>> +
>> +# This sets the port mode on one-port devices
>> +
>> +if ! [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] ; then
>> +	echo "Wrong device. This is for one-port devices only!"
>> +	exit 1
>> +fi
>> +
>> +. /lib/functions/fff/networksetup
>> +
>> +ETHMODE=$1
>> +DEV=$2
>> +
>> +[ -n "$DEV" ] || DEV="eth0"
>> +
>> +if [ "$ETHMODE" = "WAN" ] || [ "$ETHMODE" = "CLIENT" ] || [ "$ETHMODE"
>> = "BATMAN" ]; then
>> +	setupOnePort "$DEV" "$ETHMODE"
>> +	/etc/init.d/network restart
>> +	echo "Port updated successfully."
>> +else
>> +	echo "Wrong port mode. Choose one of: WAN, CLIENT, BATMAN"
>> +	exit 1
>> +fi
>> diff --git a/src/packages/fff/fff-support/Makefile b/src/packages/fff/fff-
>> support/Makefile
>> index 56e35740..2fc74b0c 100644
>> --- a/src/packages/fff/fff-support/Makefile
>> +++ b/src/packages/fff/fff-support/Makefile
>> @@ -1,7 +1,7 @@
>>  include $(TOPDIR)/rules.mk
>>
>>  PKG_NAME:=fff-support
>> -PKG_RELEASE:=2
>> +PKG_RELEASE:=3
>>
>>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
>>
>> diff --git a/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff
>> b/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff
>> new file mode 100644
>> index 00000000..30c5ab12
>> --- /dev/null
>> +++ b/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootff
>> +++ f
>> @@ -0,0 +1,13 @@
>> +#!/bin/sh
>> +# Copyright 2019 Adrian Schmutzler
>> +# License GPLv3
>> +
>> +LOCALUPGRADESCRIPT="/etc/firstbootfff"
>> +
>> +#add LOCALUPGRADESCRIPT to sysupgrade
>> +grep -q ^"${LOCALUPGRADESCRIPT}"$ /etc/sysupgrade.conf || echo
>> +"$LOCALUPGRADESCRIPT" >> /etc/sysupgrade.conf
>> +
>> +# process user commands
>> +[ -s "$LOCALCONFIGSCRIPT" ] && {
>> +	sh /etc/firstbootfff
>> +}
>> diff --git a/src/packages/fff/fff-support/files/usr/sbin/show_info
>> b/src/packages/fff/fff-support/files/usr/sbin/show_info
>> index d7ec8247..fb7f7d25 100755
>> --- a/src/packages/fff/fff-support/files/usr/sbin/show_info
>> +++ b/src/packages/fff/fff-support/files/usr/sbin/show_info
>> @@ -3,6 +3,7 @@
>>  . /etc/firmware_release
>>  . /lib/functions/fff/evalhoodinfo
>>  . /lib/functions/fff/evalbytes
>> +. /lib/functions/fff/portorder
>>  . /lib/functions.sh # required for config_load and config_foreach
>>
>>  board_name=$(uci -q get board.model.name) @@ -187,13 +188,9 @@ fi
>> echo "Download-Limit: $(uci -q get 'simple-tc.example.limit_ingress') kBit/s"
>>  echo "Upload-Limit: $(uci -q get 'simple-tc.example.limit_egress') kBit/s"
>>
>> -if grep -q 'PORTORDER=' /etc/network.$board_name ; then
>> -	portorder=$(awk -F= '/PORTORDER=/ { print $2 }'
>> /etc/network.$board_name | sed "s/\"//g")
>> -fi
>> -
>>  echo ""
>>  if swconfig list | grep -q switch0 ; then
>> -	if [ -n "$portorder" ] ; then
>> +	if [ -n "$PORTORDER" ] ; then
>>  		echo "-> SWITCH (tatsaechliche Portreihenfolge)"
>>  	else
>>  		echo "-> SWITCH (interne logische Portreihenfolge)"
>> @@ -218,7 +215,7 @@ if swconfig list | grep -q switch0 ; then
>>  		printf '%-10s%-5s%-13s%s\n' "WAN-Port: " "${link} " "- WAN "
>> "@ $speed"
>>  	fi
>>
>> -	for internalport in $portorder
>> +	for internalport in $PORTORDER
>>  	do
>>  		line=$(swconfig dev switch0 port "$internalport" show | tr -d
>> '\n' | tr -d '\t')
>>  		port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/') @@ -
>> 230,9 +227,7 @@ if swconfig list | grep -q switch0 ; then
>>  	swconfig dev switch0 show | grep "\t*link:" | while read line ; do
>>  		line=$(echo "$line" | tr -d '\n' | tr -d '\t')
>>  		port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')
>> -		if echo "$portorder" | grep -q "$port" ; then
>> -			continue
>> -		fi
>> +		echo "$PORTORDER" | grep -q "$port" && continue
>>  		printf '%-10s' "Port #${port}: "
>>  		format_port "${line}"
>>  	done
>> diff --git a/src/packages/fff/fff-sysupgrade/Makefile b/src/packages/fff/fff-
>> sysupgrade/Makefile
>> index 0e6c08ec..0f2e6a1e 100644
>> --- a/src/packages/fff/fff-sysupgrade/Makefile
>> +++ b/src/packages/fff/fff-sysupgrade/Makefile
>> @@ -1,7 +1,7 @@
>>  include $(TOPDIR)/rules.mk
>>
>>  PKG_NAME:=fff-sysupgrade
>> -PKG_RELEASE:=10
>> +PKG_RELEASE:=11
>>
>>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
>>
>> diff --git a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-
>> sysupgrade b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-
>> sysupgrade
>> index f5783687..07f991e0 100644
>> --- a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-
>> sysupgrade
>> +++ b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysu
>> +++ pgrade
>> @@ -2,7 +2,7 @@
>>  # Copyright 2017 Tim Niemeyer
>>  # License GPLv3
>>
>> -cat > /etc/sysupgrade.conf <<-__EOF__
>> +cat >> /etc/sysupgrade.conf <<-__EOF__
>>  /etc/shadow
>>  /etc/dropbear/dropbear_dss_host_key
>>  /etc/dropbear/dropbear_rsa_host_key
>> diff --git a/src/packages/fff/fff-web/Makefile b/src/packages/fff/fff-
>> web/Makefile
>> index 9bb10f71..819644a5 100644
>> --- a/src/packages/fff/fff-web/Makefile
>> +++ b/src/packages/fff/fff-web/Makefile
>> @@ -1,7 +1,7 @@
>>  include $(TOPDIR)/rules.mk
>>
>>  PKG_NAME:=fff-web
>> -PKG_RELEASE:=7
>> +PKG_RELEASE:=8
>>
>>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
>>
>> diff --git a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
>> b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
>> index 01506fce..f990d4e4 100755
>> --- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
>> +++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
>> @@ -2,22 +2,27 @@
>>
>>  <%
>>  board_name=$(uci -q get board.model.name)
>> +LOCALUPGRADESCRIPT="/etc/firstbootfff"
>> +
>>  # write
>>  if [ "$REQUEST_METHOD" = "POST" ] ; then
>>  	if [ "$POST_change_mode" != "" ] ; then
>> -		sed -i '/^.*# set via WebUI/d' /etc/network.config
>> -		echo "ETHMODE=\"${POST_mode}\" # set via WebUI" >>
>> /etc/network.config
>> -		sed -i '/^FORCEPARSE/d' /etc/network.config
>> -		echo "FORCEPARSE='2'" >> /etc/network.config
>> +		if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ]; then
>> +			setoneport "${POST_mode}"
>> +			sed -i '/^setoneport.*/d' $LOCALUPGRADESCRIPT
>> +			echo "setoneport \"${POST_mode}\" # set via
>> WebUI" >> $LOCALUPGRADESCRIPT
>> +		elif [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ]; then
>> +			set2ndport "${POST_mode}"
>> +			sed -i '/^set2ndport.*/d' $LOCALUPGRADESCRIPT
>> +			echo "set2ndport \"${POST_mode}\" # set via
>> WebUI" >> $LOCALUPGRADESCRIPT
>> +		fi
>>  		do_reboot=1
>>  		MSG='<span class="green">Port Modus ge&auml;ndert!
>> Router startet neu...</span>'
>>  	fi
>>  	if [ "$POST_change_twoport" != "" ] ; then
>> -		sed -i '/^.*# set via WebUI/d' /etc/network.config
>> -		echo "LAN0MODE=\"${POST_mode0}\" # set via WebUI" >>
>> /etc/network.config
>> -		echo "LAN1MODE=\"${POST_mode1}\" # set via WebUI" >>
>> /etc/network.config
>> -		sed -i '/^FORCEPARSE/d' /etc/network.config
>> -		echo "FORCEPARSE='2'" >> /etc/network.config
>> +		setcpev1 "${POST_mode0}" "${POST_mode1}"
>> +		sed -i '/^setcpev1.*/d' $LOCALUPGRADESCRIPT
>> +		echo "setcpev1 \"${POST_mode0}\" \"${POST_mode1}\" #
>> set via WebUI"
>> +>> $LOCALUPGRADESCRIPT
>>  		do_reboot=1
>>  		MSG='<span class="green">Port Modus ge&auml;ndert!
>> Router startet neu...</span>'
>>  	fi
>> @@ -108,11 +113,8 @@ format_port() {
>>  					echo "</td>"
>>  				fi
>>
>> -				if grep -q 'PORTORDER='
>> /etc/network.$board_name ; then
>> -					portorder=$(awk -F= '/PORTORDER=/
>> { print $2 }' /etc/network.$board_name | sed "s/\"//g")
>> -				fi
>> -				for internalport in $portorder
>> -				do
>> +				. /lib/functions/fff/portorder
>> +				for internalport in $PORTORDER ; do
>>  					line=$(swconfig dev switch0 port
>> "$internalport" show | tr -d '\n' | tr -d '\t')
>>  					port=$(echo "$line" | sed 's/.*
>> port:\([^ ]*\) .*/\1/')
>>  					echo "<td class=\"swport\">"
>> @@ -120,16 +122,12 @@ format_port() {
>>  					format_port "${line}"
>>  					echo "</td>"
>>  				done
>> -				if [ -n "$portorder" ] ; then
>> -					echo "<td class=\"swport\"
>> style=\"width:4em\"></td>"
>> -				fi
>> +				[ -n "$PORTORDER" ] && echo "<td
>> class=\"swport\" style=\"width:4em\"></td>"
>>
>>  				swconfig dev switch0 show | grep "\t*link:" |
>> while read line ; do
>>  					line=$(echo "$line" | tr -d '\n' | tr -d
>> '\t')
>>  					port=$(echo "$line" | sed 's/.*
>> port:\([^ ]*\) .*/\1/')
>> -					if echo "$portorder" | grep -q "$port" ;
>> then
>> -						continue
>> -					fi
>> +					echo "$PORTORDER" | grep -q "$port"
>> && continue
>>  					echo "<td class=\"swport\">"
>>  					echo "<span class=\"port\">Port
>> #${port}</span><br />"
>>  					format_port "${line}"
>> @@ -141,7 +139,7 @@ format_port() {
>>  		<table>
>>  			<tr><td></td></tr>
>>  			<tr><td>
>> -				<% if [ -n "$portorder" ] ; then %>
>> +				<% if [ -n "$PORTORDER" ] ; then %>
>>  				Dies zeigt die tats&auml;chliche Zuordnung
>> der Ports, wobei der WAN Port auf der linken Seite liegt. Die Nummerierung
>> entspricht der internen Zuordnung!<br />
>>  				<% else %>
>>  				Die Nummerierung und Reihenfolge der Ports
>> entspricht nicht notwendigerweise der der Netzwerkanschl&uuml;sse am
>> Router!<br /> @@ -152,12 +150,7 @@ format_port() {
>>  	</fieldset>
>>  	</td></tr>
>>  <% fi %>
>> -<% if grep -q "ONE_PORT" "/etc/network.$board_name" || grep -q
>> "ETHPORT" "/etc/network.$board_name" ; then %>
>> -	<%
>> -		# Device has a port set by $ETHMODE
>> -		. /etc/network.mode
>> -		. /etc/network.config
>> -	%>
>> +<% if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] || [ "$(uci -q
>> +get fff.ui.portsetup)" = "2ndport" ] ; then %>
>>  	<tr><td>
>>  	<fieldset>
>>  		<legend>Ethernet Anschluss</legend>
>> @@ -166,10 +159,10 @@ format_port() {
>>  				<th style="width:
>> 1em;">Anschluss&nbsp;Modus:</th>
>>  				<td>
>>  					<select name="mode">
>> -						<option value="BATMAN" <%
>> [ "$ETHMODE" = "BATMAN" ] && echo -n 'selected="selected" '
>> %>>BATMAN</option>
>> -						<option value="CLIENT" <% [
>> "$ETHMODE" = "CLIENT" ] && echo -n 'selected="selected" '
>> %>>CLIENT</option>
>> -						<% if grep -q "ONE_PORT"
>> "/etc/network.$board_name" ; then %>
>> -						<option value="WAN" <% [
>> "$ETHMODE" = "WAN" ] && echo -n 'selected="selected" '
>> %>>WAN</option>
>> +						<option
>> value="BATMAN">BATMAN</option>
>> +						<option
>> value="CLIENT">CLIENT</option>
>> +						<% if [ "$(uci -q get
>> fff.ui.portsetup)" = "oneport" ] ; then %>
>> +						<option
>> value="WAN">WAN</option>
>>  						<% fi %>
>>  					</select>
>>  				</td>
>> @@ -178,7 +171,7 @@ format_port() {
>>  			<tr><td colspan="2"></td></tr>
>>  			<tr><td colspan="2">
>>  				WAN: Knoten stellt &uuml;ber Ethernet
>> Anschluss Verbindung zum Internet her.<br />
>> -				Client: Normale Clients stellen &uuml;ber
>> Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
>> +				CLIENT: Normale Clients stellen &uuml;ber
>> Ethernet Anschluss des
>> +Knotens Verbindung zum Freifunk Netz her.<br />
>>  				BATMAN: Knoten stellt &uuml;ber Ethernet
>> Anschluss Verbindung zu anderen MESH Knoten her.<br /><br />
>>
>>  				Wenn diese Einstellung ver&auml;ndert wird,
>> wird eine evtl. vorhandene manuelle Netzwerkkonfiguration in der @@ -
>> 189,12 +182,7 @@ format_port() {
>>  	</fieldset>
>>  	</td></tr>
>>  <% fi %>
>> -<% if grep -q "LAN0PORT" "/etc/network.$board_name" || grep -q
>> "LAN1PORT" "/etc/network.$board_name" ; then %>
>> -	<%
>> -		# Device has two ports
>> -		. /etc/network.mode
>> -		. /etc/network.config
>> -	%>
>> +<% if [ "$(uci -q get fff.ui.portsetup)" = "cpev1" ] ; then %>
>>  	<tr><td>
>>  	<fieldset>
>>  		<legend>Ethernet Anschl&uuml;sse</legend> @@ -207,16
>> +195,16 @@ format_port() {
>>  			<tr>
>>  				<td>
>>  					<select name="mode0">
>> -						<option value="BATMAN" <%
>> [ "$LAN0MODE" = "BATMAN" ] && echo -n 'selected="selected" '
>> %>>BATMAN</option>
>> -						<option value="CLIENT" <% [
>> "$LAN0MODE" = "CLIENT" ] && echo -n 'selected="selected" '
>> %>>CLIENT</option>
>> -						<option value="WAN" <% [
>> "$LAN0MODE" = "WAN" ] && echo -n 'selected="selected" '
>> %>>WAN</option>
>> +						<option
>> value="BATMAN">BATMAN</option>
>> +						<option
>> value="CLIENT">CLIENT</option>
>> +						<option
>> value="WAN">WAN</option>
>>  					</select>
>>  				</td>
>>  				<td>
>>  					<select name="mode1">
>> -						<option value="BATMAN" <%
>> [ "$LAN1MODE" = "BATMAN" ] && echo -n 'selected="selected" '
>> %>>BATMAN</option>
>> -						<option value="CLIENT" <% [
>> "$LAN1MODE" = "CLIENT" ] && echo -n 'selected="selected" '
>> %>>CLIENT</option>
>> -						<option value="WAN" <% [
>> "$LAN1MODE" = "WAN" ] && echo -n 'selected="selected" '
>> %>>WAN</option>
>> +						<option
>> value="BATMAN">BATMAN</option>
>> +						<option
>> value="CLIENT">CLIENT</option>
>> +						<option
>> value="WAN">WAN</option>
>>  					</select>
>>  				</td>
>>  				<td><input type="submit"
>> name="change_twoport" /></td> @@ -224,7 +212,7 @@ format_port() {
>>  			<tr><td colspan="3"></td></tr>
>>  			<tr><td colspan="3">
>>  				WAN: Knoten stellt &uuml;ber Ethernet
>> Anschluss Verbindung zum Internet her.<br />
>> -				Client: Normale Clients stellen &uuml;ber
>> Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
>> +				CLIENT: Normale Clients stellen &uuml;ber
>> Ethernet Anschluss des
>> +Knotens Verbindung zum Freifunk Netz her.<br />
>>  				BATMAN: Knoten stellt &uuml;ber Ethernet
>> Anschluss Verbindung zu anderen MESH Knoten her.<br /><br />
>>
>>  				Wenn diese Einstellung ver&auml;ndert wird,
>> wird eine evtl. vorhandene manuelle Netzwerkkonfiguration in der
>> --
>> 2.11.0
Adrian Schmutzler April 23, 2019, 10:17 a.m.
Hallo Robert,

 

der Aufruf wird in diesem Patch mit eingefügt, mit einer ähnlichen Logik wie bei der rc.local.fff-dings:

 

new file mode 100644

index 00000000..30c5ab12

--- /dev/null

+++ b/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff

@@ -0,0 +1,13 @@ 

+#!/bin/sh

+# Copyright 2019 Adrian Schmutzler

+# License GPLv3

+

+LOCALUPGRADESCRIPT="/etc/firstbootfff"

+

+#add LOCALUPGRADESCRIPT to sysupgrade

+grep -q ^"${LOCALUPGRADESCRIPT}"$ /etc/sysupgrade.conf || echo "$LOCALUPGRADESCRIPT" >> /etc/sysupgrade.conf

+

+# process user commands

+[ -s "$LOCALCONFIGSCRIPT" ] && {

+             sh /etc/firstbootfff

+}

 

So wie wir die Datei verwenden sollte dieses Skript aber eigentlich noch nach fff-network verschoben werden, spätestens mit dem migration-Patch wird das ja notwendig. Ich mach das einfach mal.

 

Und ne Frage:

+# process user commands

+[ -s "$LOCALCONFIGSCRIPT" ] && sh /etc/firstbootfff

 

Wäre das gleichwertig, oder machen die Klammern irgendne subshell?

 

Grüße

 

Adrian

 

From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf Of robert
Sent: Dienstag, 23. April 2019 11:56
To: franken-dev@freifunk.net
Subject: Re: [PATCH v3 06/14] fff-network/-support/-web: Nice setup of special-port devices

 

Hi Adrian, 

das ist mir gestern auch aufgefallen, habe aber den Skriptaufruf in den 
uci-defaults nicht gefunden. Wo ist der denn? 

Das Beste und Einfachste wäre wohl, das /etc/init.d/network raus zu nehmen. 

Um den Restart kümmert sich dann procd. s. 
https://openwrt.org/docs/guide-developer/procd-init-scripts 

In init.d/network triggert procd auf network und wireless: 

service_triggers() 
{ 
        procd_add_reload_trigger network wireless 

.... 

 

Robert 

 

Am 23.04.19 um 10:38 schrieb mail@adrianschmutzler.de <mailto:mail@adrianschmutzler.de> : 
> Hallo, 
> 
> hier ist mir noch ein Problem aufgefallen: 
> 
> Um im WebUI gesetzte Ports für One-Port etc. upgradefest zu machen, verwende ich die Skripte in /usr/sbin (z.B. setoneport) und schreibe diese in die /etc/firstbootfff

> 
> In diesen Skripten steht jeweils aber ein /etc/init.d/network restart, die /etc/firstbootfff wird aber in den uci-defaults aufgerufen. Dies würde dann dazu führen, dass das Netzwerk beim nächsten Upgrade zu früh gestartet wird.

> 
> Ich sehe hier drei Lösungen: 
> 1. Man wirft das /etc/init.d/network restart aus den Skripten in /usr/sbin raus und überlässt das dem User (ggf. per Echo darauf hinweisen). Die Skriptaufrufe können so im WebUI verbleiben.

>    Diese Lösung wäre effektiv und einfach (und ist daher im Moment mein Favorit) 
> 2. Man baut für die betroffenen Skripte nochmal eine kleine Funktion, die dann während uci-defaults aufgerufen werden kann. Die Funtionen kommen ins /etc/firstbootfff, die Skripte sind nur zum Aufruf während Laufzeit gedacht.

>    (Nachteil: mehrfacher Code, include im /etc/firstbootfff nötig; Vorteil: Skriptnutzer in /usr/sbin muss nicht denken)

> 3. Man benutzt keine Funktionen und schreibt die relevanten paar Zeilen direkt in die /etc/firstbootfff (uci set dings, uci set bumms, uci commit)

>    (Nachteil: man muss die bei jeder Änderung wieder irgendwie löschen (und dafür irgendwie matchen). D.h. wahrscheinlich alle Commands in eine Zeile ....)

> 
> So richtig geil finde ich nichts davon, wir können es aber nicht so lassen wie im Moment in diesem Patch. 
> 
> Grüße 
> 
> Adrian 
> 
>> -----Original Message----- 
>> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf 
>> Of Adrian Schmutzler 
>> Sent: Montag, 22. April 2019 14:35 
>> To: franken-dev@freifunk.net <mailto:franken-dev@freifunk.net>  
>> Subject: [PATCH v3 06/14] fff-network/-support/-web: Nice setup of special- 
>> port devices 
>> 
>> This patch: 
>> - provides scripts to easily change port configuration on the 
>>   "special" devices 
>> - provides a file to store upgrade-safe script lines run at 
>>   first boot (to be used for port adjustments) 
>> - fixes the port page in WebUI 
>> - fixes show_info 
>> 
>> With this patch, instead of specifying data in network.config and then have a 
>> script to deal with it, we define a script /etc/firstbootfff where COMMANDS 
>> can be stored. Thus, one can just make switch ports permanent by putting 
>> the uci commands there. 
>> 
>> To keep the convenient setup of one-port (and other special) devices, we 
>> implement script, e.g. 
>> setoneport "WAN" 
>> will set the port of a one-port device to WAN mode. Those scripts are used in 
>> the WebUI and may also be implemented manually in the /etc/firstbootfff 
>> file. 
>> 
>> This patch misses the selection of the current port mode in the WebUI. It 
>> would have been too much additional code for this tiny feature. 
>> 
>> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de <mailto:freifunk@adrianschmutzler.de> > 
>> 
>> --- 
>> 
>> This patch is built to reintroduce as much of the previous functionality as 
>> possible. One could however consider removing the CPE and AR150 special 
>> cases and leave only the real one-ports in the WebUI. 
>> 
>> Changes in v2: 
>> - Removed some -q 
>> - Changed another PORTORDER in show_info 
>> - Renamed "twoport" to "cpev1" 
>> - Add ui.portsetup in 10-setup-fff 
>> - Restart network in scripts, no reboot necessary 
>> - Make 99-fff-sysupgrade append instead of overwrite 
>> 
>> Changes in v3: 
>> - Added variable port in setoneport 
>> - Added uci commit fff at end of 22a-config-ports 
>> - Use new generic names: vlan1 etc. 
>> --- 
>>  .../fff-config/files/etc/uci-defaults/10-setup-fff |  3 + 
>>  .../files/etc/uci-defaults/22a-config-ports        |  5 ++ 
>>  .../fff/fff-network/files/usr/sbin/set2ndport      | 30 +++++++++ 
>>  .../fff/fff-network/files/usr/sbin/setcpev1        | 46 +++++++++++++ 
>>  .../fff/fff-network/files/usr/sbin/setoneport      | 24 +++++++ 
>>  src/packages/fff/fff-support/Makefile              |  2 +- 
>>  .../files/etc/uci-defaults/90-firstbootfff         | 13 ++++ 
>>  .../fff/fff-support/files/usr/sbin/show_info       | 13 ++-- 
>>  src/packages/fff/fff-sysupgrade/Makefile           |  2 +- 
>>  .../files/etc/uci-defaults/99-fff-sysupgrade       |  2 +- 
>>  src/packages/fff/fff-web/Makefile                  |  2 +- 
>>  .../fff/fff-web/files/www/ssl/cgi-bin/ports.html   | 78 +++++++++------------- 
>>  12 files changed, 162 insertions(+), 58 deletions(-)  create mode 100755 
>> src/packages/fff/fff-network/files/usr/sbin/set2ndport 
>>  create mode 100755 src/packages/fff/fff-network/files/usr/sbin/setcpev1 
>>  create mode 100755 src/packages/fff/fff-network/files/usr/sbin/setoneport 
>>  create mode 100644 src/packages/fff/fff-support/files/etc/uci-defaults/90- 
>> firstbootfff 
>> 
>> diff --git a/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff 
>> b/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff 
>> index 3014f50d..a63ff6a9 100644 
>> --- a/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff 
>> +++ b/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff 
>> @@ -11,4 +11,7 @@ if ! uci -q get fff.system > /dev/null ; then 
>>      uci set "fff.system.hostname=FFF" 
>>  fi 
>> 
>> +uci set fff.ui=fff 
>> +uci -q get fff.ui.portsetup > /dev/null || uci set "fff.ui.portsetup=default" 
>> + 
>>  uci commit fff 
>> diff --git a/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config- 
>> ports b/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports 
>> index b8eaceab..cc7ab277 100644 
>> --- a/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports 
>> +++ b/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-por 
>> +++ ts 
>> @@ -21,11 +21,13 @@ case "$BOARD" in 
>>              # Default: LAN0: WAN, LAN1: CLIENT 
>>              setupSwitch "eth0" "0t 4" "0t" "0t 5" 
>>              setupWan "eth0.2" 
>> +            uci set "fff.ui.portsetup=cpev1" 
>>              ;; 
>>      gl-ar150) 
>>              # Default: CLIENT 
>>              setupSwitch "eth1" "0t 1" "0t" 
>>              setupWan "eth0" 
>> +            uci set "fff.ui.portsetup=2ndport" 
>>              ;; 
>>      tl-wdr3500-v1|\ 
>>      tl-wr741nd-v2|\ 
>> @@ -85,5 +87,8 @@ case "$BOARD" in 
>>      ubnt-unifiac-lite|\ 
>>      ubnt-unifiac-mesh) 
>>              setupOnePort "eth0" "CLIENT" 
>> +            uci set "fff.ui.portsetup=oneport" 
>>              ;; 
>>  esac 
>> + 
>> +uci commit fff 
>> diff --git a/src/packages/fff/fff-network/files/usr/sbin/set2ndport 
>> b/src/packages/fff/fff-network/files/usr/sbin/set2ndport 
>> new file mode 100755 
>> index 00000000..84aa5a2c 
>> --- /dev/null 
>> +++ b/src/packages/fff/fff-network/files/usr/sbin/set2ndport 
>> @@ -0,0 +1,30 @@ 
>> +#!/bin/sh 
>> + 
>> +# This sets the port mode on second port without switch 
>> + 
>> +if ! [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ] ; then 
>> +    echo "Wrong device. This is for two-port devices without switch 
>> only!" 
>> +    exit 1 
>> +fi 
>> + 
>> +LAN0MODE=$1 
>> + 
>> +CLIENT_PORTS="0t" 
>> +BATMAN_PORTS="0t" 
>> + 
>> +if [ "$LAN0MODE" = "CLIENT" ] ; then 
>> +    CLIENT_PORTS="$CLIENT_PORTS 1" 
>> +elif [ "$LAN0MODE" = "BATMAN" ] ; then 
>> +    BATMAN_PORTS="$BATMAN_PORTS 1" 
>> +else 
>> +    echo "Wrong port mode. Choose one of: CLIENT, BATMAN" 
>> +    exit 1 
>> +fi 
>> + 
>> +uci set "network.vlan1.ports=$CLIENT_PORTS" 
>> +uci set "network.vlan3.ports=$BATMAN_PORTS" 
>> +uci commit network 
>> + 
>> +/etc/init.d/network restart 
>> + 
>> +echo "Port updated successfully." 
>> diff --git a/src/packages/fff/fff-network/files/usr/sbin/setcpev1 
>> b/src/packages/fff/fff-network/files/usr/sbin/setcpev1 
>> new file mode 100755 
>> index 00000000..5ed9a987 
>> --- /dev/null 
>> +++ b/src/packages/fff/fff-network/files/usr/sbin/setcpev1 
>> @@ -0,0 +1,46 @@ 
>> +#!/bin/sh 
>> + 
>> +# This sets the port mode on CPE210 v1 and CPE510 v1 
>> + 
>> +if ! [ "$(uci -q get fff.ui.portsetup)" = "cpev1" ] ; then 
>> +    echo "Wrong device. This is for CPE210 v1 or CPE510 v1 only!" 
>> +    exit 1 
>> +fi 
>> + 
>> +LAN0MODE=$1 
>> +LAN1MODE=$2 
>> + 
>> +CLIENT_PORTS="0t" 
>> +WAN_PORTS="0t" 
>> +BATMAN_PORTS="0t" 
>> + 
>> +if [ "$LAN0MODE" = "WAN" ] ; then 
>> +    WAN_PORTS="$WAN_PORTS 5" 
>> +elif [ "$LAN0MODE" = "CLIENT" ] ; then 
>> +    CLIENT_PORTS="$CLIENT_PORTS 5" 
>> +elif [ "$LAN0MODE" = "BATMAN" ] ; then 
>> +    BATMAN_PORTS="$BATMAN_PORTS 5" 
>> +else 
>> +    echo "Wrong port mode for 1st port. Choose one of: WAN, CLIENT, 
>> BATMAN" 
>> +    exit 1 
>> +fi 
>> + 
>> +if [ "$LAN1MODE" = "WAN" ] ; then 
>> +    WAN_PORTS="$WAN_PORTS 4" 
>> +elif [ "$LAN1MODE" = "CLIENT" ] ; then 
>> +    CLIENT_PORTS="$CLIENT_PORTS 4" 
>> +elif [ "$LAN1MODE" = "BATMAN" ] ; then 
>> +    BATMAN_PORTS="$BATMAN_PORTS 4" 
>> +else 
>> +    echo "Wrong port mode for 2nd port. Choose one of: WAN, CLIENT, 
>> BATMAN" 
>> +    exit 1 
>> +fi 
>> + 
>> +uci set "network.vlan1.ports=$CLIENT_PORTS" 
>> +uci set "network.vlan2.ports=$WAN_PORTS" 
>> +uci set "network.vlan3.ports=$BATMAN_PORTS" 
>> +uci commit network 
>> + 
>> +/etc/init.d/network restart 
>> + 
>> +echo "Ports updated successfully." 
>> diff --git a/src/packages/fff/fff-network/files/usr/sbin/setoneport 
>> b/src/packages/fff/fff-network/files/usr/sbin/setoneport 
>> new file mode 100755 
>> index 00000000..37387827 
>> --- /dev/null 
>> +++ b/src/packages/fff/fff-network/files/usr/sbin/setoneport 
>> @@ -0,0 +1,24 @@ 
>> +#!/bin/sh 
>> + 
>> +# This sets the port mode on one-port devices 
>> + 
>> +if ! [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] ; then 
>> +    echo "Wrong device. This is for one-port devices only!" 
>> +    exit 1 
>> +fi 
>> + 
>> +. /lib/functions/fff/networksetup 
>> + 
>> +ETHMODE=$1 
>> +DEV=$2 
>> + 
>> +[ -n "$DEV" ] || DEV="eth0" 
>> + 
>> +if [ "$ETHMODE" = "WAN" ] || [ "$ETHMODE" = "CLIENT" ] || [ "$ETHMODE" 
>> = "BATMAN" ]; then 
>> +    setupOnePort "$DEV" "$ETHMODE" 
>> +    /etc/init.d/network restart 
>> +    echo "Port updated successfully." 
>> +else 
>> +    echo "Wrong port mode. Choose one of: WAN, CLIENT, BATMAN" 
>> +    exit 1 
>> +fi 
>> diff --git a/src/packages/fff/fff-support/Makefile b/src/packages/fff/fff- 
>> support/Makefile 
>> index 56e35740..2fc74b0c 100644 
>> --- a/src/packages/fff/fff-support/Makefile 
>> +++ b/src/packages/fff/fff-support/Makefile 
>> @@ -1,7 +1,7 @@ 
>>  include $(TOPDIR)/rules.mk 
>> 
>>  PKG_NAME:=fff-support 
>> -PKG_RELEASE:=2 
>> +PKG_RELEASE:=3 
>> 
>>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) 
>> 
>> diff --git a/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff 
>> b/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff 
>> new file mode 100644 
>> index 00000000..30c5ab12 
>> --- /dev/null 
>> +++ b/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootff 
>> +++ f 
>> @@ -0,0 +1,13 @@ 
>> +#!/bin/sh 
>> +# Copyright 2019 Adrian Schmutzler 
>> +# License GPLv3 
>> + 
>> +LOCALUPGRADESCRIPT="/etc/firstbootfff" 
>> + 
>> +#add LOCALUPGRADESCRIPT to sysupgrade 
>> +grep -q ^"${LOCALUPGRADESCRIPT}"$ /etc/sysupgrade.conf || echo 
>> +"$LOCALUPGRADESCRIPT" >> /etc/sysupgrade.conf 
>> + 
>> +# process user commands 
>> +[ -s "$LOCALCONFIGSCRIPT" ] && { 
>> +    sh /etc/firstbootfff 
>> +} 
>> diff --git a/src/packages/fff/fff-support/files/usr/sbin/show_info 
>> b/src/packages/fff/fff-support/files/usr/sbin/show_info 
>> index d7ec8247..fb7f7d25 100755 
>> --- a/src/packages/fff/fff-support/files/usr/sbin/show_info 
>> +++ b/src/packages/fff/fff-support/files/usr/sbin/show_info 
>> @@ -3,6 +3,7 @@ 
>>  . /etc/firmware_release 
>>  . /lib/functions/fff/evalhoodinfo 
>>  . /lib/functions/fff/evalbytes 
>> +. /lib/functions/fff/portorder 
>>  . /lib/functions.sh # required for config_load and config_foreach 
>> 
>>  board_name=$(uci -q get board.model.name) @@ -187,13 +188,9 @@ fi 
>> echo "Download-Limit: $(uci -q get 'simple-tc.example.limit_ingress') kBit/s" 
>>  echo "Upload-Limit: $(uci -q get 'simple-tc.example.limit_egress') kBit/s" 
>> 
>> -if grep -q 'PORTORDER=' /etc/network.$board_name ; then 
>> -    portorder=$(awk -F= '/PORTORDER=/ { print $2 }' 
>> /etc/network.$board_name | sed "s/\"//g") 
>> -fi 
>> - 
>>  echo "" 
>>  if swconfig list | grep -q switch0 ; then 
>> -    if [ -n "$portorder" ] ; then 
>> +    if [ -n "$PORTORDER" ] ; then 
>>              echo "-> SWITCH (tatsaechliche Portreihenfolge)" 
>>      else 
>>              echo "-> SWITCH (interne logische Portreihenfolge)" 
>> @@ -218,7 +215,7 @@ if swconfig list | grep -q switch0 ; then 
>>              printf '%-10s%-5s%-13s%s\n' "WAN-Port: " "${link} " "- WAN " 
>> "@ $speed" 
>>      fi 
>> 
>> -    for internalport in $portorder 
>> +    for internalport in $PORTORDER 
>>      do 
>>              line=$(swconfig dev switch0 port "$internalport" show | tr -d 
>> '\n' | tr -d '\t') 
>>              port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/') @@ - 
>> 230,9 +227,7 @@ if swconfig list | grep -q switch0 ; then 
>>      swconfig dev switch0 show | grep "\t*link:" | while read line ; do 
>>              line=$(echo "$line" | tr -d '\n' | tr -d '\t') 
>>              port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/') 
>> -            if echo "$portorder" | grep -q "$port" ; then 
>> -                    continue 
>> -            fi 
>> +            echo "$PORTORDER" | grep -q "$port" && continue 
>>              printf '%-10s' "Port #${port}: " 
>>              format_port "${line}" 
>>      done 
>> diff --git a/src/packages/fff/fff-sysupgrade/Makefile b/src/packages/fff/fff- 
>> sysupgrade/Makefile 
>> index 0e6c08ec..0f2e6a1e 100644 
>> --- a/src/packages/fff/fff-sysupgrade/Makefile 
>> +++ b/src/packages/fff/fff-sysupgrade/Makefile 
>> @@ -1,7 +1,7 @@ 
>>  include $(TOPDIR)/rules.mk 
>> 
>>  PKG_NAME:=fff-sysupgrade 
>> -PKG_RELEASE:=10 
>> +PKG_RELEASE:=11 
>> 
>>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) 
>> 
>> diff --git a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff- 
>> sysupgrade b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff- 
>> sysupgrade 
>> index f5783687..07f991e0 100644 
>> --- a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff- 
>> sysupgrade 
>> +++ b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysu 
>> +++ pgrade 
>> @@ -2,7 +2,7 @@ 
>>  # Copyright 2017 Tim Niemeyer 
>>  # License GPLv3 
>> 
>> -cat > /etc/sysupgrade.conf <<-__EOF__ 
>> +cat >> /etc/sysupgrade.conf <<-__EOF__ 
>>  /etc/shadow 
>>  /etc/dropbear/dropbear_dss_host_key 
>>  /etc/dropbear/dropbear_rsa_host_key 
>> diff --git a/src/packages/fff/fff-web/Makefile b/src/packages/fff/fff- 
>> web/Makefile 
>> index 9bb10f71..819644a5 100644 
>> --- a/src/packages/fff/fff-web/Makefile 
>> +++ b/src/packages/fff/fff-web/Makefile 
>> @@ -1,7 +1,7 @@ 
>>  include $(TOPDIR)/rules.mk 
>> 
>>  PKG_NAME:=fff-web 
>> -PKG_RELEASE:=7 
>> +PKG_RELEASE:=8 
>> 
>>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) 
>> 
>> diff --git a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html 
>> b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html 
>> index 01506fce..f990d4e4 100755 
>> --- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html 
>> +++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html 
>> @@ -2,22 +2,27 @@ 
>> 
>>  <% 
>>  board_name=$(uci -q get board.model.name) 
>> +LOCALUPGRADESCRIPT="/etc/firstbootfff" 
>> + 
>>  # write 
>>  if [ "$REQUEST_METHOD" = "POST" ] ; then 
>>      if [ "$POST_change_mode" != "" ] ; then 
>> -            sed -i '/^.*# set via WebUI/d' /etc/network.config 
>> -            echo "ETHMODE=\"${POST_mode}\" # set via WebUI" >> 
>> /etc/network.config 
>> -            sed -i '/^FORCEPARSE/d' /etc/network.config 
>> -            echo "FORCEPARSE='2'" >> /etc/network.config 
>> +            if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ]; then 
>> +                    setoneport "${POST_mode}" 
>> +                    sed -i '/^setoneport.*/d' $LOCALUPGRADESCRIPT 
>> +                    echo "setoneport \"${POST_mode}\" # set via 
>> WebUI" >> $LOCALUPGRADESCRIPT 
>> +            elif [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ]; then 
>> +                    set2ndport "${POST_mode}" 
>> +                    sed -i '/^set2ndport.*/d' $LOCALUPGRADESCRIPT 
>> +                    echo "set2ndport \"${POST_mode}\" # set via 
>> WebUI" >> $LOCALUPGRADESCRIPT 
>> +            fi 
>>              do_reboot=1 
>>              MSG='<span class="green">Port Modus ge&auml;ndert! 
>> Router startet neu...</span>' 
>>      fi 
>>      if [ "$POST_change_twoport" != "" ] ; then 
>> -            sed -i '/^.*# set via WebUI/d' /etc/network.config 
>> -            echo "LAN0MODE=\"${POST_mode0}\" # set via WebUI" >> 
>> /etc/network.config 
>> -            echo "LAN1MODE=\"${POST_mode1}\" # set via WebUI" >> 
>> /etc/network.config 
>> -            sed -i '/^FORCEPARSE/d' /etc/network.config 
>> -            echo "FORCEPARSE='2'" >> /etc/network.config 
>> +            setcpev1 "${POST_mode0}" "${POST_mode1}" 
>> +            sed -i '/^setcpev1.*/d' $LOCALUPGRADESCRIPT 
>> +            echo "setcpev1 \"${POST_mode0}\" \"${POST_mode1}\" # 
>> set via WebUI" 
>> +>> $LOCALUPGRADESCRIPT 
>>              do_reboot=1 
>>              MSG='<span class="green">Port Modus ge&auml;ndert! 
>> Router startet neu...</span>' 
>>      fi 
>> @@ -108,11 +113,8 @@ format_port() { 
>>                                      echo "</td>" 
>>                              fi 
>> 
>> -                            if grep -q 'PORTORDER=' 
>> /etc/network.$board_name ; then 
>> -                                    portorder=$(awk -F= '/PORTORDER=/ 
>> { print $2 }' /etc/network.$board_name | sed "s/\"//g") 
>> -                            fi 
>> -                            for internalport in $portorder 
>> -                            do 
>> +                            . /lib/functions/fff/portorder 
>> +                            for internalport in $PORTORDER ; do 
>>                                      line=$(swconfig dev switch0 port 
>> "$internalport" show | tr -d '\n' | tr -d '\t') 
>>                                      port=$(echo "$line" | sed 's/.* 
>> port:\([^ ]*\) .*/\1/') 
>>                                      echo "<td class=\"swport\">" 
>> @@ -120,16 +122,12 @@ format_port() { 
>>                                      format_port "${line}" 
>>                                      echo "</td>" 
>>                              done 
>> -                            if [ -n "$portorder" ] ; then 
>> -                                    echo "<td class=\"swport\" 
>> style=\"width:4em\"></td>" 
>> -                            fi 
>> +                            [ -n "$PORTORDER" ] && echo "<td 
>> class=\"swport\" style=\"width:4em\"></td>" 
>> 
>>                              swconfig dev switch0 show | grep "\t*link:" | 
>> while read line ; do 
>>                                      line=$(echo "$line" | tr -d '\n' | tr -d 
>> '\t') 
>>                                      port=$(echo "$line" | sed 's/.* 
>> port:\([^ ]*\) .*/\1/') 
>> -                                    if echo "$portorder" | grep -q "$port" ; 
>> then 
>> -                                            continue 
>> -                                    fi 
>> +                                    echo "$PORTORDER" | grep -q "$port" 
>> && continue 
>>                                      echo "<td class=\"swport\">" 
>>                                      echo "<span class=\"port\">Port 
>> #${port}</span><br />" 
>>                                      format_port "${line}" 
>> @@ -141,7 +139,7 @@ format_port() { 
>>              <table> 
>>                      <tr><td></td></tr> 
>>                      <tr><td> 
>> -                            <% if [ -n "$portorder" ] ; then %> 
>> +                            <% if [ -n "$PORTORDER" ] ; then %> 
>>                              Dies zeigt die tats&auml;chliche Zuordnung 
>> der Ports, wobei der WAN Port auf der linken Seite liegt. Die Nummerierung 
>> entspricht der internen Zuordnung!<br /> 
>>                              <% else %> 
>>                              Die Nummerierung und Reihenfolge der Ports 
>> entspricht nicht notwendigerweise der der Netzwerkanschl&uuml;sse am 
>> Router!<br /> @@ -152,12 +150,7 @@ format_port() { 
>>      </fieldset> 
>>      </td></tr> 
>>  <% fi %> 
>> -<% if grep -q "ONE_PORT" "/etc/network.$board_name" || grep -q 
>> "ETHPORT" "/etc/network.$board_name" ; then %> 
>> -    <% 
>> -            # Device has a port set by $ETHMODE 
>> -            . /etc/network.mode 
>> -            . /etc/network.config 
>> -    %> 
>> +<% if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] || [ "$(uci -q 
>> +get fff.ui.portsetup)" = "2ndport" ] ; then %> 
>>      <tr><td> 
>>      <fieldset> 
>>              <legend>Ethernet Anschluss</legend> 
>> @@ -166,10 +159,10 @@ format_port() { 
>>                              <th style="width: 
>> 1em;">Anschluss&nbsp;Modus:</th> 
>>                              <td> 
>>                                      <select name="mode"> 
>> -                                            <option value="BATMAN" <% 
>> [ "$ETHMODE" = "BATMAN" ] && echo -n 'selected="selected" ' 
>> %>>BATMAN</option> 
>> -                                            <option value="CLIENT" <% [ 
>> "$ETHMODE" = "CLIENT" ] && echo -n 'selected="selected" ' 
>> %>>CLIENT</option> 
>> -                                            <% if grep -q "ONE_PORT" 
>> "/etc/network.$board_name" ; then %> 
>> -                                            <option value="WAN" <% [ 
>> "$ETHMODE" = "WAN" ] && echo -n 'selected="selected" ' 
>> %>>WAN</option> 
>> +                                            <option 
>> value="BATMAN">BATMAN</option> 
>> +                                            <option 
>> value="CLIENT">CLIENT</option> 
>> +                                            <% if [ "$(uci -q get 
>> fff.ui.portsetup)" = "oneport" ] ; then %> 
>> +                                            <option 
>> value="WAN">WAN</option> 
>>                                              <% fi %> 
>>                                      </select> 
>>                              </td> 
>> @@ -178,7 +171,7 @@ format_port() { 
>>                      <tr><td colspan="2"></td></tr> 
>>                      <tr><td colspan="2"> 
>>                              WAN: Knoten stellt &uuml;ber Ethernet 
>> Anschluss Verbindung zum Internet her.<br /> 
>> -                            Client: Normale Clients stellen &uuml;ber 
>> Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br /> 
>> +                            CLIENT: Normale Clients stellen &uuml;ber 
>> Ethernet Anschluss des 
>> +Knotens Verbindung zum Freifunk Netz her.<br /> 
>>                              BATMAN: Knoten stellt &uuml;ber Ethernet 
>> Anschluss Verbindung zu anderen MESH Knoten her.<br /><br /> 
>> 
>>                              Wenn diese Einstellung ver&auml;ndert wird, 
>> wird eine evtl. vorhandene manuelle Netzwerkkonfiguration in der @@ - 
>> 189,12 +182,7 @@ format_port() { 
>>      </fieldset> 
>>      </td></tr> 
>>  <% fi %> 
>> -<% if grep -q "LAN0PORT" "/etc/network.$board_name" || grep -q 
>> "LAN1PORT" "/etc/network.$board_name" ; then %> 
>> -    <% 
>> -            # Device has two ports 
>> -            . /etc/network.mode 
>> -            . /etc/network.config 
>> -    %> 
>> +<% if [ "$(uci -q get fff.ui.portsetup)" = "cpev1" ] ; then %> 
>>      <tr><td> 
>>      <fieldset> 
>>              <legend>Ethernet Anschl&uuml;sse</legend> @@ -207,16 
>> +195,16 @@ format_port() { 
>>                      <tr> 
>>                              <td> 
>>                                      <select name="mode0"> 
>> -                                            <option value="BATMAN" <% 
>> [ "$LAN0MODE" = "BATMAN" ] && echo -n 'selected="selected" ' 
>> %>>BATMAN</option> 
>> -                                            <option value="CLIENT" <% [ 
>> "$LAN0MODE" = "CLIENT" ] && echo -n 'selected="selected" ' 
>> %>>CLIENT</option> 
>> -                                            <option value="WAN" <% [ 
>> "$LAN0MODE" = "WAN" ] && echo -n 'selected="selected" ' 
>> %>>WAN</option> 
>> +                                            <option 
>> value="BATMAN">BATMAN</option> 
>> +                                            <option 
>> value="CLIENT">CLIENT</option> 
>> +                                            <option 
>> value="WAN">WAN</option> 
>>                                      </select> 
>>                              </td> 
>>                              <td> 
>>                                      <select name="mode1"> 
>> -                                            <option value="BATMAN" <% 
>> [ "$LAN1MODE" = "BATMAN" ] && echo -n 'selected="selected" ' 
>> %>>BATMAN</option> 
>> -                                            <option value="CLIENT" <% [ 
>> "$LAN1MODE" = "CLIENT" ] && echo -n 'selected="selected" ' 
>> %>>CLIENT</option> 
>> -                                            <option value="WAN" <% [ 
>> "$LAN1MODE" = "WAN" ] && echo -n 'selected="selected" ' 
>> %>>WAN</option> 
>> +                                            <option 
>> value="BATMAN">BATMAN</option> 
>> +                                            <option 
>> value="CLIENT">CLIENT</option> 
>> +                                            <option 
>> value="WAN">WAN</option> 
>>                                      </select> 
>>                              </td> 
>>                              <td><input type="submit" 
>> name="change_twoport" /></td> @@ -224,7 +212,7 @@ format_port() { 
>>                      <tr><td colspan="3"></td></tr> 
>>                      <tr><td colspan="3"> 
>>                              WAN: Knoten stellt &uuml;ber Ethernet 
>> Anschluss Verbindung zum Internet her.<br /> 
>> -                            Client: Normale Clients stellen &uuml;ber 
>> Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br /> 
>> +                            CLIENT: Normale Clients stellen &uuml;ber 
>> Ethernet Anschluss des 
>> +Knotens Verbindung zum Freifunk Netz her.<br /> 
>>                              BATMAN: Knoten stellt &uuml;ber Ethernet 
>> Anschluss Verbindung zu anderen MESH Knoten her.<br /><br /> 
>> 
>>                              Wenn diese Einstellung ver&auml;ndert wird, 
>> wird eine evtl. vorhandene manuelle Netzwerkkonfiguration in der 
>> -- 
>> 2.11.0
Christian Dresel April 23, 2019, 11:21 a.m.
Acked-by: Christian Dresel <fff@chrisi01.de>

On 22.04.19 23:07, robert wrote:
> Hi Adrian,
>
> ich war ja anfangs etwas skeptisch wegen den Skripten in sbin. Es ist
> aber doch eine recht elegante Lösung, wenn man sich das im Ganzen anschaut.
>
> Reviewed-by: Robert Langhammer <rlanghammer@web.de>
>
> Am 22.04.19 um 14:35 schrieb Adrian Schmutzler:
>> This patch:
>> - provides scripts to easily change port configuration on the
>>   "special" devices
>> - provides a file to store upgrade-safe script lines run at
>>   first boot (to be used for port adjustments)
>> - fixes the port page in WebUI
>> - fixes show_info
>>
>> With this patch, instead of specifying data in network.config
>> and then have a script to deal with it, we define a script
>> /etc/firstbootfff where COMMANDS can be stored. Thus, one can
>> just make switch ports permanent by putting the uci commands there.
>>
>> To keep the convenient setup of one-port (and other special)
>> devices, we implement script, e.g.
>> setoneport "WAN"
>> will set the port of a one-port device to WAN mode. Those scripts
>> are used in the WebUI and may also be implemented manually in the
>> /etc/firstbootfff file.
>>
>> This patch misses the selection of the current port mode in the
>> WebUI. It would have been too much additional code for this
>> tiny feature.
>>
>> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
>>
>> ---
>>
>> This patch is built to reintroduce as much of the previous
>> functionality as possible. One could however consider removing the
>> CPE and AR150 special cases and leave only the real one-ports in
>> the WebUI.
>>
>> Changes in v2:
>> - Removed some -q
>> - Changed another PORTORDER in show_info
>> - Renamed "twoport" to "cpev1"
>> - Add ui.portsetup in 10-setup-fff
>> - Restart network in scripts, no reboot necessary
>> - Make 99-fff-sysupgrade append instead of overwrite
>>
>> Changes in v3:
>> - Added variable port in setoneport
>> - Added uci commit fff at end of 22a-config-ports
>> - Use new generic names: vlan1 etc.
>> ---
>>  .../fff-config/files/etc/uci-defaults/10-setup-fff |  3 +
>>  .../files/etc/uci-defaults/22a-config-ports        |  5 ++
>>  .../fff/fff-network/files/usr/sbin/set2ndport      | 30 +++++++++
>>  .../fff/fff-network/files/usr/sbin/setcpev1        | 46 +++++++++++++
>>  .../fff/fff-network/files/usr/sbin/setoneport      | 24 +++++++
>>  src/packages/fff/fff-support/Makefile              |  2 +-
>>  .../files/etc/uci-defaults/90-firstbootfff         | 13 ++++
>>  .../fff/fff-support/files/usr/sbin/show_info       | 13 ++--
>>  src/packages/fff/fff-sysupgrade/Makefile           |  2 +-
>>  .../files/etc/uci-defaults/99-fff-sysupgrade       |  2 +-
>>  src/packages/fff/fff-web/Makefile                  |  2 +-
>>  .../fff/fff-web/files/www/ssl/cgi-bin/ports.html   | 78 +++++++++-------------
>>  12 files changed, 162 insertions(+), 58 deletions(-)
>>  create mode 100755 src/packages/fff/fff-network/files/usr/sbin/set2ndport
>>  create mode 100755 src/packages/fff/fff-network/files/usr/sbin/setcpev1
>>  create mode 100755 src/packages/fff/fff-network/files/usr/sbin/setoneport
>>  create mode 100644 src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff
>>
>> diff --git a/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff b/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
>> index 3014f50d..a63ff6a9 100644
>> --- a/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
>> +++ b/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
>> @@ -11,4 +11,7 @@ if ! uci -q get fff.system > /dev/null ; then
>>  	uci set "fff.system.hostname=FFF"
>>  fi
>>  
>> +uci set fff.ui=fff
>> +uci -q get fff.ui.portsetup > /dev/null || uci set "fff.ui.portsetup=default"
>> +
>>  uci commit fff
>> diff --git a/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports b/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
>> index b8eaceab..cc7ab277 100644
>> --- a/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
>> +++ b/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
>> @@ -21,11 +21,13 @@ case "$BOARD" in
>>  		# Default: LAN0: WAN, LAN1: CLIENT
>>  		setupSwitch "eth0" "0t 4" "0t" "0t 5"
>>  		setupWan "eth0.2"
>> +		uci set "fff.ui.portsetup=cpev1"
>>  		;;
>>  	gl-ar150)
>>  		# Default: CLIENT
>>  		setupSwitch "eth1" "0t 1" "0t"
>>  		setupWan "eth0"
>> +		uci set "fff.ui.portsetup=2ndport"
>>  		;;
>>  	tl-wdr3500-v1|\
>>  	tl-wr741nd-v2|\
>> @@ -85,5 +87,8 @@ case "$BOARD" in
>>  	ubnt-unifiac-lite|\
>>  	ubnt-unifiac-mesh)
>>  		setupOnePort "eth0" "CLIENT"
>> +		uci set "fff.ui.portsetup=oneport"
>>  		;;
>>  esac
>> +
>> +uci commit fff
>> diff --git a/src/packages/fff/fff-network/files/usr/sbin/set2ndport b/src/packages/fff/fff-network/files/usr/sbin/set2ndport
>> new file mode 100755
>> index 00000000..84aa5a2c
>> --- /dev/null
>> +++ b/src/packages/fff/fff-network/files/usr/sbin/set2ndport
>> @@ -0,0 +1,30 @@
>> +#!/bin/sh
>> +
>> +# This sets the port mode on second port without switch
>> +
>> +if ! [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ] ; then
>> +	echo "Wrong device. This is for two-port devices without switch only!"
>> +	exit 1
>> +fi
>> +
>> +LAN0MODE=$1
>> +
>> +CLIENT_PORTS="0t"
>> +BATMAN_PORTS="0t"
>> +
>> +if [ "$LAN0MODE" = "CLIENT" ] ; then
>> +	CLIENT_PORTS="$CLIENT_PORTS 1"
>> +elif [ "$LAN0MODE" = "BATMAN" ] ; then
>> +	BATMAN_PORTS="$BATMAN_PORTS 1"
>> +else
>> +	echo "Wrong port mode. Choose one of: CLIENT, BATMAN"
>> +	exit 1
>> +fi
>> +
>> +uci set "network.vlan1.ports=$CLIENT_PORTS"
>> +uci set "network.vlan3.ports=$BATMAN_PORTS"
>> +uci commit network
>> +
>> +/etc/init.d/network restart
>> +
>> +echo "Port updated successfully."
>> diff --git a/src/packages/fff/fff-network/files/usr/sbin/setcpev1 b/src/packages/fff/fff-network/files/usr/sbin/setcpev1
>> new file mode 100755
>> index 00000000..5ed9a987
>> --- /dev/null
>> +++ b/src/packages/fff/fff-network/files/usr/sbin/setcpev1
>> @@ -0,0 +1,46 @@
>> +#!/bin/sh
>> +
>> +# This sets the port mode on CPE210 v1 and CPE510 v1
>> +
>> +if ! [ "$(uci -q get fff.ui.portsetup)" = "cpev1" ] ; then
>> +	echo "Wrong device. This is for CPE210 v1 or CPE510 v1 only!"
>> +	exit 1
>> +fi
>> +
>> +LAN0MODE=$1
>> +LAN1MODE=$2
>> +
>> +CLIENT_PORTS="0t"
>> +WAN_PORTS="0t"
>> +BATMAN_PORTS="0t"
>> +
>> +if [ "$LAN0MODE" = "WAN" ] ; then
>> +	WAN_PORTS="$WAN_PORTS 5"
>> +elif [ "$LAN0MODE" = "CLIENT" ] ; then
>> +	CLIENT_PORTS="$CLIENT_PORTS 5"
>> +elif [ "$LAN0MODE" = "BATMAN" ] ; then
>> +	BATMAN_PORTS="$BATMAN_PORTS 5"
>> +else
>> +	echo "Wrong port mode for 1st port. Choose one of: WAN, CLIENT, BATMAN"
>> +	exit 1
>> +fi
>> +
>> +if [ "$LAN1MODE" = "WAN" ] ; then
>> +	WAN_PORTS="$WAN_PORTS 4"
>> +elif [ "$LAN1MODE" = "CLIENT" ] ; then
>> +	CLIENT_PORTS="$CLIENT_PORTS 4"
>> +elif [ "$LAN1MODE" = "BATMAN" ] ; then
>> +	BATMAN_PORTS="$BATMAN_PORTS 4"
>> +else
>> +	echo "Wrong port mode for 2nd port. Choose one of: WAN, CLIENT, BATMAN"
>> +	exit 1
>> +fi
>> +
>> +uci set "network.vlan1.ports=$CLIENT_PORTS"
>> +uci set "network.vlan2.ports=$WAN_PORTS"
>> +uci set "network.vlan3.ports=$BATMAN_PORTS"
>> +uci commit network
>> +
>> +/etc/init.d/network restart
>> +
>> +echo "Ports updated successfully."
>> diff --git a/src/packages/fff/fff-network/files/usr/sbin/setoneport b/src/packages/fff/fff-network/files/usr/sbin/setoneport
>> new file mode 100755
>> index 00000000..37387827
>> --- /dev/null
>> +++ b/src/packages/fff/fff-network/files/usr/sbin/setoneport
>> @@ -0,0 +1,24 @@
>> +#!/bin/sh
>> +
>> +# This sets the port mode on one-port devices
>> +
>> +if ! [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] ; then
>> +	echo "Wrong device. This is for one-port devices only!"
>> +	exit 1
>> +fi
>> +
>> +. /lib/functions/fff/networksetup
>> +
>> +ETHMODE=$1
>> +DEV=$2
>> +
>> +[ -n "$DEV" ] || DEV="eth0"
>> +
>> +if [ "$ETHMODE" = "WAN" ] || [ "$ETHMODE" = "CLIENT" ] || [ "$ETHMODE" = "BATMAN" ]; then
>> +	setupOnePort "$DEV" "$ETHMODE"
>> +	/etc/init.d/network restart
>> +	echo "Port updated successfully."
>> +else
>> +	echo "Wrong port mode. Choose one of: WAN, CLIENT, BATMAN"
>> +	exit 1
>> +fi
>> diff --git a/src/packages/fff/fff-support/Makefile b/src/packages/fff/fff-support/Makefile
>> index 56e35740..2fc74b0c 100644
>> --- a/src/packages/fff/fff-support/Makefile
>> +++ b/src/packages/fff/fff-support/Makefile
>> @@ -1,7 +1,7 @@
>>  include $(TOPDIR)/rules.mk
>>  
>>  PKG_NAME:=fff-support
>> -PKG_RELEASE:=2
>> +PKG_RELEASE:=3
>>  
>>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
>>  
>> diff --git a/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff b/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff
>> new file mode 100644
>> index 00000000..30c5ab12
>> --- /dev/null
>> +++ b/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff
>> @@ -0,0 +1,13 @@
>> +#!/bin/sh
>> +# Copyright 2019 Adrian Schmutzler
>> +# License GPLv3
>> +
>> +LOCALUPGRADESCRIPT="/etc/firstbootfff"
>> +
>> +#add LOCALUPGRADESCRIPT to sysupgrade
>> +grep -q ^"${LOCALUPGRADESCRIPT}"$ /etc/sysupgrade.conf || echo "$LOCALUPGRADESCRIPT" >> /etc/sysupgrade.conf
>> +
>> +# process user commands
>> +[ -s "$LOCALCONFIGSCRIPT" ] && {
>> +	sh /etc/firstbootfff
>> +}
>> diff --git a/src/packages/fff/fff-support/files/usr/sbin/show_info b/src/packages/fff/fff-support/files/usr/sbin/show_info
>> index d7ec8247..fb7f7d25 100755
>> --- a/src/packages/fff/fff-support/files/usr/sbin/show_info
>> +++ b/src/packages/fff/fff-support/files/usr/sbin/show_info
>> @@ -3,6 +3,7 @@
>>  . /etc/firmware_release
>>  . /lib/functions/fff/evalhoodinfo
>>  . /lib/functions/fff/evalbytes
>> +. /lib/functions/fff/portorder
>>  . /lib/functions.sh # required for config_load and config_foreach
>>  
>>  board_name=$(uci -q get board.model.name)
>> @@ -187,13 +188,9 @@ fi
>>  echo "Download-Limit: $(uci -q get 'simple-tc.example.limit_ingress') kBit/s"
>>  echo "Upload-Limit: $(uci -q get 'simple-tc.example.limit_egress') kBit/s"
>>  
>> -if grep -q 'PORTORDER=' /etc/network.$board_name ; then
>> -	portorder=$(awk -F= '/PORTORDER=/ { print $2 }' /etc/network.$board_name | sed "s/\"//g")
>> -fi
>> -
>>  echo ""
>>  if swconfig list | grep -q switch0 ; then
>> -	if [ -n "$portorder" ] ; then
>> +	if [ -n "$PORTORDER" ] ; then
>>  		echo "-> SWITCH (tatsaechliche Portreihenfolge)"
>>  	else
>>  		echo "-> SWITCH (interne logische Portreihenfolge)"
>> @@ -218,7 +215,7 @@ if swconfig list | grep -q switch0 ; then
>>  		printf '%-10s%-5s%-13s%s\n' "WAN-Port: " "${link} " "- WAN " "@ $speed"
>>  	fi
>>  
>> -	for internalport in $portorder
>> +	for internalport in $PORTORDER
>>  	do
>>  		line=$(swconfig dev switch0 port "$internalport" show | tr -d '\n' | tr -d '\t')
>>  		port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')
>> @@ -230,9 +227,7 @@ if swconfig list | grep -q switch0 ; then
>>  	swconfig dev switch0 show | grep "\t*link:" | while read line ; do
>>  		line=$(echo "$line" | tr -d '\n' | tr -d '\t')
>>  		port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')
>> -		if echo "$portorder" | grep -q "$port" ; then
>> -			continue
>> -		fi
>> +		echo "$PORTORDER" | grep -q "$port" && continue
>>  		printf '%-10s' "Port #${port}: "
>>  		format_port "${line}"
>>  	done
>> diff --git a/src/packages/fff/fff-sysupgrade/Makefile b/src/packages/fff/fff-sysupgrade/Makefile
>> index 0e6c08ec..0f2e6a1e 100644
>> --- a/src/packages/fff/fff-sysupgrade/Makefile
>> +++ b/src/packages/fff/fff-sysupgrade/Makefile
>> @@ -1,7 +1,7 @@
>>  include $(TOPDIR)/rules.mk
>>  
>>  PKG_NAME:=fff-sysupgrade
>> -PKG_RELEASE:=10
>> +PKG_RELEASE:=11
>>  
>>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
>>  
>> diff --git a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysupgrade b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysupgrade
>> index f5783687..07f991e0 100644
>> --- a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysupgrade
>> +++ b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysupgrade
>> @@ -2,7 +2,7 @@
>>  # Copyright 2017 Tim Niemeyer
>>  # License GPLv3
>>  
>> -cat > /etc/sysupgrade.conf <<-__EOF__
>> +cat >> /etc/sysupgrade.conf <<-__EOF__
>>  /etc/shadow
>>  /etc/dropbear/dropbear_dss_host_key
>>  /etc/dropbear/dropbear_rsa_host_key
>> diff --git a/src/packages/fff/fff-web/Makefile b/src/packages/fff/fff-web/Makefile
>> index 9bb10f71..819644a5 100644
>> --- a/src/packages/fff/fff-web/Makefile
>> +++ b/src/packages/fff/fff-web/Makefile
>> @@ -1,7 +1,7 @@
>>  include $(TOPDIR)/rules.mk
>>  
>>  PKG_NAME:=fff-web
>> -PKG_RELEASE:=7
>> +PKG_RELEASE:=8
>>  
>>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
>>  
>> diff --git a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
>> index 01506fce..f990d4e4 100755
>> --- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
>> +++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
>> @@ -2,22 +2,27 @@
>>  
>>  <%
>>  board_name=$(uci -q get board.model.name)
>> +LOCALUPGRADESCRIPT="/etc/firstbootfff"
>> +
>>  # write
>>  if [ "$REQUEST_METHOD" = "POST" ] ; then
>>  	if [ "$POST_change_mode" != "" ] ; then
>> -		sed -i '/^.*# set via WebUI/d' /etc/network.config
>> -		echo "ETHMODE=\"${POST_mode}\" # set via WebUI" >> /etc/network.config
>> -		sed -i '/^FORCEPARSE/d' /etc/network.config
>> -		echo "FORCEPARSE='2'" >> /etc/network.config
>> +		if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ]; then
>> +			setoneport "${POST_mode}"
>> +			sed -i '/^setoneport.*/d' $LOCALUPGRADESCRIPT
>> +			echo "setoneport \"${POST_mode}\" # set via WebUI" >> $LOCALUPGRADESCRIPT
>> +		elif [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ]; then
>> +			set2ndport "${POST_mode}"
>> +			sed -i '/^set2ndport.*/d' $LOCALUPGRADESCRIPT
>> +			echo "set2ndport \"${POST_mode}\" # set via WebUI" >> $LOCALUPGRADESCRIPT
>> +		fi
>>  		do_reboot=1
>>  		MSG='<span class="green">Port Modus ge&auml;ndert! Router startet neu...</span>'
>>  	fi
>>  	if [ "$POST_change_twoport" != "" ] ; then
>> -		sed -i '/^.*# set via WebUI/d' /etc/network.config
>> -		echo "LAN0MODE=\"${POST_mode0}\" # set via WebUI" >> /etc/network.config
>> -		echo "LAN1MODE=\"${POST_mode1}\" # set via WebUI" >> /etc/network.config
>> -		sed -i '/^FORCEPARSE/d' /etc/network.config
>> -		echo "FORCEPARSE='2'" >> /etc/network.config
>> +		setcpev1 "${POST_mode0}" "${POST_mode1}"
>> +		sed -i '/^setcpev1.*/d' $LOCALUPGRADESCRIPT
>> +		echo "setcpev1 \"${POST_mode0}\" \"${POST_mode1}\" # set via WebUI" >> $LOCALUPGRADESCRIPT
>>  		do_reboot=1
>>  		MSG='<span class="green">Port Modus ge&auml;ndert! Router startet neu...</span>'
>>  	fi
>> @@ -108,11 +113,8 @@ format_port() {
>>  					echo "</td>"
>>  				fi
>>  				
>> -				if grep -q 'PORTORDER=' /etc/network.$board_name ; then
>> -					portorder=$(awk -F= '/PORTORDER=/ { print $2 }' /etc/network.$board_name | sed "s/\"//g")
>> -				fi
>> -				for internalport in $portorder
>> -				do
>> +				. /lib/functions/fff/portorder
>> +				for internalport in $PORTORDER ; do
>>  					line=$(swconfig dev switch0 port "$internalport" show | tr -d '\n' | tr -d '\t')
>>  					port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')
>>  					echo "<td class=\"swport\">"
>> @@ -120,16 +122,12 @@ format_port() {
>>  					format_port "${line}"
>>  					echo "</td>"
>>  				done
>> -				if [ -n "$portorder" ] ; then
>> -					echo "<td class=\"swport\" style=\"width:4em\"></td>"
>> -				fi
>> +				[ -n "$PORTORDER" ] && echo "<td class=\"swport\" style=\"width:4em\"></td>"
>>  				
>>  				swconfig dev switch0 show | grep "\t*link:" | while read line ; do
>>  					line=$(echo "$line" | tr -d '\n' | tr -d '\t')
>>  					port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')
>> -					if echo "$portorder" | grep -q "$port" ; then
>> -						continue
>> -					fi
>> +					echo "$PORTORDER" | grep -q "$port" && continue
>>  					echo "<td class=\"swport\">"
>>  					echo "<span class=\"port\">Port #${port}</span><br />"
>>  					format_port "${line}"
>> @@ -141,7 +139,7 @@ format_port() {
>>  		<table>
>>  			<tr><td></td></tr>
>>  			<tr><td>
>> -				<% if [ -n "$portorder" ] ; then %>
>> +				<% if [ -n "$PORTORDER" ] ; then %>
>>  				Dies zeigt die tats&auml;chliche Zuordnung der Ports, wobei der WAN Port auf der linken Seite liegt. Die Nummerierung entspricht der internen Zuordnung!<br />
>>  				<% else %>
>>  				Die Nummerierung und Reihenfolge der Ports entspricht nicht notwendigerweise der der Netzwerkanschl&uuml;sse am Router!<br />
>> @@ -152,12 +150,7 @@ format_port() {
>>  	</fieldset>
>>  	</td></tr>
>>  <% fi %>
>> -<% if grep -q "ONE_PORT" "/etc/network.$board_name" || grep -q "ETHPORT" "/etc/network.$board_name" ; then %>
>> -	<%
>> -		# Device has a port set by $ETHMODE
>> -		. /etc/network.mode
>> -		. /etc/network.config
>> -	%>
>> +<% if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] || [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ] ; then %>
>>  	<tr><td>
>>  	<fieldset>
>>  		<legend>Ethernet Anschluss</legend>
>> @@ -166,10 +159,10 @@ format_port() {
>>  				<th style="width: 1em;">Anschluss&nbsp;Modus:</th>
>>  				<td>
>>  					<select name="mode">
>> -						<option value="BATMAN" <% [ "$ETHMODE" = "BATMAN" ] && echo -n 'selected="selected" ' %>>BATMAN</option>
>> -						<option value="CLIENT" <% [ "$ETHMODE" = "CLIENT" ] && echo -n 'selected="selected" ' %>>CLIENT</option>
>> -						<% if grep -q "ONE_PORT" "/etc/network.$board_name" ; then %>
>> -						<option value="WAN" <% [ "$ETHMODE" = "WAN" ] && echo -n 'selected="selected" ' %>>WAN</option>
>> +						<option value="BATMAN">BATMAN</option>
>> +						<option value="CLIENT">CLIENT</option>
>> +						<% if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] ; then %>
>> +						<option value="WAN">WAN</option>
>>  						<% fi %>
>>  					</select>
>>  				</td>
>> @@ -178,7 +171,7 @@ format_port() {
>>  			<tr><td colspan="2"></td></tr>
>>  			<tr><td colspan="2">
>>  				WAN: Knoten stellt &uuml;ber Ethernet Anschluss Verbindung zum Internet her.<br />
>> -				Client: Normale Clients stellen &uuml;ber Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
>> +				CLIENT: Normale Clients stellen &uuml;ber Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
>>  				BATMAN: Knoten stellt &uuml;ber Ethernet Anschluss Verbindung zu anderen MESH Knoten her.<br /><br />
>>  
>>  				Wenn diese Einstellung ver&auml;ndert wird, wird eine evtl. vorhandene manuelle Netzwerkkonfiguration in der
>> @@ -189,12 +182,7 @@ format_port() {
>>  	</fieldset>
>>  	</td></tr>
>>  <% fi %>
>> -<% if grep -q "LAN0PORT" "/etc/network.$board_name" || grep -q "LAN1PORT" "/etc/network.$board_name" ; then %>
>> -	<%
>> -		# Device has two ports
>> -		. /etc/network.mode
>> -		. /etc/network.config
>> -	%>
>> +<% if [ "$(uci -q get fff.ui.portsetup)" = "cpev1" ] ; then %>
>>  	<tr><td>
>>  	<fieldset>
>>  		<legend>Ethernet Anschl&uuml;sse</legend>
>> @@ -207,16 +195,16 @@ format_port() {
>>  			<tr>
>>  				<td>
>>  					<select name="mode0">
>> -						<option value="BATMAN" <% [ "$LAN0MODE" = "BATMAN" ] && echo -n 'selected="selected" ' %>>BATMAN</option>
>> -						<option value="CLIENT" <% [ "$LAN0MODE" = "CLIENT" ] && echo -n 'selected="selected" ' %>>CLIENT</option>
>> -						<option value="WAN" <% [ "$LAN0MODE" = "WAN" ] && echo -n 'selected="selected" ' %>>WAN</option>
>> +						<option value="BATMAN">BATMAN</option>
>> +						<option value="CLIENT">CLIENT</option>
>> +						<option value="WAN">WAN</option>
>>  					</select>
>>  				</td>
>>  				<td>
>>  					<select name="mode1">
>> -						<option value="BATMAN" <% [ "$LAN1MODE" = "BATMAN" ] && echo -n 'selected="selected" ' %>>BATMAN</option>
>> -						<option value="CLIENT" <% [ "$LAN1MODE" = "CLIENT" ] && echo -n 'selected="selected" ' %>>CLIENT</option>
>> -						<option value="WAN" <% [ "$LAN1MODE" = "WAN" ] && echo -n 'selected="selected" ' %>>WAN</option>
>> +						<option value="BATMAN">BATMAN</option>
>> +						<option value="CLIENT">CLIENT</option>
>> +						<option value="WAN">WAN</option>
>>  					</select>
>>  				</td>
>>  				<td><input type="submit" name="change_twoport" /></td>
>> @@ -224,7 +212,7 @@ format_port() {
>>  			<tr><td colspan="3"></td></tr>
>>  			<tr><td colspan="3">
>>  				WAN: Knoten stellt &uuml;ber Ethernet Anschluss Verbindung zum Internet her.<br />
>> -				Client: Normale Clients stellen &uuml;ber Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
>> +				CLIENT: Normale Clients stellen &uuml;ber Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
>>  				BATMAN: Knoten stellt &uuml;ber Ethernet Anschluss Verbindung zu anderen MESH Knoten her.<br /><br />
>>  
>>  				Wenn diese Einstellung ver&auml;ndert wird, wird eine evtl. vorhandene manuelle Netzwerkkonfiguration in der
Robert Langhammer April 27, 2019, 7:13 p.m.
Hi Adrian,

zu dem Problem hab ich eine gute Lösung gefunden. Man kann mit "ubus
list network" feststellen ob /etc/init.d/network schon gelaufen ist.
Wenn nicht kommt ein Fehler.

Mann kann also das network restart davon abhängig machen. z.B

ubus list network && /etc/init.d/network restart

War etwas tricky das zu testen bevor das Netz an ist. Wollte schon den
Lötkolben anwerfen. Einfacher war dann ein init-testskript, das vor
network läuft.

Grüße

Robert


Am 23.04.19 um 10:38 schrieb mail@adrianschmutzler.de:
> Hallo,
>
> hier ist mir noch ein Problem aufgefallen:
>
> Um im WebUI gesetzte Ports für One-Port etc. upgradefest zu machen, verwende ich die Skripte in /usr/sbin (z.B. setoneport) und schreibe diese in die /etc/firstbootfff
>
> In diesen Skripten steht jeweils aber ein /etc/init.d/network restart, die /etc/firstbootfff wird aber in den uci-defaults aufgerufen. Dies würde dann dazu führen, dass das Netzwerk beim nächsten Upgrade zu früh gestartet wird.
>
> Ich sehe hier drei Lösungen:
> 1. Man wirft das /etc/init.d/network restart aus den Skripten in /usr/sbin raus und überlässt das dem User (ggf. per Echo darauf hinweisen). Die Skriptaufrufe können so im WebUI verbleiben.
>    Diese Lösung wäre effektiv und einfach (und ist daher im Moment mein Favorit)
> 2. Man baut für die betroffenen Skripte nochmal eine kleine Funktion, die dann während uci-defaults aufgerufen werden kann. Die Funtionen kommen ins /etc/firstbootfff, die Skripte sind nur zum Aufruf während Laufzeit gedacht.
>    (Nachteil: mehrfacher Code, include im /etc/firstbootfff nötig; Vorteil: Skriptnutzer in /usr/sbin muss nicht denken)
> 3. Man benutzt keine Funktionen und schreibt die relevanten paar Zeilen direkt in die /etc/firstbootfff (uci set dings, uci set bumms, uci commit)
>    (Nachteil: man muss die bei jeder Änderung wieder irgendwie löschen (und dafür irgendwie matchen). D.h. wahrscheinlich alle Commands in eine Zeile ....)
>
> So richtig geil finde ich nichts davon, wir können es aber nicht so lassen wie im Moment in diesem Patch.
>
> Grüße
>
> Adrian
>
>> -----Original Message-----
>> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf
>> Of Adrian Schmutzler
>> Sent: Montag, 22. April 2019 14:35
>> To: franken-dev@freifunk.net
>> Subject: [PATCH v3 06/14] fff-network/-support/-web: Nice setup of special-
>> port devices
>>
>> This patch:
>> - provides scripts to easily change port configuration on the
>>   "special" devices
>> - provides a file to store upgrade-safe script lines run at
>>   first boot (to be used for port adjustments)
>> - fixes the port page in WebUI
>> - fixes show_info
>>
>> With this patch, instead of specifying data in network.config and then have a
>> script to deal with it, we define a script /etc/firstbootfff where COMMANDS
>> can be stored. Thus, one can just make switch ports permanent by putting
>> the uci commands there.
>>
>> To keep the convenient setup of one-port (and other special) devices, we
>> implement script, e.g.
>> setoneport "WAN"
>> will set the port of a one-port device to WAN mode. Those scripts are used in
>> the WebUI and may also be implemented manually in the /etc/firstbootfff
>> file.
>>
>> This patch misses the selection of the current port mode in the WebUI. It
>> would have been too much additional code for this tiny feature.
>>
>> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
>>
>> ---
>>
>> This patch is built to reintroduce as much of the previous functionality as
>> possible. One could however consider removing the CPE and AR150 special
>> cases and leave only the real one-ports in the WebUI.
>>
>> Changes in v2:
>> - Removed some -q
>> - Changed another PORTORDER in show_info
>> - Renamed "twoport" to "cpev1"
>> - Add ui.portsetup in 10-setup-fff
>> - Restart network in scripts, no reboot necessary
>> - Make 99-fff-sysupgrade append instead of overwrite
>>
>> Changes in v3:
>> - Added variable port in setoneport
>> - Added uci commit fff at end of 22a-config-ports
>> - Use new generic names: vlan1 etc.
>> ---
>>  .../fff-config/files/etc/uci-defaults/10-setup-fff |  3 +
>>  .../files/etc/uci-defaults/22a-config-ports        |  5 ++
>>  .../fff/fff-network/files/usr/sbin/set2ndport      | 30 +++++++++
>>  .../fff/fff-network/files/usr/sbin/setcpev1        | 46 +++++++++++++
>>  .../fff/fff-network/files/usr/sbin/setoneport      | 24 +++++++
>>  src/packages/fff/fff-support/Makefile              |  2 +-
>>  .../files/etc/uci-defaults/90-firstbootfff         | 13 ++++
>>  .../fff/fff-support/files/usr/sbin/show_info       | 13 ++--
>>  src/packages/fff/fff-sysupgrade/Makefile           |  2 +-
>>  .../files/etc/uci-defaults/99-fff-sysupgrade       |  2 +-
>>  src/packages/fff/fff-web/Makefile                  |  2 +-
>>  .../fff/fff-web/files/www/ssl/cgi-bin/ports.html   | 78 +++++++++-------------
>>  12 files changed, 162 insertions(+), 58 deletions(-)  create mode 100755
>> src/packages/fff/fff-network/files/usr/sbin/set2ndport
>>  create mode 100755 src/packages/fff/fff-network/files/usr/sbin/setcpev1
>>  create mode 100755 src/packages/fff/fff-network/files/usr/sbin/setoneport
>>  create mode 100644 src/packages/fff/fff-support/files/etc/uci-defaults/90-
>> firstbootfff
>>
>> diff --git a/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
>> b/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
>> index 3014f50d..a63ff6a9 100644
>> --- a/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
>> +++ b/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
>> @@ -11,4 +11,7 @@ if ! uci -q get fff.system > /dev/null ; then
>>  	uci set "fff.system.hostname=FFF"
>>  fi
>>
>> +uci set fff.ui=fff
>> +uci -q get fff.ui.portsetup > /dev/null || uci set "fff.ui.portsetup=default"
>> +
>>  uci commit fff
>> diff --git a/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-
>> ports b/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
>> index b8eaceab..cc7ab277 100644
>> --- a/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
>> +++ b/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-por
>> +++ ts
>> @@ -21,11 +21,13 @@ case "$BOARD" in
>>  		# Default: LAN0: WAN, LAN1: CLIENT
>>  		setupSwitch "eth0" "0t 4" "0t" "0t 5"
>>  		setupWan "eth0.2"
>> +		uci set "fff.ui.portsetup=cpev1"
>>  		;;
>>  	gl-ar150)
>>  		# Default: CLIENT
>>  		setupSwitch "eth1" "0t 1" "0t"
>>  		setupWan "eth0"
>> +		uci set "fff.ui.portsetup=2ndport"
>>  		;;
>>  	tl-wdr3500-v1|\
>>  	tl-wr741nd-v2|\
>> @@ -85,5 +87,8 @@ case "$BOARD" in
>>  	ubnt-unifiac-lite|\
>>  	ubnt-unifiac-mesh)
>>  		setupOnePort "eth0" "CLIENT"
>> +		uci set "fff.ui.portsetup=oneport"
>>  		;;
>>  esac
>> +
>> +uci commit fff
>> diff --git a/src/packages/fff/fff-network/files/usr/sbin/set2ndport
>> b/src/packages/fff/fff-network/files/usr/sbin/set2ndport
>> new file mode 100755
>> index 00000000..84aa5a2c
>> --- /dev/null
>> +++ b/src/packages/fff/fff-network/files/usr/sbin/set2ndport
>> @@ -0,0 +1,30 @@
>> +#!/bin/sh
>> +
>> +# This sets the port mode on second port without switch
>> +
>> +if ! [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ] ; then
>> +	echo "Wrong device. This is for two-port devices without switch
>> only!"
>> +	exit 1
>> +fi
>> +
>> +LAN0MODE=$1
>> +
>> +CLIENT_PORTS="0t"
>> +BATMAN_PORTS="0t"
>> +
>> +if [ "$LAN0MODE" = "CLIENT" ] ; then
>> +	CLIENT_PORTS="$CLIENT_PORTS 1"
>> +elif [ "$LAN0MODE" = "BATMAN" ] ; then
>> +	BATMAN_PORTS="$BATMAN_PORTS 1"
>> +else
>> +	echo "Wrong port mode. Choose one of: CLIENT, BATMAN"
>> +	exit 1
>> +fi
>> +
>> +uci set "network.vlan1.ports=$CLIENT_PORTS"
>> +uci set "network.vlan3.ports=$BATMAN_PORTS"
>> +uci commit network
>> +
>> +/etc/init.d/network restart
>> +
>> +echo "Port updated successfully."
>> diff --git a/src/packages/fff/fff-network/files/usr/sbin/setcpev1
>> b/src/packages/fff/fff-network/files/usr/sbin/setcpev1
>> new file mode 100755
>> index 00000000..5ed9a987
>> --- /dev/null
>> +++ b/src/packages/fff/fff-network/files/usr/sbin/setcpev1
>> @@ -0,0 +1,46 @@
>> +#!/bin/sh
>> +
>> +# This sets the port mode on CPE210 v1 and CPE510 v1
>> +
>> +if ! [ "$(uci -q get fff.ui.portsetup)" = "cpev1" ] ; then
>> +	echo "Wrong device. This is for CPE210 v1 or CPE510 v1 only!"
>> +	exit 1
>> +fi
>> +
>> +LAN0MODE=$1
>> +LAN1MODE=$2
>> +
>> +CLIENT_PORTS="0t"
>> +WAN_PORTS="0t"
>> +BATMAN_PORTS="0t"
>> +
>> +if [ "$LAN0MODE" = "WAN" ] ; then
>> +	WAN_PORTS="$WAN_PORTS 5"
>> +elif [ "$LAN0MODE" = "CLIENT" ] ; then
>> +	CLIENT_PORTS="$CLIENT_PORTS 5"
>> +elif [ "$LAN0MODE" = "BATMAN" ] ; then
>> +	BATMAN_PORTS="$BATMAN_PORTS 5"
>> +else
>> +	echo "Wrong port mode for 1st port. Choose one of: WAN, CLIENT,
>> BATMAN"
>> +	exit 1
>> +fi
>> +
>> +if [ "$LAN1MODE" = "WAN" ] ; then
>> +	WAN_PORTS="$WAN_PORTS 4"
>> +elif [ "$LAN1MODE" = "CLIENT" ] ; then
>> +	CLIENT_PORTS="$CLIENT_PORTS 4"
>> +elif [ "$LAN1MODE" = "BATMAN" ] ; then
>> +	BATMAN_PORTS="$BATMAN_PORTS 4"
>> +else
>> +	echo "Wrong port mode for 2nd port. Choose one of: WAN, CLIENT,
>> BATMAN"
>> +	exit 1
>> +fi
>> +
>> +uci set "network.vlan1.ports=$CLIENT_PORTS"
>> +uci set "network.vlan2.ports=$WAN_PORTS"
>> +uci set "network.vlan3.ports=$BATMAN_PORTS"
>> +uci commit network
>> +
>> +/etc/init.d/network restart
>> +
>> +echo "Ports updated successfully."
>> diff --git a/src/packages/fff/fff-network/files/usr/sbin/setoneport
>> b/src/packages/fff/fff-network/files/usr/sbin/setoneport
>> new file mode 100755
>> index 00000000..37387827
>> --- /dev/null
>> +++ b/src/packages/fff/fff-network/files/usr/sbin/setoneport
>> @@ -0,0 +1,24 @@
>> +#!/bin/sh
>> +
>> +# This sets the port mode on one-port devices
>> +
>> +if ! [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] ; then
>> +	echo "Wrong device. This is for one-port devices only!"
>> +	exit 1
>> +fi
>> +
>> +. /lib/functions/fff/networksetup
>> +
>> +ETHMODE=$1
>> +DEV=$2
>> +
>> +[ -n "$DEV" ] || DEV="eth0"
>> +
>> +if [ "$ETHMODE" = "WAN" ] || [ "$ETHMODE" = "CLIENT" ] || [ "$ETHMODE"
>> = "BATMAN" ]; then
>> +	setupOnePort "$DEV" "$ETHMODE"
>> +	/etc/init.d/network restart
>> +	echo "Port updated successfully."
>> +else
>> +	echo "Wrong port mode. Choose one of: WAN, CLIENT, BATMAN"
>> +	exit 1
>> +fi
>> diff --git a/src/packages/fff/fff-support/Makefile b/src/packages/fff/fff-
>> support/Makefile
>> index 56e35740..2fc74b0c 100644
>> --- a/src/packages/fff/fff-support/Makefile
>> +++ b/src/packages/fff/fff-support/Makefile
>> @@ -1,7 +1,7 @@
>>  include $(TOPDIR)/rules.mk
>>
>>  PKG_NAME:=fff-support
>> -PKG_RELEASE:=2
>> +PKG_RELEASE:=3
>>
>>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
>>
>> diff --git a/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff
>> b/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff
>> new file mode 100644
>> index 00000000..30c5ab12
>> --- /dev/null
>> +++ b/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootff
>> +++ f
>> @@ -0,0 +1,13 @@
>> +#!/bin/sh
>> +# Copyright 2019 Adrian Schmutzler
>> +# License GPLv3
>> +
>> +LOCALUPGRADESCRIPT="/etc/firstbootfff"
>> +
>> +#add LOCALUPGRADESCRIPT to sysupgrade
>> +grep -q ^"${LOCALUPGRADESCRIPT}"$ /etc/sysupgrade.conf || echo
>> +"$LOCALUPGRADESCRIPT" >> /etc/sysupgrade.conf
>> +
>> +# process user commands
>> +[ -s "$LOCALCONFIGSCRIPT" ] && {
>> +	sh /etc/firstbootfff
>> +}
>> diff --git a/src/packages/fff/fff-support/files/usr/sbin/show_info
>> b/src/packages/fff/fff-support/files/usr/sbin/show_info
>> index d7ec8247..fb7f7d25 100755
>> --- a/src/packages/fff/fff-support/files/usr/sbin/show_info
>> +++ b/src/packages/fff/fff-support/files/usr/sbin/show_info
>> @@ -3,6 +3,7 @@
>>  . /etc/firmware_release
>>  . /lib/functions/fff/evalhoodinfo
>>  . /lib/functions/fff/evalbytes
>> +. /lib/functions/fff/portorder
>>  . /lib/functions.sh # required for config_load and config_foreach
>>
>>  board_name=$(uci -q get board.model.name) @@ -187,13 +188,9 @@ fi
>> echo "Download-Limit: $(uci -q get 'simple-tc.example.limit_ingress') kBit/s"
>>  echo "Upload-Limit: $(uci -q get 'simple-tc.example.limit_egress') kBit/s"
>>
>> -if grep -q 'PORTORDER=' /etc/network.$board_name ; then
>> -	portorder=$(awk -F= '/PORTORDER=/ { print $2 }'
>> /etc/network.$board_name | sed "s/\"//g")
>> -fi
>> -
>>  echo ""
>>  if swconfig list | grep -q switch0 ; then
>> -	if [ -n "$portorder" ] ; then
>> +	if [ -n "$PORTORDER" ] ; then
>>  		echo "-> SWITCH (tatsaechliche Portreihenfolge)"
>>  	else
>>  		echo "-> SWITCH (interne logische Portreihenfolge)"
>> @@ -218,7 +215,7 @@ if swconfig list | grep -q switch0 ; then
>>  		printf '%-10s%-5s%-13s%s\n' "WAN-Port: " "${link} " "- WAN "
>> "@ $speed"
>>  	fi
>>
>> -	for internalport in $portorder
>> +	for internalport in $PORTORDER
>>  	do
>>  		line=$(swconfig dev switch0 port "$internalport" show | tr -d
>> '\n' | tr -d '\t')
>>  		port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/') @@ -
>> 230,9 +227,7 @@ if swconfig list | grep -q switch0 ; then
>>  	swconfig dev switch0 show | grep "\t*link:" | while read line ; do
>>  		line=$(echo "$line" | tr -d '\n' | tr -d '\t')
>>  		port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')
>> -		if echo "$portorder" | grep -q "$port" ; then
>> -			continue
>> -		fi
>> +		echo "$PORTORDER" | grep -q "$port" && continue
>>  		printf '%-10s' "Port #${port}: "
>>  		format_port "${line}"
>>  	done
>> diff --git a/src/packages/fff/fff-sysupgrade/Makefile b/src/packages/fff/fff-
>> sysupgrade/Makefile
>> index 0e6c08ec..0f2e6a1e 100644
>> --- a/src/packages/fff/fff-sysupgrade/Makefile
>> +++ b/src/packages/fff/fff-sysupgrade/Makefile
>> @@ -1,7 +1,7 @@
>>  include $(TOPDIR)/rules.mk
>>
>>  PKG_NAME:=fff-sysupgrade
>> -PKG_RELEASE:=10
>> +PKG_RELEASE:=11
>>
>>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
>>
>> diff --git a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-
>> sysupgrade b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-
>> sysupgrade
>> index f5783687..07f991e0 100644
>> --- a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-
>> sysupgrade
>> +++ b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysu
>> +++ pgrade
>> @@ -2,7 +2,7 @@
>>  # Copyright 2017 Tim Niemeyer
>>  # License GPLv3
>>
>> -cat > /etc/sysupgrade.conf <<-__EOF__
>> +cat >> /etc/sysupgrade.conf <<-__EOF__
>>  /etc/shadow
>>  /etc/dropbear/dropbear_dss_host_key
>>  /etc/dropbear/dropbear_rsa_host_key
>> diff --git a/src/packages/fff/fff-web/Makefile b/src/packages/fff/fff-
>> web/Makefile
>> index 9bb10f71..819644a5 100644
>> --- a/src/packages/fff/fff-web/Makefile
>> +++ b/src/packages/fff/fff-web/Makefile
>> @@ -1,7 +1,7 @@
>>  include $(TOPDIR)/rules.mk
>>
>>  PKG_NAME:=fff-web
>> -PKG_RELEASE:=7
>> +PKG_RELEASE:=8
>>
>>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
>>
>> diff --git a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
>> b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
>> index 01506fce..f990d4e4 100755
>> --- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
>> +++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
>> @@ -2,22 +2,27 @@
>>
>>  <%
>>  board_name=$(uci -q get board.model.name)
>> +LOCALUPGRADESCRIPT="/etc/firstbootfff"
>> +
>>  # write
>>  if [ "$REQUEST_METHOD" = "POST" ] ; then
>>  	if [ "$POST_change_mode" != "" ] ; then
>> -		sed -i '/^.*# set via WebUI/d' /etc/network.config
>> -		echo "ETHMODE=\"${POST_mode}\" # set via WebUI" >>
>> /etc/network.config
>> -		sed -i '/^FORCEPARSE/d' /etc/network.config
>> -		echo "FORCEPARSE='2'" >> /etc/network.config
>> +		if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ]; then
>> +			setoneport "${POST_mode}"
>> +			sed -i '/^setoneport.*/d' $LOCALUPGRADESCRIPT
>> +			echo "setoneport \"${POST_mode}\" # set via
>> WebUI" >> $LOCALUPGRADESCRIPT
>> +		elif [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ]; then
>> +			set2ndport "${POST_mode}"
>> +			sed -i '/^set2ndport.*/d' $LOCALUPGRADESCRIPT
>> +			echo "set2ndport \"${POST_mode}\" # set via
>> WebUI" >> $LOCALUPGRADESCRIPT
>> +		fi
>>  		do_reboot=1
>>  		MSG='<span class="green">Port Modus ge&auml;ndert!
>> Router startet neu...</span>'
>>  	fi
>>  	if [ "$POST_change_twoport" != "" ] ; then
>> -		sed -i '/^.*# set via WebUI/d' /etc/network.config
>> -		echo "LAN0MODE=\"${POST_mode0}\" # set via WebUI" >>
>> /etc/network.config
>> -		echo "LAN1MODE=\"${POST_mode1}\" # set via WebUI" >>
>> /etc/network.config
>> -		sed -i '/^FORCEPARSE/d' /etc/network.config
>> -		echo "FORCEPARSE='2'" >> /etc/network.config
>> +		setcpev1 "${POST_mode0}" "${POST_mode1}"
>> +		sed -i '/^setcpev1.*/d' $LOCALUPGRADESCRIPT
>> +		echo "setcpev1 \"${POST_mode0}\" \"${POST_mode1}\" #
>> set via WebUI"
>> +>> $LOCALUPGRADESCRIPT
>>  		do_reboot=1
>>  		MSG='<span class="green">Port Modus ge&auml;ndert!
>> Router startet neu...</span>'
>>  	fi
>> @@ -108,11 +113,8 @@ format_port() {
>>  					echo "</td>"
>>  				fi
>>
>> -				if grep -q 'PORTORDER='
>> /etc/network.$board_name ; then
>> -					portorder=$(awk -F= '/PORTORDER=/
>> { print $2 }' /etc/network.$board_name | sed "s/\"//g")
>> -				fi
>> -				for internalport in $portorder
>> -				do
>> +				. /lib/functions/fff/portorder
>> +				for internalport in $PORTORDER ; do
>>  					line=$(swconfig dev switch0 port
>> "$internalport" show | tr -d '\n' | tr -d '\t')
>>  					port=$(echo "$line" | sed 's/.*
>> port:\([^ ]*\) .*/\1/')
>>  					echo "<td class=\"swport\">"
>> @@ -120,16 +122,12 @@ format_port() {
>>  					format_port "${line}"
>>  					echo "</td>"
>>  				done
>> -				if [ -n "$portorder" ] ; then
>> -					echo "<td class=\"swport\"
>> style=\"width:4em\"></td>"
>> -				fi
>> +				[ -n "$PORTORDER" ] && echo "<td
>> class=\"swport\" style=\"width:4em\"></td>"
>>
>>  				swconfig dev switch0 show | grep "\t*link:" |
>> while read line ; do
>>  					line=$(echo "$line" | tr -d '\n' | tr -d
>> '\t')
>>  					port=$(echo "$line" | sed 's/.*
>> port:\([^ ]*\) .*/\1/')
>> -					if echo "$portorder" | grep -q "$port" ;
>> then
>> -						continue
>> -					fi
>> +					echo "$PORTORDER" | grep -q "$port"
>> && continue
>>  					echo "<td class=\"swport\">"
>>  					echo "<span class=\"port\">Port
>> #${port}</span><br />"
>>  					format_port "${line}"
>> @@ -141,7 +139,7 @@ format_port() {
>>  		<table>
>>  			<tr><td></td></tr>
>>  			<tr><td>
>> -				<% if [ -n "$portorder" ] ; then %>
>> +				<% if [ -n "$PORTORDER" ] ; then %>
>>  				Dies zeigt die tats&auml;chliche Zuordnung
>> der Ports, wobei der WAN Port auf der linken Seite liegt. Die Nummerierung
>> entspricht der internen Zuordnung!<br />
>>  				<% else %>
>>  				Die Nummerierung und Reihenfolge der Ports
>> entspricht nicht notwendigerweise der der Netzwerkanschl&uuml;sse am
>> Router!<br /> @@ -152,12 +150,7 @@ format_port() {
>>  	</fieldset>
>>  	</td></tr>
>>  <% fi %>
>> -<% if grep -q "ONE_PORT" "/etc/network.$board_name" || grep -q
>> "ETHPORT" "/etc/network.$board_name" ; then %>
>> -	<%
>> -		# Device has a port set by $ETHMODE
>> -		. /etc/network.mode
>> -		. /etc/network.config
>> -	%>
>> +<% if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] || [ "$(uci -q
>> +get fff.ui.portsetup)" = "2ndport" ] ; then %>
>>  	<tr><td>
>>  	<fieldset>
>>  		<legend>Ethernet Anschluss</legend>
>> @@ -166,10 +159,10 @@ format_port() {
>>  				<th style="width:
>> 1em;">Anschluss&nbsp;Modus:</th>
>>  				<td>
>>  					<select name="mode">
>> -						<option value="BATMAN" <%
>> [ "$ETHMODE" = "BATMAN" ] && echo -n 'selected="selected" '
>> %>>BATMAN</option>
>> -						<option value="CLIENT" <% [
>> "$ETHMODE" = "CLIENT" ] && echo -n 'selected="selected" '
>> %>>CLIENT</option>
>> -						<% if grep -q "ONE_PORT"
>> "/etc/network.$board_name" ; then %>
>> -						<option value="WAN" <% [
>> "$ETHMODE" = "WAN" ] && echo -n 'selected="selected" '
>> %>>WAN</option>
>> +						<option
>> value="BATMAN">BATMAN</option>
>> +						<option
>> value="CLIENT">CLIENT</option>
>> +						<% if [ "$(uci -q get
>> fff.ui.portsetup)" = "oneport" ] ; then %>
>> +						<option
>> value="WAN">WAN</option>
>>  						<% fi %>
>>  					</select>
>>  				</td>
>> @@ -178,7 +171,7 @@ format_port() {
>>  			<tr><td colspan="2"></td></tr>
>>  			<tr><td colspan="2">
>>  				WAN: Knoten stellt &uuml;ber Ethernet
>> Anschluss Verbindung zum Internet her.<br />
>> -				Client: Normale Clients stellen &uuml;ber
>> Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
>> +				CLIENT: Normale Clients stellen &uuml;ber
>> Ethernet Anschluss des
>> +Knotens Verbindung zum Freifunk Netz her.<br />
>>  				BATMAN: Knoten stellt &uuml;ber Ethernet
>> Anschluss Verbindung zu anderen MESH Knoten her.<br /><br />
>>
>>  				Wenn diese Einstellung ver&auml;ndert wird,
>> wird eine evtl. vorhandene manuelle Netzwerkkonfiguration in der @@ -
>> 189,12 +182,7 @@ format_port() {
>>  	</fieldset>
>>  	</td></tr>
>>  <% fi %>
>> -<% if grep -q "LAN0PORT" "/etc/network.$board_name" || grep -q
>> "LAN1PORT" "/etc/network.$board_name" ; then %>
>> -	<%
>> -		# Device has two ports
>> -		. /etc/network.mode
>> -		. /etc/network.config
>> -	%>
>> +<% if [ "$(uci -q get fff.ui.portsetup)" = "cpev1" ] ; then %>
>>  	<tr><td>
>>  	<fieldset>
>>  		<legend>Ethernet Anschl&uuml;sse</legend> @@ -207,16
>> +195,16 @@ format_port() {
>>  			<tr>
>>  				<td>
>>  					<select name="mode0">
>> -						<option value="BATMAN" <%
>> [ "$LAN0MODE" = "BATMAN" ] && echo -n 'selected="selected" '
>> %>>BATMAN</option>
>> -						<option value="CLIENT" <% [
>> "$LAN0MODE" = "CLIENT" ] && echo -n 'selected="selected" '
>> %>>CLIENT</option>
>> -						<option value="WAN" <% [
>> "$LAN0MODE" = "WAN" ] && echo -n 'selected="selected" '
>> %>>WAN</option>
>> +						<option
>> value="BATMAN">BATMAN</option>
>> +						<option
>> value="CLIENT">CLIENT</option>
>> +						<option
>> value="WAN">WAN</option>
>>  					</select>
>>  				</td>
>>  				<td>
>>  					<select name="mode1">
>> -						<option value="BATMAN" <%
>> [ "$LAN1MODE" = "BATMAN" ] && echo -n 'selected="selected" '
>> %>>BATMAN</option>
>> -						<option value="CLIENT" <% [
>> "$LAN1MODE" = "CLIENT" ] && echo -n 'selected="selected" '
>> %>>CLIENT</option>
>> -						<option value="WAN" <% [
>> "$LAN1MODE" = "WAN" ] && echo -n 'selected="selected" '
>> %>>WAN</option>
>> +						<option
>> value="BATMAN">BATMAN</option>
>> +						<option
>> value="CLIENT">CLIENT</option>
>> +						<option
>> value="WAN">WAN</option>
>>  					</select>
>>  				</td>
>>  				<td><input type="submit"
>> name="change_twoport" /></td> @@ -224,7 +212,7 @@ format_port() {
>>  			<tr><td colspan="3"></td></tr>
>>  			<tr><td colspan="3">
>>  				WAN: Knoten stellt &uuml;ber Ethernet
>> Anschluss Verbindung zum Internet her.<br />
>> -				Client: Normale Clients stellen &uuml;ber
>> Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br />
>> +				CLIENT: Normale Clients stellen &uuml;ber
>> Ethernet Anschluss des
>> +Knotens Verbindung zum Freifunk Netz her.<br />
>>  				BATMAN: Knoten stellt &uuml;ber Ethernet
>> Anschluss Verbindung zu anderen MESH Knoten her.<br /><br />
>>
>>  				Wenn diese Einstellung ver&auml;ndert wird,
>> wird eine evtl. vorhandene manuelle Netzwerkkonfiguration in der
>> --
>> 2.11.0
Adrian Schmutzler April 27, 2019, 11:37 p.m.
Hallo Robert,

Tatsächlich habe ich hier auch bereits darüber nachgedacht, ob ich nach so einer Lösung fragen sollte. Cool, dass es so was tatsächlich gibt.

Für mich ist das einzige "Problem" dabei, das ich die Sache etwas intransparent finde: Für den Nutzer, weil sich die gleiche Funktion unterschiedlich verhält und für den Entwickler, weil es kacke zu testen ist.

Da du das mit dem testen aber ja scheinbar hingekriegt hast, werde ich mir das mal genauer ankucken.

Grüße

Adrian

On 27 April 2019 21:13:24 CEST, robert <rlanghammer@web.de> wrote:
>Hi Adrian,
>
>zu dem Problem hab ich eine gute Lösung gefunden. Man kann mit "ubus
>list network" feststellen ob /etc/init.d/network schon gelaufen ist.
>Wenn nicht kommt ein Fehler.
>
>Mann kann also das network restart davon abhängig machen. z.B
>
>ubus list network && /etc/init.d/network restart
>
>War etwas tricky das zu testen bevor das Netz an ist. Wollte schon den
>Lötkolben anwerfen. Einfacher war dann ein init-testskript, das vor
>network läuft.
>
>Grüße
>
>Robert
>
>
>Am 23.04.19 um 10:38 schrieb mail@adrianschmutzler.de:
>> Hallo,
>>
>> hier ist mir noch ein Problem aufgefallen:
>>
>> Um im WebUI gesetzte Ports für One-Port etc. upgradefest zu machen,
>verwende ich die Skripte in /usr/sbin (z.B. setoneport) und schreibe
>diese in die /etc/firstbootfff
>>
>> In diesen Skripten steht jeweils aber ein /etc/init.d/network
>restart, die /etc/firstbootfff wird aber in den uci-defaults
>aufgerufen. Dies würde dann dazu führen, dass das Netzwerk beim
>nächsten Upgrade zu früh gestartet wird.
>>
>> Ich sehe hier drei Lösungen:
>> 1. Man wirft das /etc/init.d/network restart aus den Skripten in
>/usr/sbin raus und überlässt das dem User (ggf. per Echo darauf
>hinweisen). Die Skriptaufrufe können so im WebUI verbleiben.
>>    Diese Lösung wäre effektiv und einfach (und ist daher im Moment
>mein Favorit)
>> 2. Man baut für die betroffenen Skripte nochmal eine kleine Funktion,
>die dann während uci-defaults aufgerufen werden kann. Die Funtionen
>kommen ins /etc/firstbootfff, die Skripte sind nur zum Aufruf während
>Laufzeit gedacht.
>>    (Nachteil: mehrfacher Code, include im /etc/firstbootfff nötig;
>Vorteil: Skriptnutzer in /usr/sbin muss nicht denken)
>> 3. Man benutzt keine Funktionen und schreibt die relevanten paar
>Zeilen direkt in die /etc/firstbootfff (uci set dings, uci set bumms,
>uci commit)
>>    (Nachteil: man muss die bei jeder Änderung wieder irgendwie
>löschen (und dafür irgendwie matchen). D.h. wahrscheinlich alle
>Commands in eine Zeile ....)
>>
>> So richtig geil finde ich nichts davon, wir können es aber nicht so
>lassen wie im Moment in diesem Patch.
>>
>> Grüße
>>
>> Adrian
>>
>>> -----Original Message-----
>>> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On
>Behalf
>>> Of Adrian Schmutzler
>>> Sent: Montag, 22. April 2019 14:35
>>> To: franken-dev@freifunk.net
>>> Subject: [PATCH v3 06/14] fff-network/-support/-web: Nice setup of
>special-
>>> port devices
>>>
>>> This patch:
>>> - provides scripts to easily change port configuration on the
>>>   "special" devices
>>> - provides a file to store upgrade-safe script lines run at
>>>   first boot (to be used for port adjustments)
>>> - fixes the port page in WebUI
>>> - fixes show_info
>>>
>>> With this patch, instead of specifying data in network.config and
>then have a
>>> script to deal with it, we define a script /etc/firstbootfff where
>COMMANDS
>>> can be stored. Thus, one can just make switch ports permanent by
>putting
>>> the uci commands there.
>>>
>>> To keep the convenient setup of one-port (and other special)
>devices, we
>>> implement script, e.g.
>>> setoneport "WAN"
>>> will set the port of a one-port device to WAN mode. Those scripts
>are used in
>>> the WebUI and may also be implemented manually in the
>/etc/firstbootfff
>>> file.
>>>
>>> This patch misses the selection of the current port mode in the
>WebUI. It
>>> would have been too much additional code for this tiny feature.
>>>
>>> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
>>>
>>> ---
>>>
>>> This patch is built to reintroduce as much of the previous
>functionality as
>>> possible. One could however consider removing the CPE and AR150
>special
>>> cases and leave only the real one-ports in the WebUI.
>>>
>>> Changes in v2:
>>> - Removed some -q
>>> - Changed another PORTORDER in show_info
>>> - Renamed "twoport" to "cpev1"
>>> - Add ui.portsetup in 10-setup-fff
>>> - Restart network in scripts, no reboot necessary
>>> - Make 99-fff-sysupgrade append instead of overwrite
>>>
>>> Changes in v3:
>>> - Added variable port in setoneport
>>> - Added uci commit fff at end of 22a-config-ports
>>> - Use new generic names: vlan1 etc.
>>> ---
>>>  .../fff-config/files/etc/uci-defaults/10-setup-fff |  3 +
>>>  .../files/etc/uci-defaults/22a-config-ports        |  5 ++
>>>  .../fff/fff-network/files/usr/sbin/set2ndport      | 30 +++++++++
>>>  .../fff/fff-network/files/usr/sbin/setcpev1        | 46
>+++++++++++++
>>>  .../fff/fff-network/files/usr/sbin/setoneport      | 24 +++++++
>>>  src/packages/fff/fff-support/Makefile              |  2 +-
>>>  .../files/etc/uci-defaults/90-firstbootfff         | 13 ++++
>>>  .../fff/fff-support/files/usr/sbin/show_info       | 13 ++--
>>>  src/packages/fff/fff-sysupgrade/Makefile           |  2 +-
>>>  .../files/etc/uci-defaults/99-fff-sysupgrade       |  2 +-
>>>  src/packages/fff/fff-web/Makefile                  |  2 +-
>>>  .../fff/fff-web/files/www/ssl/cgi-bin/ports.html   | 78
>+++++++++-------------
>>>  12 files changed, 162 insertions(+), 58 deletions(-)  create mode
>100755
>>> src/packages/fff/fff-network/files/usr/sbin/set2ndport
>>>  create mode 100755
>src/packages/fff/fff-network/files/usr/sbin/setcpev1
>>>  create mode 100755
>src/packages/fff/fff-network/files/usr/sbin/setoneport
>>>  create mode 100644
>src/packages/fff/fff-support/files/etc/uci-defaults/90-
>>> firstbootfff
>>>
>>> diff --git
>a/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
>>> b/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
>>> index 3014f50d..a63ff6a9 100644
>>> ---
>a/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
>>> +++
>b/src/packages/fff/fff-config/files/etc/uci-defaults/10-setup-fff
>>> @@ -11,4 +11,7 @@ if ! uci -q get fff.system > /dev/null ; then
>>>  	uci set "fff.system.hostname=FFF"
>>>  fi
>>>
>>> +uci set fff.ui=fff
>>> +uci -q get fff.ui.portsetup > /dev/null || uci set
>"fff.ui.portsetup=default"
>>> +
>>>  uci commit fff
>>> diff --git
>a/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-
>>> ports
>b/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
>>> index b8eaceab..cc7ab277 100644
>>> ---
>a/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
>>> +++
>b/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-por
>>> +++ ts
>>> @@ -21,11 +21,13 @@ case "$BOARD" in
>>>  		# Default: LAN0: WAN, LAN1: CLIENT
>>>  		setupSwitch "eth0" "0t 4" "0t" "0t 5"
>>>  		setupWan "eth0.2"
>>> +		uci set "fff.ui.portsetup=cpev1"
>>>  		;;
>>>  	gl-ar150)
>>>  		# Default: CLIENT
>>>  		setupSwitch "eth1" "0t 1" "0t"
>>>  		setupWan "eth0"
>>> +		uci set "fff.ui.portsetup=2ndport"
>>>  		;;
>>>  	tl-wdr3500-v1|\
>>>  	tl-wr741nd-v2|\
>>> @@ -85,5 +87,8 @@ case "$BOARD" in
>>>  	ubnt-unifiac-lite|\
>>>  	ubnt-unifiac-mesh)
>>>  		setupOnePort "eth0" "CLIENT"
>>> +		uci set "fff.ui.portsetup=oneport"
>>>  		;;
>>>  esac
>>> +
>>> +uci commit fff
>>> diff --git a/src/packages/fff/fff-network/files/usr/sbin/set2ndport
>>> b/src/packages/fff/fff-network/files/usr/sbin/set2ndport
>>> new file mode 100755
>>> index 00000000..84aa5a2c
>>> --- /dev/null
>>> +++ b/src/packages/fff/fff-network/files/usr/sbin/set2ndport
>>> @@ -0,0 +1,30 @@
>>> +#!/bin/sh
>>> +
>>> +# This sets the port mode on second port without switch
>>> +
>>> +if ! [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ] ; then
>>> +	echo "Wrong device. This is for two-port devices without switch
>>> only!"
>>> +	exit 1
>>> +fi
>>> +
>>> +LAN0MODE=$1
>>> +
>>> +CLIENT_PORTS="0t"
>>> +BATMAN_PORTS="0t"
>>> +
>>> +if [ "$LAN0MODE" = "CLIENT" ] ; then
>>> +	CLIENT_PORTS="$CLIENT_PORTS 1"
>>> +elif [ "$LAN0MODE" = "BATMAN" ] ; then
>>> +	BATMAN_PORTS="$BATMAN_PORTS 1"
>>> +else
>>> +	echo "Wrong port mode. Choose one of: CLIENT, BATMAN"
>>> +	exit 1
>>> +fi
>>> +
>>> +uci set "network.vlan1.ports=$CLIENT_PORTS"
>>> +uci set "network.vlan3.ports=$BATMAN_PORTS"
>>> +uci commit network
>>> +
>>> +/etc/init.d/network restart
>>> +
>>> +echo "Port updated successfully."
>>> diff --git a/src/packages/fff/fff-network/files/usr/sbin/setcpev1
>>> b/src/packages/fff/fff-network/files/usr/sbin/setcpev1
>>> new file mode 100755
>>> index 00000000..5ed9a987
>>> --- /dev/null
>>> +++ b/src/packages/fff/fff-network/files/usr/sbin/setcpev1
>>> @@ -0,0 +1,46 @@
>>> +#!/bin/sh
>>> +
>>> +# This sets the port mode on CPE210 v1 and CPE510 v1
>>> +
>>> +if ! [ "$(uci -q get fff.ui.portsetup)" = "cpev1" ] ; then
>>> +	echo "Wrong device. This is for CPE210 v1 or CPE510 v1 only!"
>>> +	exit 1
>>> +fi
>>> +
>>> +LAN0MODE=$1
>>> +LAN1MODE=$2
>>> +
>>> +CLIENT_PORTS="0t"
>>> +WAN_PORTS="0t"
>>> +BATMAN_PORTS="0t"
>>> +
>>> +if [ "$LAN0MODE" = "WAN" ] ; then
>>> +	WAN_PORTS="$WAN_PORTS 5"
>>> +elif [ "$LAN0MODE" = "CLIENT" ] ; then
>>> +	CLIENT_PORTS="$CLIENT_PORTS 5"
>>> +elif [ "$LAN0MODE" = "BATMAN" ] ; then
>>> +	BATMAN_PORTS="$BATMAN_PORTS 5"
>>> +else
>>> +	echo "Wrong port mode for 1st port. Choose one of: WAN, CLIENT,
>>> BATMAN"
>>> +	exit 1
>>> +fi
>>> +
>>> +if [ "$LAN1MODE" = "WAN" ] ; then
>>> +	WAN_PORTS="$WAN_PORTS 4"
>>> +elif [ "$LAN1MODE" = "CLIENT" ] ; then
>>> +	CLIENT_PORTS="$CLIENT_PORTS 4"
>>> +elif [ "$LAN1MODE" = "BATMAN" ] ; then
>>> +	BATMAN_PORTS="$BATMAN_PORTS 4"
>>> +else
>>> +	echo "Wrong port mode for 2nd port. Choose one of: WAN, CLIENT,
>>> BATMAN"
>>> +	exit 1
>>> +fi
>>> +
>>> +uci set "network.vlan1.ports=$CLIENT_PORTS"
>>> +uci set "network.vlan2.ports=$WAN_PORTS"
>>> +uci set "network.vlan3.ports=$BATMAN_PORTS"
>>> +uci commit network
>>> +
>>> +/etc/init.d/network restart
>>> +
>>> +echo "Ports updated successfully."
>>> diff --git a/src/packages/fff/fff-network/files/usr/sbin/setoneport
>>> b/src/packages/fff/fff-network/files/usr/sbin/setoneport
>>> new file mode 100755
>>> index 00000000..37387827
>>> --- /dev/null
>>> +++ b/src/packages/fff/fff-network/files/usr/sbin/setoneport
>>> @@ -0,0 +1,24 @@
>>> +#!/bin/sh
>>> +
>>> +# This sets the port mode on one-port devices
>>> +
>>> +if ! [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] ; then
>>> +	echo "Wrong device. This is for one-port devices only!"
>>> +	exit 1
>>> +fi
>>> +
>>> +. /lib/functions/fff/networksetup
>>> +
>>> +ETHMODE=$1
>>> +DEV=$2
>>> +
>>> +[ -n "$DEV" ] || DEV="eth0"
>>> +
>>> +if [ "$ETHMODE" = "WAN" ] || [ "$ETHMODE" = "CLIENT" ] || [
>"$ETHMODE"
>>> = "BATMAN" ]; then
>>> +	setupOnePort "$DEV" "$ETHMODE"
>>> +	/etc/init.d/network restart
>>> +	echo "Port updated successfully."
>>> +else
>>> +	echo "Wrong port mode. Choose one of: WAN, CLIENT, BATMAN"
>>> +	exit 1
>>> +fi
>>> diff --git a/src/packages/fff/fff-support/Makefile
>b/src/packages/fff/fff-
>>> support/Makefile
>>> index 56e35740..2fc74b0c 100644
>>> --- a/src/packages/fff/fff-support/Makefile
>>> +++ b/src/packages/fff/fff-support/Makefile
>>> @@ -1,7 +1,7 @@
>>>  include $(TOPDIR)/rules.mk
>>>
>>>  PKG_NAME:=fff-support
>>> -PKG_RELEASE:=2
>>> +PKG_RELEASE:=3
>>>
>>>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
>>>
>>> diff --git
>a/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff
>>>
>b/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootfff
>>> new file mode 100644
>>> index 00000000..30c5ab12
>>> --- /dev/null
>>> +++
>b/src/packages/fff/fff-support/files/etc/uci-defaults/90-firstbootff
>>> +++ f
>>> @@ -0,0 +1,13 @@
>>> +#!/bin/sh
>>> +# Copyright 2019 Adrian Schmutzler
>>> +# License GPLv3
>>> +
>>> +LOCALUPGRADESCRIPT="/etc/firstbootfff"
>>> +
>>> +#add LOCALUPGRADESCRIPT to sysupgrade
>>> +grep -q ^"${LOCALUPGRADESCRIPT}"$ /etc/sysupgrade.conf || echo
>>> +"$LOCALUPGRADESCRIPT" >> /etc/sysupgrade.conf
>>> +
>>> +# process user commands
>>> +[ -s "$LOCALCONFIGSCRIPT" ] && {
>>> +	sh /etc/firstbootfff
>>> +}
>>> diff --git a/src/packages/fff/fff-support/files/usr/sbin/show_info
>>> b/src/packages/fff/fff-support/files/usr/sbin/show_info
>>> index d7ec8247..fb7f7d25 100755
>>> --- a/src/packages/fff/fff-support/files/usr/sbin/show_info
>>> +++ b/src/packages/fff/fff-support/files/usr/sbin/show_info
>>> @@ -3,6 +3,7 @@
>>>  . /etc/firmware_release
>>>  . /lib/functions/fff/evalhoodinfo
>>>  . /lib/functions/fff/evalbytes
>>> +. /lib/functions/fff/portorder
>>>  . /lib/functions.sh # required for config_load and config_foreach
>>>
>>>  board_name=$(uci -q get board.model.name) @@ -187,13 +188,9 @@ fi
>>> echo "Download-Limit: $(uci -q get
>'simple-tc.example.limit_ingress') kBit/s"
>>>  echo "Upload-Limit: $(uci -q get 'simple-tc.example.limit_egress')
>kBit/s"
>>>
>>> -if grep -q 'PORTORDER=' /etc/network.$board_name ; then
>>> -	portorder=$(awk -F= '/PORTORDER=/ { print $2 }'
>>> /etc/network.$board_name | sed "s/\"//g")
>>> -fi
>>> -
>>>  echo ""
>>>  if swconfig list | grep -q switch0 ; then
>>> -	if [ -n "$portorder" ] ; then
>>> +	if [ -n "$PORTORDER" ] ; then
>>>  		echo "-> SWITCH (tatsaechliche Portreihenfolge)"
>>>  	else
>>>  		echo "-> SWITCH (interne logische Portreihenfolge)"
>>> @@ -218,7 +215,7 @@ if swconfig list | grep -q switch0 ; then
>>>  		printf '%-10s%-5s%-13s%s\n' "WAN-Port: " "${link} " "- WAN "
>>> "@ $speed"
>>>  	fi
>>>
>>> -	for internalport in $portorder
>>> +	for internalport in $PORTORDER
>>>  	do
>>>  		line=$(swconfig dev switch0 port "$internalport" show | tr -d
>>> '\n' | tr -d '\t')
>>>  		port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/') @@ -
>>> 230,9 +227,7 @@ if swconfig list | grep -q switch0 ; then
>>>  	swconfig dev switch0 show | grep "\t*link:" | while read line ; do
>>>  		line=$(echo "$line" | tr -d '\n' | tr -d '\t')
>>>  		port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')
>>> -		if echo "$portorder" | grep -q "$port" ; then
>>> -			continue
>>> -		fi
>>> +		echo "$PORTORDER" | grep -q "$port" && continue
>>>  		printf '%-10s' "Port #${port}: "
>>>  		format_port "${line}"
>>>  	done
>>> diff --git a/src/packages/fff/fff-sysupgrade/Makefile
>b/src/packages/fff/fff-
>>> sysupgrade/Makefile
>>> index 0e6c08ec..0f2e6a1e 100644
>>> --- a/src/packages/fff/fff-sysupgrade/Makefile
>>> +++ b/src/packages/fff/fff-sysupgrade/Makefile
>>> @@ -1,7 +1,7 @@
>>>  include $(TOPDIR)/rules.mk
>>>
>>>  PKG_NAME:=fff-sysupgrade
>>> -PKG_RELEASE:=10
>>> +PKG_RELEASE:=11
>>>
>>>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
>>>
>>> diff --git
>a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-
>>> sysupgrade
>b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-
>>> sysupgrade
>>> index f5783687..07f991e0 100644
>>> --- a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-
>>> sysupgrade
>>> +++
>b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysu
>>> +++ pgrade
>>> @@ -2,7 +2,7 @@
>>>  # Copyright 2017 Tim Niemeyer
>>>  # License GPLv3
>>>
>>> -cat > /etc/sysupgrade.conf <<-__EOF__
>>> +cat >> /etc/sysupgrade.conf <<-__EOF__
>>>  /etc/shadow
>>>  /etc/dropbear/dropbear_dss_host_key
>>>  /etc/dropbear/dropbear_rsa_host_key
>>> diff --git a/src/packages/fff/fff-web/Makefile
>b/src/packages/fff/fff-
>>> web/Makefile
>>> index 9bb10f71..819644a5 100644
>>> --- a/src/packages/fff/fff-web/Makefile
>>> +++ b/src/packages/fff/fff-web/Makefile
>>> @@ -1,7 +1,7 @@
>>>  include $(TOPDIR)/rules.mk
>>>
>>>  PKG_NAME:=fff-web
>>> -PKG_RELEASE:=7
>>> +PKG_RELEASE:=8
>>>
>>>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
>>>
>>> diff --git
>a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
>>> b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
>>> index 01506fce..f990d4e4 100755
>>> --- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
>>> +++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
>>> @@ -2,22 +2,27 @@
>>>
>>>  <%
>>>  board_name=$(uci -q get board.model.name)
>>> +LOCALUPGRADESCRIPT="/etc/firstbootfff"
>>> +
>>>  # write
>>>  if [ "$REQUEST_METHOD" = "POST" ] ; then
>>>  	if [ "$POST_change_mode" != "" ] ; then
>>> -		sed -i '/^.*# set via WebUI/d' /etc/network.config
>>> -		echo "ETHMODE=\"${POST_mode}\" # set via WebUI" >>
>>> /etc/network.config
>>> -		sed -i '/^FORCEPARSE/d' /etc/network.config
>>> -		echo "FORCEPARSE='2'" >> /etc/network.config
>>> +		if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ]; then
>>> +			setoneport "${POST_mode}"
>>> +			sed -i '/^setoneport.*/d' $LOCALUPGRADESCRIPT
>>> +			echo "setoneport \"${POST_mode}\" # set via
>>> WebUI" >> $LOCALUPGRADESCRIPT
>>> +		elif [ "$(uci -q get fff.ui.portsetup)" = "2ndport" ]; then
>>> +			set2ndport "${POST_mode}"
>>> +			sed -i '/^set2ndport.*/d' $LOCALUPGRADESCRIPT
>>> +			echo "set2ndport \"${POST_mode}\" # set via
>>> WebUI" >> $LOCALUPGRADESCRIPT
>>> +		fi
>>>  		do_reboot=1
>>>  		MSG='<span class="green">Port Modus ge&auml;ndert!
>>> Router startet neu...</span>'
>>>  	fi
>>>  	if [ "$POST_change_twoport" != "" ] ; then
>>> -		sed -i '/^.*# set via WebUI/d' /etc/network.config
>>> -		echo "LAN0MODE=\"${POST_mode0}\" # set via WebUI" >>
>>> /etc/network.config
>>> -		echo "LAN1MODE=\"${POST_mode1}\" # set via WebUI" >>
>>> /etc/network.config
>>> -		sed -i '/^FORCEPARSE/d' /etc/network.config
>>> -		echo "FORCEPARSE='2'" >> /etc/network.config
>>> +		setcpev1 "${POST_mode0}" "${POST_mode1}"
>>> +		sed -i '/^setcpev1.*/d' $LOCALUPGRADESCRIPT
>>> +		echo "setcpev1 \"${POST_mode0}\" \"${POST_mode1}\" #
>>> set via WebUI"
>>> +>> $LOCALUPGRADESCRIPT
>>>  		do_reboot=1
>>>  		MSG='<span class="green">Port Modus ge&auml;ndert!
>>> Router startet neu...</span>'
>>>  	fi
>>> @@ -108,11 +113,8 @@ format_port() {
>>>  					echo "</td>"
>>>  				fi
>>>
>>> -				if grep -q 'PORTORDER='
>>> /etc/network.$board_name ; then
>>> -					portorder=$(awk -F= '/PORTORDER=/
>>> { print $2 }' /etc/network.$board_name | sed "s/\"//g")
>>> -				fi
>>> -				for internalport in $portorder
>>> -				do
>>> +				. /lib/functions/fff/portorder
>>> +				for internalport in $PORTORDER ; do
>>>  					line=$(swconfig dev switch0 port
>>> "$internalport" show | tr -d '\n' | tr -d '\t')
>>>  					port=$(echo "$line" | sed 's/.*
>>> port:\([^ ]*\) .*/\1/')
>>>  					echo "<td class=\"swport\">"
>>> @@ -120,16 +122,12 @@ format_port() {
>>>  					format_port "${line}"
>>>  					echo "</td>"
>>>  				done
>>> -				if [ -n "$portorder" ] ; then
>>> -					echo "<td class=\"swport\"
>>> style=\"width:4em\"></td>"
>>> -				fi
>>> +				[ -n "$PORTORDER" ] && echo "<td
>>> class=\"swport\" style=\"width:4em\"></td>"
>>>
>>>  				swconfig dev switch0 show | grep "\t*link:" |
>>> while read line ; do
>>>  					line=$(echo "$line" | tr -d '\n' | tr -d
>>> '\t')
>>>  					port=$(echo "$line" | sed 's/.*
>>> port:\([^ ]*\) .*/\1/')
>>> -					if echo "$portorder" | grep -q "$port" ;
>>> then
>>> -						continue
>>> -					fi
>>> +					echo "$PORTORDER" | grep -q "$port"
>>> && continue
>>>  					echo "<td class=\"swport\">"
>>>  					echo "<span class=\"port\">Port
>>> #${port}</span><br />"
>>>  					format_port "${line}"
>>> @@ -141,7 +139,7 @@ format_port() {
>>>  		<table>
>>>  			<tr><td></td></tr>
>>>  			<tr><td>
>>> -				<% if [ -n "$portorder" ] ; then %>
>>> +				<% if [ -n "$PORTORDER" ] ; then %>
>>>  				Dies zeigt die tats&auml;chliche Zuordnung
>>> der Ports, wobei der WAN Port auf der linken Seite liegt. Die
>Nummerierung
>>> entspricht der internen Zuordnung!<br />
>>>  				<% else %>
>>>  				Die Nummerierung und Reihenfolge der Ports
>>> entspricht nicht notwendigerweise der der Netzwerkanschl&uuml;sse am
>>> Router!<br /> @@ -152,12 +150,7 @@ format_port() {
>>>  	</fieldset>
>>>  	</td></tr>
>>>  <% fi %>
>>> -<% if grep -q "ONE_PORT" "/etc/network.$board_name" || grep -q
>>> "ETHPORT" "/etc/network.$board_name" ; then %>
>>> -	<%
>>> -		# Device has a port set by $ETHMODE
>>> -		. /etc/network.mode
>>> -		. /etc/network.config
>>> -	%>
>>> +<% if [ "$(uci -q get fff.ui.portsetup)" = "oneport" ] || [ "$(uci
>-q
>>> +get fff.ui.portsetup)" = "2ndport" ] ; then %>
>>>  	<tr><td>
>>>  	<fieldset>
>>>  		<legend>Ethernet Anschluss</legend>
>>> @@ -166,10 +159,10 @@ format_port() {
>>>  				<th style="width:
>>> 1em;">Anschluss&nbsp;Modus:</th>
>>>  				<td>
>>>  					<select name="mode">
>>> -						<option value="BATMAN" <%
>>> [ "$ETHMODE" = "BATMAN" ] && echo -n 'selected="selected" '
>>> %>>BATMAN</option>
>>> -						<option value="CLIENT" <% [
>>> "$ETHMODE" = "CLIENT" ] && echo -n 'selected="selected" '
>>> %>>CLIENT</option>
>>> -						<% if grep -q "ONE_PORT"
>>> "/etc/network.$board_name" ; then %>
>>> -						<option value="WAN" <% [
>>> "$ETHMODE" = "WAN" ] && echo -n 'selected="selected" '
>>> %>>WAN</option>
>>> +						<option
>>> value="BATMAN">BATMAN</option>
>>> +						<option
>>> value="CLIENT">CLIENT</option>
>>> +						<% if [ "$(uci -q get
>>> fff.ui.portsetup)" = "oneport" ] ; then %>
>>> +						<option
>>> value="WAN">WAN</option>
>>>  						<% fi %>
>>>  					</select>
>>>  				</td>
>>> @@ -178,7 +171,7 @@ format_port() {
>>>  			<tr><td colspan="2"></td></tr>
>>>  			<tr><td colspan="2">
>>>  				WAN: Knoten stellt &uuml;ber Ethernet
>>> Anschluss Verbindung zum Internet her.<br />
>>> -				Client: Normale Clients stellen &uuml;ber
>>> Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br
>/>
>>> +				CLIENT: Normale Clients stellen &uuml;ber
>>> Ethernet Anschluss des
>>> +Knotens Verbindung zum Freifunk Netz her.<br />
>>>  				BATMAN: Knoten stellt &uuml;ber Ethernet
>>> Anschluss Verbindung zu anderen MESH Knoten her.<br /><br />
>>>
>>>  				Wenn diese Einstellung ver&auml;ndert wird,
>>> wird eine evtl. vorhandene manuelle Netzwerkkonfiguration in der @@
>-
>>> 189,12 +182,7 @@ format_port() {
>>>  	</fieldset>
>>>  	</td></tr>
>>>  <% fi %>
>>> -<% if grep -q "LAN0PORT" "/etc/network.$board_name" || grep -q
>>> "LAN1PORT" "/etc/network.$board_name" ; then %>
>>> -	<%
>>> -		# Device has two ports
>>> -		. /etc/network.mode
>>> -		. /etc/network.config
>>> -	%>
>>> +<% if [ "$(uci -q get fff.ui.portsetup)" = "cpev1" ] ; then %>
>>>  	<tr><td>
>>>  	<fieldset>
>>>  		<legend>Ethernet Anschl&uuml;sse</legend> @@ -207,16
>>> +195,16 @@ format_port() {
>>>  			<tr>
>>>  				<td>
>>>  					<select name="mode0">
>>> -						<option value="BATMAN" <%
>>> [ "$LAN0MODE" = "BATMAN" ] && echo -n 'selected="selected" '
>>> %>>BATMAN</option>
>>> -						<option value="CLIENT" <% [
>>> "$LAN0MODE" = "CLIENT" ] && echo -n 'selected="selected" '
>>> %>>CLIENT</option>
>>> -						<option value="WAN" <% [
>>> "$LAN0MODE" = "WAN" ] && echo -n 'selected="selected" '
>>> %>>WAN</option>
>>> +						<option
>>> value="BATMAN">BATMAN</option>
>>> +						<option
>>> value="CLIENT">CLIENT</option>
>>> +						<option
>>> value="WAN">WAN</option>
>>>  					</select>
>>>  				</td>
>>>  				<td>
>>>  					<select name="mode1">
>>> -						<option value="BATMAN" <%
>>> [ "$LAN1MODE" = "BATMAN" ] && echo -n 'selected="selected" '
>>> %>>BATMAN</option>
>>> -						<option value="CLIENT" <% [
>>> "$LAN1MODE" = "CLIENT" ] && echo -n 'selected="selected" '
>>> %>>CLIENT</option>
>>> -						<option value="WAN" <% [
>>> "$LAN1MODE" = "WAN" ] && echo -n 'selected="selected" '
>>> %>>WAN</option>
>>> +						<option
>>> value="BATMAN">BATMAN</option>
>>> +						<option
>>> value="CLIENT">CLIENT</option>
>>> +						<option
>>> value="WAN">WAN</option>
>>>  					</select>
>>>  				</td>
>>>  				<td><input type="submit"
>>> name="change_twoport" /></td> @@ -224,7 +212,7 @@ format_port() {
>>>  			<tr><td colspan="3"></td></tr>
>>>  			<tr><td colspan="3">
>>>  				WAN: Knoten stellt &uuml;ber Ethernet
>>> Anschluss Verbindung zum Internet her.<br />
>>> -				Client: Normale Clients stellen &uuml;ber
>>> Ethernet Anschluss des Knotens Verbindung zum Freifunk Netz her.<br
>/>
>>> +				CLIENT: Normale Clients stellen &uuml;ber
>>> Ethernet Anschluss des
>>> +Knotens Verbindung zum Freifunk Netz her.<br />
>>>  				BATMAN: Knoten stellt &uuml;ber Ethernet
>>> Anschluss Verbindung zu anderen MESH Knoten her.<br /><br />
>>>
>>>  				Wenn diese Einstellung ver&auml;ndert wird,
>>> wird eine evtl. vorhandene manuelle Netzwerkkonfiguration in der
>>> --
>>> 2.11.0
Robert Langhammer April 28, 2019, 6:29 a.m.
Hi Adrian,

eigentlich ist es ganz simpel. ubus list zeigt alle registrierten
"namespaces". Und der network namespace wird im init Skript registriert.
Ist also vorher noch nicht da.

Zum testen hab ich ein simples init Skript angelegt:


#!/bin/sh /etc/rc.common

START=18

start() {

ubus list network ; echo "errorlevel $?" >> /tmp/ubustest
ubus list network || echo "network aus" >> /tmp/ubustest
                    
echo >> /tmp/ubustest                          
echo "registrierte namespaces"  >> /tmp/ubustest
ubus list >> /tmp/ubustest                     
                         
}                         

Der user merkt davon nix. Er kommt nur auf die Kiste, wenn das Netzwerk
an ist. Für ihn verhält sich das Skript immer gleich.

Grüße

Robert




Am 28.04.19 um 01:37 schrieb Adrian Schmutzler:
> Hallo Robert,
>
> Tatsächlich habe ich hier auch bereits darüber nachgedacht, ob ich nach so einer Lösung fragen sollte. Cool, dass es so was tatsächlich gibt.
>
> Für mich ist das einzige "Problem" dabei, das ich die Sache etwas intransparent finde: Für den Nutzer, weil sich die gleiche Funktion unterschiedlich verhält und für den Entwickler, weil es kacke zu testen ist.
>
> Da du das mit dem testen aber ja scheinbar hingekriegt hast, werde ich mir das mal genauer ankucken.
>
> Grüße
>
> Adrian
>
> On 27 April 2019 21:13:24 CEST, robert <rlanghammer@web.de> wrote:
>> Hi Adrian,
>>
>> zu dem Problem hab ich eine gute Lösung gefunden. Man kann mit "ubus
>> list network" feststellen ob /etc/init.d/network schon gelaufen ist.
>> Wenn nicht kommt ein Fehler.
>>
>> Mann kann also das network restart davon abhängig machen. z.B
>>
>> ubus list network && /etc/init.d/network restart
>>
>> War etwas tricky das zu testen bevor das Netz an ist. Wollte schon den
>> Lötkolben anwerfen. Einfacher war dann ein init-testskript, das vor
>> network läuft.
>>
>> Grüße
>>
>> Robert
>>
>>
>
Adrian Schmutzler May 14, 2019, 11:12 a.m.
Hallo,

ich habe gerade noch überlegt, ob man nicht aus dem ubus auch das spezifische Gerät rauskriegt, also irgendwie
ubus list network.interface.eth0
oder so machen kann. Da stehen aber wirklich nur die Interfaces, insofern ist es mit deiner einfachen Variante wohl am besten.

Grüße

Adrian

> -----Original Message-----
> From: robert [mailto:rlanghammer@web.de]
> Sent: Sonntag, 28. April 2019 08:29
> To: Adrian Schmutzler <mail@adrianschmutzler.de>; franken-dev <franken-
> dev@freifunk.net>
> Subject: Re: [PATCH v3 06/14] fff-network/-support/-web: Nice setup of
> special-port devices
> 
> Hi Adrian,
> 
> eigentlich ist es ganz simpel. ubus list zeigt alle registrierten
> "namespaces". Und der network namespace wird im init Skript registriert.
> Ist also vorher noch nicht da.
> 
> Zum testen hab ich ein simples init Skript angelegt:
> 
> 
> #!/bin/sh /etc/rc.common
> 
> START=18
> 
> start() {
> 
> ubus list network ; echo "errorlevel $?" >> /tmp/ubustest
> ubus list network || echo "network aus" >> /tmp/ubustest
> 
> echo >> /tmp/ubustest
> echo "registrierte namespaces"  >> /tmp/ubustest
> ubus list >> /tmp/ubustest
> 
> }
> 
> Der user merkt davon nix. Er kommt nur auf die Kiste, wenn das Netzwerk
> an ist. Für ihn verhält sich das Skript immer gleich.
> 
> Grüße
> 
> Robert
> 
> 
> 
> 
> Am 28.04.19 um 01:37 schrieb Adrian Schmutzler:
> > Hallo Robert,
> >
> > Tatsächlich habe ich hier auch bereits darüber nachgedacht, ob ich nach so
> einer Lösung fragen sollte. Cool, dass es so was tatsächlich gibt.
> >
> > Für mich ist das einzige "Problem" dabei, das ich die Sache etwas intransparent
> finde: Für den Nutzer, weil sich die gleiche Funktion unterschiedlich verhält und
> für den Entwickler, weil es kacke zu testen ist.
> >
> > Da du das mit dem testen aber ja scheinbar hingekriegt hast, werde ich mir das
> mal genauer ankucken.
> >
> > Grüße
> >
> > Adrian
> >
> > On 27 April 2019 21:13:24 CEST, robert <rlanghammer@web.de> wrote:
> >> Hi Adrian,
> >>
> >> zu dem Problem hab ich eine gute Lösung gefunden. Man kann mit "ubus
> >> list network" feststellen ob /etc/init.d/network schon gelaufen ist.
> >> Wenn nicht kommt ein Fehler.
> >>
> >> Mann kann also das network restart davon abhängig machen. z.B
> >>
> >> ubus list network && /etc/init.d/network restart
> >>
> >> War etwas tricky das zu testen bevor das Netz an ist. Wollte schon den
> >> Lötkolben anwerfen. Einfacher war dann ein init-testskript, das vor
> >> network läuft.
> >>
> >> Grüße
> >>
> >> Robert
> >>
> >>
> >