From patchwork Fri Jul 21 13:08:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [RFC, v4, 04/11] Rearrange fff config values into their own config file From: Adrian Schmutzler X-Patchwork-Id: 397 Message-Id: <1500642529-3627-5-git-send-email-freifunk@adrianschmutzler.de> To: franken-dev@freifunk.net Date: Fri, 21 Jul 2017 15:08:42 +0200 Inspired by Tim's suggestions regarding the CPE210 PoE passthrough, this moves the FFF configuration from /etc/config/system to a new file /etc/config/fff. Thus, this file can be copied as a whole during upgrade (with compatibility provided) and then resulting values in other files are re-set later. This also fixes the bandwidth settings not being persistent during upgrade. Other settings may join, like a switch for the PoE passthrough or similar ... I tried to go through all the code and update all occurrences of the relevant system variables (looking for "system" both in GitHub and my local src folder). Tested on an AR150 and CPE210. Signed-off-by: Adrian Schmutzler Tested-by: Adrian Schmutzler --- bsp/default/root_file_system/etc/rc.local | 3 ++ src/packages/fff/fff-nodewatcher/Makefile | 2 +- .../fff/fff-nodewatcher/files/usr/sbin/nodewatcher | 16 +++++----- .../ar71xx/usr/sbin/prepare_firmware_downgrade.sh | 27 ++++++++++++++++ src/packages/fff/fff-sysupgrade/Makefile | 2 +- .../etc/uci-defaults/05-config-system-migration | 37 +++++++++++++--------- .../files/etc/uci-defaults/99-fff-sysupgrade | 2 +- .../fff-sysupgrade/files/usr/sbin/configurefffinit | 32 +++++++++++++++++++ src/packages/fff/fff-vpn-select/Makefile | 2 +- .../fff/fff-vpn-select/files/usr/sbin/vpn-select | 4 +-- src/packages/fff/fff-web/Makefile | 2 +- .../fff-web/files/www/public/cgi-bin/status.html | 12 +++---- .../fff/fff-web/files/www/ssl/cgi-bin/header | 2 +- .../fff-web/files/www/ssl/cgi-bin/settings.html | 37 +++++++++++++--------- 14 files changed, 128 insertions(+), 52 deletions(-) create mode 100755 src/packages/fff/fff-support/ar71xx/usr/sbin/prepare_firmware_downgrade.sh create mode 100755 src/packages/fff/fff-sysupgrade/files/usr/sbin/configurefffinit diff --git a/bsp/default/root_file_system/etc/rc.local b/bsp/default/root_file_system/etc/rc.local index bd972fb..212a5f3 100755 --- a/bsp/default/root_file_system/etc/rc.local +++ b/bsp/default/root_file_system/etc/rc.local @@ -3,6 +3,9 @@ # the system init finished. By default this file does nothing. /usr/sbin/configurenetwork +if [ -s /usr/sbin/configurefffinit ] ; then + /usr/sbin/configurefffinit && mv /usr/sbin/configurefffinit /usr/sbin/configurefff +fi touch /tmp/started diff --git a/src/packages/fff/fff-nodewatcher/Makefile b/src/packages/fff/fff-nodewatcher/Makefile index 73a221e..6bf6cdb 100644 --- a/src/packages/fff/fff-nodewatcher/Makefile +++ b/src/packages/fff/fff-nodewatcher/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=fff-nodewatcher -PKG_VERSION:=41 +PKG_VERSION:=42 PKG_RELEASE:=1 PKG_BUILD_DIR:=$(BUILD_DIR)/fff-nodewatcher diff --git a/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher b/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher index f9d6e65..683379a 100755 --- a/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher +++ b/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher @@ -2,7 +2,7 @@ # Netmon Nodewatcher (C) 2010-2012 Freifunk Oldenburg # License; GPL v3 -SCRIPT_VERSION="41" +SCRIPT_VERSION="42" test -f /tmp/started || exit @@ -56,20 +56,20 @@ crawl() { #Get system data from other locations err "$(date): Collecting basic system status data" hostname="$(cat /proc/sys/kernel/hostname)" - description="$(uci get system.@system[0].description)" + description="$(uci get fff.@system[0].description)" if [ -n "$description" ]; then description="" fi - latitude="$(uci get system.@system[0].latitude)" - longitude="$(uci get system.@system[0].longitude)" + latitude="$(uci get fff.@system[0].latitude)" + longitude="$(uci get fff.@system[0].longitude)" if [ -n "$longitude" -a -n "$latitude" ]; then geo="$latitude$longitude"; fi - position_comment="$(uci get system.@system[0].position_comment)" + position_comment="$(uci get fff.@system[0].position_comment)" if [ -n "$position_comment" ]; then position_comment="" fi - contact="$(uci get system.@system[0].contact)" + contact="$(uci get fff.@system[0].contact)" if [ -n "$contact" ]; then contact="$contact" fi @@ -135,9 +135,9 @@ crawl() { SYSTEM_DATA=$SYSTEM_DATA"${geo}" SYSTEM_DATA=$SYSTEM_DATA"${position_comment}" SYSTEM_DATA=$SYSTEM_DATA"${contact}" - if [ "$(uci -q get "system.@system[0].hood")" ] + if [ "$(uci -q get "fff.@system[0].hood")" ] then - SYSTEM_DATA=$SYSTEM_DATA"$(uci -q get "system.@system[0].hood")" + SYSTEM_DATA=$SYSTEM_DATA"$(uci -q get "fff.@system[0].hood")" fi SYSTEM_DATA=$SYSTEM_DATA"$distname" SYSTEM_DATA=$SYSTEM_DATA"$distversion" diff --git a/src/packages/fff/fff-support/ar71xx/usr/sbin/prepare_firmware_downgrade.sh b/src/packages/fff/fff-support/ar71xx/usr/sbin/prepare_firmware_downgrade.sh new file mode 100755 index 0000000..f8fa0b1 --- /dev/null +++ b/src/packages/fff/fff-support/ar71xx/usr/sbin/prepare_firmware_downgrade.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +if ! grep -q '/etc/config/system' /etc/sysupgrade.conf 2> /dev/null ; then +cat > /etc/sysupgrade.conf <<-__EOF__ +/etc/config/system +__EOF__ +fi + +if [ -s /etc/config/fff ] ; then + + UPGRADE_hostname=$(uci -q get "fff.@system[0].hostname") + UPGRADE_description=$(uci -q get "fff.@system[0].description") + UPGRADE_latitude=$(uci -q get "fff.@system[0].latitude") + UPGRADE_longitude=$(uci -q get "fff.@system[0].longitude") + UPGRADE_position_comment=$(uci -q get "fff.@system[0].position_comment") + UPGRADE_contact=$(uci -q get "fff.@system[0].contact") + + test -n "${UPGRADE_hostname}" && uci -q set "system.@system[0].hostname=${UPGRADE_hostname}" + test -n "${UPGRADE_description}" && uci -q set "system.@system[0].description=${UPGRADE_description}" + test -n "${UPGRADE_latitude}" && uci -q set "system.@system[0].latitude=${UPGRADE_latitude}" + test -n "${UPGRADE_longitude}" && uci -q set "system.@system[0].longitude=${UPGRADE_longitude}" + test -n "${UPGRADE_position_comment}" && uci -q set "system.@system[0].position_comment=${UPGRADE_position_comment}" + test -n "${UPGRADE_contact}" && uci -q set "system.@system[0].contact=${UPGRADE_contact}" + + uci -q commit system + +fi diff --git a/src/packages/fff/fff-sysupgrade/Makefile b/src/packages/fff/fff-sysupgrade/Makefile index 3224662..6bd96f5 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_VERSION:=0.0.4 +PKG_VERSION:=5 PKG_RELEASE:=4 PKG_BUILD_DIR:=$(BUILD_DIR)/fff-sysupgrade diff --git a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/05-config-system-migration b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/05-config-system-migration index 0e36587..8f843f7 100644 --- a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/05-config-system-migration +++ b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/05-config-system-migration @@ -1,21 +1,28 @@ #!/bin/sh -UPGRADE_hostname=$(uci -q get "system.@system[0].hostname") -UPGRADE_description=$(uci -q get "system.@system[0].description") -UPGRADE_latitude=$(uci -q get "system.@system[0].latitude") -UPGRADE_longitude=$(uci -q get "system.@system[0].longitude") -UPGRADE_position_comment=$(uci -q get "system.@system[0].position_comment") -UPGRADE_contact=$(uci -q get "system.@system[0].contact") +if [ ! -s /etc/config/fff ] ; then -/bin/rm -rf /etc/config/system + UPGRADE_hostname=$(uci -q get "system.@system[0].hostname") + UPGRADE_description=$(uci -q get "system.@system[0].description") + UPGRADE_latitude=$(uci -q get "system.@system[0].latitude") + UPGRADE_longitude=$(uci -q get "system.@system[0].longitude") + UPGRADE_position_comment=$(uci -q get "system.@system[0].position_comment") + UPGRADE_contact=$(uci -q get "system.@system[0].contact") -/bin/config_generate + /bin/rm -rf /etc/config/system + + /bin/config_generate -test -n "${UPGRADE_hostname}" && uci -q set "system.@system[0].hostname=${UPGRADE_hostname}" -test -n "${UPGRADE_description}" && uci -q set "system.@system[0].description=${UPGRADE_description}" -test -n "${UPGRADE_latitude}" && uci -q set "system.@system[0].latitude=${UPGRADE_latitude}" -test -n "${UPGRADE_longitude}" && uci -q set "system.@system[0].longitude=${UPGRADE_longitude}" -test -n "${UPGRADE_position_comment}" && uci -q set "system.@system[0].position_comment=${UPGRADE_position_comment}" -test -n "${UPGRADE_contact}" && uci -q set "system.@system[0].contact=${UPGRADE_contact}" + touch /etc/config/fff -uci -q commit system + uci -q add fff system > /dev/null + + test -n "${UPGRADE_hostname}" && uci -q set "fff.@system[0].hostname=${UPGRADE_hostname}" + test -n "${UPGRADE_description}" && uci -q set "fff.@system[0].description=${UPGRADE_description}" + test -n "${UPGRADE_latitude}" && uci -q set "fff.@system[0].latitude=${UPGRADE_latitude}" + test -n "${UPGRADE_longitude}" && uci -q set "fff.@system[0].longitude=${UPGRADE_longitude}" + test -n "${UPGRADE_position_comment}" && uci -q set "fff.@system[0].position_comment=${UPGRADE_position_comment}" + test -n "${UPGRADE_contact}" && uci -q set "fff.@system[0].contact=${UPGRADE_contact}" + + uci -q commit fff +fi 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 61f2d1f..4c5061a 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 @@ -8,5 +8,5 @@ cat > /etc/sysupgrade.conf <<-__EOF__ /etc/dropbear/dropbear_rsa_host_key /etc/dropbear/authorized_keys /etc/network.mode -/etc/config/system +/etc/config/fff __EOF__ diff --git a/src/packages/fff/fff-sysupgrade/files/usr/sbin/configurefffinit b/src/packages/fff/fff-sysupgrade/files/usr/sbin/configurefffinit new file mode 100755 index 0000000..abee2a7 --- /dev/null +++ b/src/packages/fff/fff-sysupgrade/files/usr/sbin/configurefffinit @@ -0,0 +1,32 @@ +#!/bin/sh + +touch /etc/config/fff + +if ! uci -q get fff.@system[0] > /dev/null ; then + uci -q add fff system > /dev/null + uci -q set "fff.@system[0].hostname=Freifunk-Router" +fi + +FFF_hostname=$(uci -q get "fff.@system[0].hostname") +test -n "${FFF_hostname}" && uci -q set "system.@system[0].hostname=${FFF_hostname}" +test -n "${FFF_hostname}" && echo "${FFF_hostname}" > /proc/sys/kernel/hostname + +traffic_enabled=$(uci -q get "fff.@trafficcontrol[0].enabled") +traffic_in=$(uci -q get "fff.@trafficcontrol[0].limit_in") +traffic_out=$(uci -q get "fff.@trafficcontrol[0].limit_out") + +test -n "${traffic_enabled}" && uci -q set "simple-tc.example.enabled=${traffic_enabled}" +wan_interface=$(uci -q get network.wan.ifname) +uci -q set "simple-tc.example.ifname=${wan_interface}" +uci -q set "simple-tc.example.limit_ingress=${traffic_in}" +uci -q set "simple-tc.example.limit_egress=${traffic_out}" + +uci -q commit + +if [ "$traffic_enabled" -eq 1 ] ; then + test -n "$traffic_in" || traffic_in=- + test -n "$traffic_out" || traffic_out=- + simple-tc "${wan_interface}" "${traffic_in}" "${traffic_out}" 2> /dev/null +fi + +exit 0 diff --git a/src/packages/fff/fff-vpn-select/Makefile b/src/packages/fff/fff-vpn-select/Makefile index 9d3c13c..4b11257 100644 --- a/src/packages/fff/fff-vpn-select/Makefile +++ b/src/packages/fff/fff-vpn-select/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=fff-vpn-select -PKG_VERSION:=1 +PKG_VERSION:=2 PKG_RELEASE:=1 PKG_BUILD_DIR:=$(BUILD_DIR)/fff-vpn-select diff --git a/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select b/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select index c3d003f..12bb798 100755 --- a/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select +++ b/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select @@ -51,8 +51,8 @@ if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null || . /etc/community.cfg project="$VPN_PROJECT" mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }' /sys/class/net/br-mesh/address 2>/dev/null) - lat=$(uci get system.@system[0].latitude) - long=$(uci get system.@system[0].longitude) + lat=$(uci get fff.@system[0].latitude) + long=$(uci get fff.@system[0].longitude) hostname=$(cat /proc/sys/kernel/hostname) [ "$hostname" = "OpenWrt" ] && hostname="" [ "$hostname" = "" ] && hostname="$mac" diff --git a/src/packages/fff/fff-web/Makefile b/src/packages/fff/fff-web/Makefile index 723d9a9..906bf49 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_VERSION:=0.0.4 +PKG_VERSION:=5 PKG_RELEASE:=2 PKG_BUILD_DIR:=$(BUILD_DIR)/fff-web diff --git a/src/packages/fff/fff-web/files/www/public/cgi-bin/status.html b/src/packages/fff/fff-web/files/www/public/cgi-bin/status.html index ae58260..dcecc99 100755 --- a/src/packages/fff/fff-web/files/www/public/cgi-bin/status.html +++ b/src/packages/fff/fff-web/files/www/public/cgi-bin/status.html @@ -2,12 +2,12 @@ <% echo -en "Content-Type: text/html\r\n\r\n" -HOSTNAME=$(uci -q get 'system.@system[0].hostname') +HOSTNAME=$(uci -q get 'fff.@system[0].hostname') MAC="$(uci -q get network.mesh.macaddr)" -lat="$(uci -q get system.@system[0].latitude)" -lon="$(uci -q get system.@system[0].longitude)" -contact="$(uci -q get system.@system[0].contact)" +lat="$(uci -q get fff.@system[0].latitude)" +lon="$(uci -q get fff.@system[0].longitude)" +contact="$(uci -q get fff.@system[0].contact)" . /etc/firmware_release @@ -47,11 +47,11 @@ contact="$(uci -q get system.@system[0].contact)" MAC-Adresse:<%= $MAC %> Modell:<% cat /tmp/sysinfo/model 2>/dev/null %> Firmware:<%= ${FIRMWARE_VERSION} %> - Beschreibung:<% uci -q get 'system.@system[0].description' %> + Beschreibung:<% uci -q get 'fff.@system[0].description' %> Position:<% if [ -n "$lat" -a -n "$lon" ]; then echo "${lat:0:8}N, ${lon:0:8}E" fi %> - Standort:<% uci -q get 'system.@system[0].position_comment' %> + Standort:<% uci -q get 'fff.@system[0].position_comment' %> E-Mail Adresse:<%= $contact %> diff --git a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/header b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/header index 8df0ed0..dffca6d 100755 --- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/header +++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/header @@ -12,7 +12,7 @@ nav_entry() { echo -ne "\t$2\n\t\t" } -HOSTNAME=$(uci -q get 'system.@system[0].hostname') +HOSTNAME=$(uci -q get 'fff.@system[0].hostname') NOW=$(date +%s) #Check if new Firmware check older then 1 day diff --git a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/settings.html b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/settings.html index 7488af6..a3fbcd5 100755 --- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/settings.html +++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/settings.html @@ -13,21 +13,28 @@ if [ "$REQUEST_METHOD" == "POST" ] ; then MSG='Knotenname enthält ungültige Zeichen!' else # Allgemeine Einstellungen + uci -q set "fff.@system[0].hostname=${POST_hostname}" + echo $(uci -q get "fff.@system[0].hostname") > /proc/sys/kernel/hostname uci -q set "system.@system[0].hostname=${POST_hostname}" - echo $(uci -q get "system.@system[0].hostname") > /proc/sys/kernel/hostname - uci -q set "system.@system[0].description=${POST_description}" - uci -q set "system.@system[0].latitude=${POST_latitude}" - uci -q set "system.@system[0].longitude=${POST_longitude}" - uci -q set "system.@system[0].position_comment=${POST_position_comment}" - uci -q set "system.@system[0].contact=${POST_contact}" + uci -q set "fff.@system[0].description=${POST_description}" + uci -q set "fff.@system[0].latitude=${POST_latitude}" + uci -q set "fff.@system[0].longitude=${POST_longitude}" + uci -q set "fff.@system[0].position_comment=${POST_position_comment}" + uci -q set "fff.@system[0].contact=${POST_contact}" # Bitratenbegrenzung + uci -q get "fff.@trafficcontrol[0]" > /dev/null || uci -q add fff trafficcontrol > /dev/null if [ "$POST_traffic_limit" == "on" ] ; then - uci -q set "simple-tc.example.ifname=$(uci -q get network.wan.ifname)" + uci -q set "fff.@trafficcontrol[0].enabled=1" uci -q set "simple-tc.example.enabled=1" else + uci -q set "fff.@trafficcontrol[0].enabled=0" uci -q set "simple-tc.example.enabled=0" fi + uci -q set "fff.@trafficcontrol[0].limit_in=${POST_limit_ingress}" + uci -q set "fff.@trafficcontrol[0].limit_out=${POST_limit_egress}" + + uci -q set "simple-tc.example.ifname=$(uci -q get network.wan.ifname)" uci -q set "simple-tc.example.limit_ingress=${POST_limit_ingress}" uci -q set "simple-tc.example.limit_egress=${POST_limit_egress}" @@ -43,7 +50,7 @@ fi <%in /www/ssl/cgi-bin/helpers %> <% # read -if [ "$(uci -q get 'simple-tc.example.enabled')" == "1" ] ; then +if [ "$(uci -q get 'fff.@trafficcontrol[0].enabled')" == "1" ] ; then traffic_checked="checked" else traffic_checked="" @@ -57,16 +64,16 @@ fi Allgemeine Einstellungen - + - + - - - + + +
Knotenname:
Knotenbeschreibung:
Knotenbeschreibung:
GPS Breitengrad:
GPS Längengrad:
Standortbeschreibung:
E-Mail Adresse:
GPS Längengrad:
Standortbeschreibung:
E-Mail Adresse:
@@ -76,8 +83,8 @@ fi Aktiviert: > - Freifunk Download:kbit/s - Freifunk Upload:kbit/s + Freifunk Download:kbit/s + Freifunk Upload:kbit/s