Message ID | 20190315202213.17577-1-fabian@blaese.de |
---|---|
State | Superseded |
Headers | show |
diff --git a/src/packages/fff/fff-gateway/Makefile b/src/packages/fff/fff-gateway/Makefile new file mode 100644 index 0000000..f310894 --- /dev/null +++ b/src/packages/fff/fff-gateway/Makefile @@ -0,0 +1,39 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=fff-gateway +PKG_VERSION:=1 +PKG_RELEASE:=1 + +PKG_BUILD_DIR:=$(BUILD_DIR)/fff-gateway + +include $(INCLUDE_DIR)/package.mk + +define Package/fff-gateway + SECTION:=base + CATEGORY:=Freifunk + TITLE:= Freifunk-Franken gateway configuration + URL:=https://www.freifunk-franken.de + DEPENDS:=+fff-network +endef + +define Package/fff-gateway/description + This package configures the gateway +endef + +define Build/Prepare + echo "all: " > $(PKG_BUILD_DIR)/Makefile +endef + +define Build/Configure + # nothing +endef + +define Build/Compile + # nothing +endef + +define Package/fff-gateway/install + $(CP) ./files/* $(1)/ +endef + +$(eval $(call BuildPackage,fff-gateway)) diff --git a/src/packages/fff/fff-gateway/files/usr/sbin/configuregateway b/src/packages/fff/fff-gateway/files/usr/sbin/configuregateway new file mode 100755 index 0000000..1c81398 --- /dev/null +++ b/src/packages/fff/fff-gateway/files/usr/sbin/configuregateway @@ -0,0 +1,122 @@ +#!/bin/sh +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + + +# IMPORTANT!! +# DO NOT RUN THIS IN CRONJOB! + +BOARD="$(uci get board.model.name)" +. /etc/network.$BOARD + +#load uci functions +. /lib/functions.sh +. /usr/share/libubox/jshn.sh + +#load fff functions +. /lib/functions/fff/wireless +. /lib/functions/fff/network +. /lib/functions/fff/keyxchange + + +execute_subshell() { + if [ $# -ne 1 ]; then + echo "Usage:" "$0" "<function>" + fi + + for script in /etc/gateway.d/*; do + ( + # unset function to prevent executing parents shell function + unset -f "$1" + . "$script" + + if type "$1" | grep "shell function" > /dev/null; then + "$1" + fi + ) + + if [ $? -ne 0 ]; then + echo "Error when executing" "$1" "from" "$(basename "$script")" + exit 1 + fi + done +} + +configure() { + # ensure client config exists + if ! uci get gateway.@client[0] > /dev/null; then + echo "ERROR: No client config or error parsing config!" + exit 1 + fi + + + echo "This script might remove existing vlans, interfaces, addresses, etc." + read -r -p "Do you really want to continue? (y/n) " response + if ! [ "$response" == "y" ] || [ "$response" == "Y" ]; then + exit 1 + fi + + + execute_subshell configure + + exit 0 +} + +restart_services() { + execute_subshell reload + reload_config +} + +apply_changes() { + execute_subshell apply + restart_services + exit 0 +} + +revert_changes() { + execute_subshell revert + exit 0 +} + +test_changes() { + restart_services + + sleep 5 + echo "services restarted. waiting up to 200s for SIGINT.." + sleep 200 + echo "reverting changes.." + + revert_changes + restart_services +} + + +usage() { + echo Usage: $0 [OPTION]; + echo; + echo "Options:" + echo " -c: configure. No commit, no restart!" + echo " -t: test changes. Restarts services, waits up to 200s for SIGINT" + echo " -a: apply changes" + echo " -r: revert changes" +} + + +if [ $# != 1 ]; then + usage; exit 1 +fi + +case "$1" in + -c) configure ;; + -t) test_changes ;; + -a) apply_changes ;; + -r) revert_changes ;; + *) usage; exit 1 ;; +esac
Moin Am Freitag, den 15.03.2019, 21:22 +0100 schrieb Fabian Bläse: > This introduces a new script for simple gateway configuration. > > The main configuregateway script is able to execute functions > for various steps like 'configure' or 'apply' from scripts in /etc/gateway.d. > > This makes it easy to distribute configuration to the appropriate packages. > > > Signed-off-by: Fabian Bläse <fabian@blaese.de> > --- > src/packages/fff/fff-gateway/Makefile | 39 ++++++ > .../files/usr/sbin/configuregateway | 122 ++++++++++++++++++ > 2 files changed, 161 insertions(+) > create mode 100644 src/packages/fff/fff-gateway/Makefile > create mode 100755 src/packages/fff/fff-gateway/files/usr/sbin/configuregateway > > diff --git a/src/packages/fff/fff-gateway/Makefile b/src/packages/fff/fff-gateway/Makefile > new file mode 100644 > index 0000000..f310894 > --- /dev/null > +++ b/src/packages/fff/fff-gateway/Makefile > @@ -0,0 +1,39 @@ > +include $(TOPDIR)/rules.mk > + > +PKG_NAME:=fff-gateway > +PKG_VERSION:=1 > +PKG_RELEASE:=1 > + > +PKG_BUILD_DIR:=$(BUILD_DIR)/fff-gateway > + > +include $(INCLUDE_DIR)/package.mk > + > +define Package/fff-gateway > + SECTION:=base > + CATEGORY:=Freifunk > + TITLE:= Freifunk-Franken gateway configuration > + URL:=https://www.freifunk-franken.de > + DEPENDS:=+fff-network Wieso depended das darauf? > +endef > + > +define Package/fff-gateway/description > + This package configures the gateway > +endef > + > +define Build/Prepare > > + echo "all: " > $(PKG_BUILD_DIR)/Makefile > +endef > + > +define Build/Configure > > + # nothing > +endef > + > +define Build/Compile > > + # nothing > +endef > + > +define Package/fff-gateway/install > > + $(CP) ./files/* $(1)/ > +endef > + > +$(eval $(call BuildPackage,fff-gateway)) > diff --git a/src/packages/fff/fff-gateway/files/usr/sbin/configuregateway b/src/packages/fff/fff-gateway/files/usr/sbin/configuregateway > new file mode 100755 > index 0000000..1c81398 > --- /dev/null > +++ b/src/packages/fff/fff-gateway/files/usr/sbin/configuregateway > @@ -0,0 +1,122 @@ > +#!/bin/sh > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > + > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > + > + > +# IMPORTANT!! > +# DO NOT RUN THIS IN CRONJOB! > + > +BOARD="$(uci get board.model.name)" > +. /etc/network.$BOARD > + > +#load uci functions > +. /lib/functions.sh > +. /usr/share/libubox/jshn.sh Wird das hier verwendet? > + > +#load fff functions > +. /lib/functions/fff/wireless Wofür? > +. /lib/functions/fff/network Wofür? > +. /lib/functions/fff/keyxchange Wofür? > + > + > +execute_subshell() { > > + if [ $# -ne 1 ]; then > > + echo "Usage:" "$0" "<function>" > > + fi > + > > + for script in /etc/gateway.d/*; do > > + ( > > + # unset function to prevent executing parents shell function > > + unset -f "$1" > > + . "$script" > + > > + if type "$1" | grep "shell function" > /dev/null; then > > + "$1" > > + fi > > + ) > + > > + if [ $? -ne 0 ]; then > > + echo "Error when executing" "$1" "from" "$(basename "$script")" > > + exit 1 > > + fi > > + done > +} > + > +configure() { > > + # ensure client config exists > > > + if ! uci get gateway.@client[0] > /dev/null; then > > + echo "ERROR: No client config or error parsing config!" > > + exit 1 > + fi Warum wird bei configure geprüft ob es dieses client config gibt und bei allen andere nicht? Tim > + > + > > + echo "This script might remove existing vlans, interfaces, addresses, etc." > > + read -r -p "Do you really want to continue? (y/n) " response > > + if ! [ "$response" == "y" ] || [ "$response" == "Y" ]; then > > + exit 1 > > + fi > + > + > > + execute_subshell configure > + > > + exit 0 > +} > + > +restart_services() { > > + execute_subshell reload > > + reload_config > +} > + > +apply_changes() { > > + execute_subshell apply > > + restart_services > > + exit 0 > +} > + > +revert_changes() { > > + execute_subshell revert > > + exit 0 > +} > + > +test_changes() { > > + restart_services > + > > + sleep 5 > > + echo "services restarted. waiting up to 200s for SIGINT.." > > + sleep 200 > > + echo "reverting changes.." > + > > + revert_changes > > + restart_services > +} > + > + > +usage() { > > + echo Usage: $0 [OPTION]; > > + echo; > > + echo "Options:" > > > + echo " -c: configure. No commit, no restart!" > > > + echo " -t: test changes. Restarts services, waits up to 200s for SIGINT" > > > + echo " -a: apply changes" > > > + echo " -r: revert changes" > +} > + > + > +if [ $# != 1 ]; then > > + usage; exit 1 > +fi > + > +case "$1" in > > + -c) configure ;; > > + -t) test_changes ;; > > + -a) apply_changes ;; > > + -r) revert_changes ;; > > + *) usage; exit 1 ;; > +esac
Hey, On 15.03.19 21:42, Tim Niemeyer wrote: > Moin > > Am Freitag, den 15.03.2019, 21:22 +0100 schrieb Fabian Bläse: >> +define Package/fff-gateway >> + SECTION:=base >> + CATEGORY:=Freifunk >> + TITLE:= Freifunk-Franken gateway configuration >> + URL:=https://www.freifunk-franken.de >> + DEPENDS:=+fff-network > Wieso depended das darauf? Das ist so, weil in dieses Package noch ein Script für die Netzwerkkonfiguration dazu kommt, welches die gerätespezifischen Konfigurationen und Funktionen aus dem fff-network Package verwendet. Aktuell ist es auch generell so, dass bei ersten Boot zunächst die klassischen fff-network Skripte ausgeführt werden, woraufhin der User dann die gateway-Skripte verwenden kann. Vielleicht wäre es besser, für die Geräte eine default gateway-config abzulegen und beim ersten Boot danach zu konfigurieren. Dann würde man das fff-network los werden. >> +#load uci functions >> +. /lib/functions.sh >> +. /usr/share/libubox/jshn.sh > Wird das hier verwendet? Stimmt, das gehört hier nicht hin. Gilt auch für die anderen von dir entdeckten sources. >> +configure() { >>> + # ensure client config exists >>>> + if ! uci get gateway.@client[0] > /dev/null; then >>> + echo "ERROR: No client config or error parsing config!" >>> + exit 1 >> + fi > > Warum wird bei configure geprüft ob es dieses client config gibt und > bei allen andere nicht? Auch das ist wohl ein Überrest. Was bei so einem grundlegenden Umbau alles kaputt geht.. O.o Hier sollte man wohl einfach - wenn überhaupt - nur überprüfen, ob eine Gateway Konfiguration existiert. Gruß Fabian
This introduces a new script for simple gateway configuration. The main configuregateway script is able to execute functions for various steps like 'configure' or 'apply' from scripts in /etc/gateway.d. This makes it easy to distribute configuration to the appropriate packages. Signed-off-by: Fabian Bläse <fabian@blaese.de> --- src/packages/fff/fff-gateway/Makefile | 39 ++++++ .../files/usr/sbin/configuregateway | 122 ++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 src/packages/fff/fff-gateway/Makefile create mode 100755 src/packages/fff/fff-gateway/files/usr/sbin/configuregateway