From patchwork Wed Aug 1 18:43:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [v2,1/2] vpn-select: Demand hood file to be provided as argument From: Adrian Schmutzler X-Patchwork-Id: 903 Message-Id: <005101d429c7$8f788ce0$ae69a6a0$@adrianschmutzler.de> To: "'robert'" , Date: Wed, 1 Aug 2018 20:43:37 +0200 Danke. Ich würde anstreben, dass das in ein stable-Release noch mit reinkommt. Grüße Adrian From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf Of robert Sent: Mittwoch, 1. August 2018 19:59 To: franken-dev@freifunk.net Subject: Re: [PATCH v2 1/2] vpn-select: Demand hood file to be provided as argument Hallo Adrian, Reviewed-by: Robert Langhammer Am 29.07.2018 um 12:36 schrieb Adrian Schmutzler: By removing the reference to the hood file from vpn-select, we remove the entire dependency from fff-hoodutils. vpn-select will now work with any file provided, as long as it has the correct syntax. At the moment, the only provider is the configurehood script. Since the various hood file variants are handled there, it seems logical that configurehood also chooses and provides the correct hood file for vpn-select, instead of vpn-select which had no other contact with hood file choice. This is simple, tidy and effective. Adjusted some comments. Fixes #106 Signed-off-by: Adrian Schmutzler --- Changes in v2: - Added usage comment - Added exit 0 - Added error and exit 1 for missing file - Removed sh call in configurehood Since multiple things changed, I did NOT copy the reviews. Please redo! I raised the version for fff-vpn-select by 2, since it still was on 1. The never existant version 2 would have been the initial KeyXchangeV2 version. --- src/packages/fff/fff-hoods/Makefile | 2 +- src/packages/fff/fff-hoods/files/usr/sbin/configurehood | 4 ++-- src/packages/fff/fff-vpn-select/Makefile | 2 +- src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select | 15 +++++++++++---- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-hoods/Makefile index b565ac7..93fd430 100644 --- a/src/packages/fff/fff-hoods/Makefile +++ b/src/packages/fff/fff-hoods/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=fff-hoods -PKG_VERSION:=2 +PKG_VERSION:=3 PKG_RELEASE:=1 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood index 57c6f9f..47e228b 100755 --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood @@ -195,9 +195,9 @@ if [ -s "$hoodfiletmp" ]; then # and now we get to vpn-select script and load VPNs directly from /tmp/keyxchangev2data if hasInternet ; then - sh /usr/sbin/vpn-select + /usr/sbin/vpn-select "$hoodfiletmp" else - sh /usr/sbin/vpn-stop + /usr/sbin/vpn-stop fi # now we load the prefix from the hoodfile and set this to br-mesh diff --git a/src/packages/fff/fff-vpn-select/Makefile b/src/packages/fff/fff-vpn-select/Makefile index 4e2d89b..27cff09 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:=3 PKG_RELEASE:=1 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) 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 7c9bced..ddd21a1 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 @@ -1,15 +1,18 @@ #!/bin/sh -. /lib/functions/fff/keyxchange +# Usage: vpn-select + . /usr/share/libubox/jshn.sh +hoodfile="$1" + make_config() { # remove old config >/etc/config/tunneldigger rm /tmp/fastd_fff_peers/* count=0 Index=1 -json_load "$(cat "$hoodfiletmp")" +json_load "$(cat "$hoodfile")" json_select vpn # get fastd peers while json_select "$Index" > /dev/null @@ -53,8 +56,8 @@ json_select ".." # back to root # main -# Only do something when file is here and greater 0 byte -if [ -s "$hoodfiletmp" ]; then +# Only do something if file is there and not empty; otherwise exit 1 +if [ -s "$hoodfile" ]; then # set some vars hostname=$(cat /proc/sys/kernel/hostname) mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }' /sys/class/net/br-mesh/address 2>/dev/null) @@ -84,4 +87,8 @@ if [ -s "$hoodfiletmp" ]; then ([ -s "$pidfile" ] && [ -d "/proc/$(cat "$pidfile")" ]) && /etc/init.d/fastd stop fi fi + exit 0 +else + echo "vpn-select: Hood file not found or empty!" + exit 1 fi