[v3,1/3] fff-gateway: add package

Submitted by Fabian Blaese on April 23, 2019, 4:09 p.m.

Details

Message ID 20190423160908.28420-1-fabian@blaese.de
State Accepted
Headers show

Commit Message

Fabian Blaese April 23, 2019, 4:09 p.m.
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>
Reviewed-by: Robert Langhammer <rlanghammer@web.de>
---
Changes in v2:
- Remove unnecessary package dependency
- Remove unnecessary shell sources
- Remove wrong sanity check left over from refactoring

Changes in v3:
- rename service reload function
- use grep -q instead of redirection to /dev/null
- use tabs for Makefile indentation
---
 src/packages/fff/fff-gateway/Makefile         |  38 +++++++
 .../files/usr/sbin/configuregateway           | 102 ++++++++++++++++++
 2 files changed, 140 insertions(+)
 create mode 100644 src/packages/fff/fff-gateway/Makefile
 create mode 100755 src/packages/fff/fff-gateway/files/usr/sbin/configuregateway

Patch hide | download patch | download mbox

diff --git a/src/packages/fff/fff-gateway/Makefile b/src/packages/fff/fff-gateway/Makefile
new file mode 100644
index 0000000..7c1dd55
--- /dev/null
+++ b/src/packages/fff/fff-gateway/Makefile
@@ -0,0 +1,38 @@ 
+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
+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..42be02f
--- /dev/null
+++ b/src/packages/fff/fff-gateway/files/usr/sbin/configuregateway
@@ -0,0 +1,102 @@ 
+#!/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!
+
+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 -q "shell function"; then
+				"$1"
+			fi
+		)
+
+		if [ $? -ne 0 ]; then
+			echo "Error when executing" "$1" "from" "$(basename "$script")"
+			exit 1
+		fi
+	done
+}
+
+configure() {
+	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
+}
+
+reload_services() {
+	execute_subshell reload
+	reload_config
+}
+
+apply_changes() {
+	execute_subshell apply
+	reload_services
+	exit 0
+}
+
+revert_changes() {
+	execute_subshell revert
+	exit 0
+}
+
+test_changes() {
+	reload_services
+
+	sleep 5
+	echo "Configuration reloaded. Changes will be reverted in 200s."
+	echo "Kill this script to keep changes."
+	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

Comments

Adrian Schmutzler April 23, 2019, 10 p.m.
Hallo Fabian,

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

mit den unten genannten Änderungen.
Sollte alles beim Applien möglich sein.

> -----Original Message-----
> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf Of
> Fabian Bläse
> Sent: Dienstag, 23. April 2019 18:09
> To: franken-dev@freifunk.net
> Subject: [PATCH v3 1/3] fff-gateway: add package
> 
> 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>
> Reviewed-by: Robert Langhammer <rlanghammer@web.de>
> ---
> Changes in v2:
> - Remove unnecessary package dependency
> - Remove unnecessary shell sources
> - Remove wrong sanity check left over from refactoring
> 
> Changes in v3:
> - rename service reload function
> - use grep -q instead of redirection to /dev/null
> - use tabs for Makefile indentation
> ---
>  src/packages/fff/fff-gateway/Makefile         |  38 +++++++
>  .../files/usr/sbin/configuregateway           | 102 ++++++++++++++++++
>  2 files changed, 140 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..7c1dd55
> --- /dev/null
> +++ b/src/packages/fff/fff-gateway/Makefile
> @@ -0,0 +1,38 @@
> +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
> +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..42be02f
> --- /dev/null
> +++ b/src/packages/fff/fff-gateway/files/usr/sbin/configuregateway
> @@ -0,0 +1,102 @@
> +#!/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!
> +
> +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 -q "shell function"; then
> +				"$1"
> +			fi
> +		)
> +
> +		if [ $? -ne 0 ]; then
> +			echo "Error when executing" "$1" "from" "$(basename
> "$script")"
> +			exit 1
> +		fi
> +	done
> +}
> +
> +configure() {
> +	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

Da fehlt ne Klammer? Oder habe ich die Operator-Reihenfolge falsch im Kopf?

+	if ! ( [ "$response" == "y" ] || [ "$response" == "Y" ] ); then

Selbst dann würde ich eine hinmachen zur Klarheit.

> +		exit 1
> +	fi
> +
> +	execute_subshell configure
> +
> +	exit 0
> +}
> +
> +reload_services() {
> +	execute_subshell reload
> +	reload_config
> +}
> +
> +apply_changes() {
> +	execute_subshell apply
> +	reload_services
> +	exit 0
> +}
> +
> +revert_changes() {
> +	execute_subshell revert
> +	exit 0
> +}
> +
> +test_changes() {
> +	reload_services
> +
> +	sleep 5
> +	echo "Configuration reloaded. Changes will be reverted in 200s."
> +	echo "Kill this script to keep changes."
> +	sleep 200
> +	echo "Reverting changes.."

Falls ich das applye, mache ich hier den Punkt weg.

> +
> +	revert_changes
> +	restart_services

reload_services

> +}
> +
> +
> +usage() {
> +	echo Usage: $0 [OPTION];

Ich bin echt fasziniert, dass das ohne Anführungszeichen geht. Ich würde trotzdem gerne welche rum machen (dann kann das Semikolon weg?).

Grüße

Adrian

> +	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
> --
> 2.21.0
Fabian Blaese April 24, 2019, 8:22 a.m.
Hallo Adrian

On 24.04.19 00:00, Adrian Schmutzler wrote:
>> +
>> +configure() {
>> +	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
> 
> Da fehlt ne Klammer? Oder habe ich die Operator-Reihenfolge falsch im Kopf?
> 
> +	if ! ( [ "$response" == "y" ] || [ "$response" == "Y" ] ); then
> 
> Selbst dann würde ich eine hinmachen zur Klarheit.
Ja. So funktioniert ein "Y" nicht.
Die Klammern stimmen so, wie du geschrieben hast.

>> +	sleep 5
>> +	echo "Configuration reloaded. Changes will be reverted in 200s."
>> +	echo "Kill this script to keep changes."
>> +	sleep 200
>> +	echo "Reverting changes.."
> 
> Falls ich das applye, mache ich hier den Punkt weg.
Von mir aus.

>> +
>> +	revert_changes
>> +	restart_services
> 
> reload_services
Sachen gibts.. Hast hier natürlich auch Recht.

>> +}
>> +
>> +
>> +usage() {
>> +	echo Usage: $0 [OPTION];
> 
> Ich bin echt fasziniert, dass das ohne Anführungszeichen geht. Ich würde trotzdem gerne welche rum machen (dann kann das Semikolon weg?).
Ja, Klammern rum.
Das Semikolon hat damit nichts zu tun, das kann auch so weg, genauso in der nächsten Zeile.

Gruß
Fabian
Fabian Blaese May 7, 2019, 8:57 a.m.
Gibt es hierzu noch Kommentare?
Ansonsten würde ich die von Adrian gewünschten Änderungen beim Applien einbauen.

Gruß
Fabian

On 24.04.19 10:22, Fabian Bläse wrote:
> Hallo Adrian
> 
> On 24.04.19 00:00, Adrian Schmutzler wrote:
>>> +
>>> +configure() {
>>> +	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
>>
>> Da fehlt ne Klammer? Oder habe ich die Operator-Reihenfolge falsch im Kopf?
>>
>> +	if ! ( [ "$response" == "y" ] || [ "$response" == "Y" ] ); then
>>
>> Selbst dann würde ich eine hinmachen zur Klarheit.
> Ja. So funktioniert ein "Y" nicht.
> Die Klammern stimmen so, wie du geschrieben hast.
> 
>>> +	sleep 5
>>> +	echo "Configuration reloaded. Changes will be reverted in 200s."
>>> +	echo "Kill this script to keep changes."
>>> +	sleep 200
>>> +	echo "Reverting changes.."
>>
>> Falls ich das applye, mache ich hier den Punkt weg.
> Von mir aus.
> 
>>> +
>>> +	revert_changes
>>> +	restart_services
>>
>> reload_services
> Sachen gibts.. Hast hier natürlich auch Recht.
> 
>>> +}
>>> +
>>> +
>>> +usage() {
>>> +	echo Usage: $0 [OPTION];
>>
>> Ich bin echt fasziniert, dass das ohne Anführungszeichen geht. Ich würde trotzdem gerne welche rum machen (dann kann das Semikolon weg?).
> Ja, Klammern rum.
> Das Semikolon hat damit nichts zu tun, das kann auch so weg, genauso in der nächsten Zeile.
> 
> Gruß
> Fabian
> 
> 
>
Tim Niemeyer May 8, 2019, 7:20 p.m.
Hi

Reviewed-by: Tim Niemeyer <tim@tn-x.org>

Tim

Am Dienstag, den 23.04.2019, 18:09 +0200 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>
> Reviewed-by: Robert Langhammer <rlanghammer@web.de>
> ---
> Changes in v2:
> - Remove unnecessary package dependency
> - Remove unnecessary shell sources
> - Remove wrong sanity check left over from refactoring
> 
> Changes in v3:
> - rename service reload function
> - use grep -q instead of redirection to /dev/null
> - use tabs for Makefile indentation
> ---
>  src/packages/fff/fff-gateway/Makefile         |  38 +++++++
>  .../files/usr/sbin/configuregateway           | 102
> ++++++++++++++++++
>  2 files changed, 140 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..7c1dd55
> --- /dev/null
> +++ b/src/packages/fff/fff-gateway/Makefile
> @@ -0,0 +1,38 @@
> +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
> +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..42be02f
> --- /dev/null
> +++ b/src/packages/fff/fff-gateway/files/usr/sbin/configuregateway
> @@ -0,0 +1,102 @@
> +#!/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!
> +
> +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 -q "shell function";
> then
> +				"$1"
> +			fi
> +		)
> +
> +		if [ $? -ne 0 ]; then
> +			echo "Error when executing" "$1" "from"
> "$(basename "$script")"
> +			exit 1
> +		fi
> +	done
> +}
> +
> +configure() {
> +	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
> +}
> +
> +reload_services() {
> +	execute_subshell reload
> +	reload_config
> +}
> +
> +apply_changes() {
> +	execute_subshell apply
> +	reload_services
> +	exit 0
> +}
> +
> +revert_changes() {
> +	execute_subshell revert
> +	exit 0
> +}
> +
> +test_changes() {
> +	reload_services
> +
> +	sleep 5
> +	echo "Configuration reloaded. Changes will be reverted in
> 200s."
> +	echo "Kill this script to keep changes."
> +	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
Fabian Blaese May 9, 2019, 9:13 a.m.
Mit den besprochenen Änderungen applied.