From patchwork Fri Apr 17 15:54:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [v3] vpn-select: indent contents of make_config function From: Adrian Schmutzler X-Patchwork-Id: 1346 Message-Id: <20200417155449.2984-1-freifunk@adrianschmutzler.de> To: franken-dev@freifunk.net Date: Fri, 17 Apr 2020 17:54:49 +0200 This is a purely cosmetic change to enhance the readability of the function. Also add some empty lines and comments for overview. Signed-off-by: Adrian Schmutzler Reviewed-by: Fabian Bläse --- Changes in v3: - rebase - remove trivial # main comment --- src/packages/fff/fff-vpn-select/Makefile | 2 +- .../fff-vpn-select/files/usr/sbin/vpn-select | 56 ++++++++++--------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/packages/fff/fff-vpn-select/Makefile b/src/packages/fff/fff-vpn-select/Makefile index 267ed447..55825555 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_RELEASE:=4 +PKG_RELEASE:=5 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 b3efc6b8..30883f50 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 @@ -7,34 +7,36 @@ hoodfile="$1" make_config() { -# remove old config -rm /tmp/fastd_fff_peers/* -Index=1 -json_load "$(cat "$hoodfile")" -json_select vpn -# get fastd peers -while json_select "$Index" > /dev/null -do - json_get_var protocol protocol - if [ "$protocol" = "fastd" ]; then - json_get_var servername name - filename="/etc/fastd/fff/peers/$servername" - echo "#name \"${servername}\";" > "$filename" - json_get_var key key - echo "key \"${key}\";" >> "$filename" - json_get_var address address - json_get_var port port - echo "remote \"${address}\" port ${port};" >> "$filename" - echo "" >> "$filename" - echo "float yes;" >> "$filename" - fi - json_select ".." # back to vpn - Index=$(( Index + 1 )) -done -json_select ".." # back to root -} + # remove old config + rm /tmp/fastd_fff_peers/* + + # prepare + Index=1 + json_load "$(cat "$hoodfile")" + json_select vpn -# main + # get fastd peers + while json_select "$Index" > /dev/null + do + json_get_var protocol protocol + if [ "$protocol" = "fastd" ]; then + # set up fastd + json_get_var servername name + filename="/etc/fastd/fff/peers/$servername" + echo "#name \"${servername}\";" > "$filename" + json_get_var key key + echo "key \"${key}\";" >> "$filename" + json_get_var address address + json_get_var port port + echo "remote \"${address}\" port ${port};" >> "$filename" + echo "" >> "$filename" + echo "float yes;" >> "$filename" + fi + json_select ".." # back to vpn + Index=$(( Index + 1 )) + done + json_select ".." # back to root +} # Only do something if file is there and not empty; otherwise exit 1 if [ -s "$hoodfile" ]; then