[v2,2/2] vpn-select: Indent contents of make_config function

Submitted by Adrian Schmutzler on July 29, 2018, 10:36 a.m.

Details

Message ID 20180729103637.28166-2-freifunk@adrianschmutzler.de
State Superseded
Headers show

Commit Message

Adrian Schmutzler July 29, 2018, 10:36 a.m.
This is a purely cosmetic change to enhance the readability
of the function.

Also added some empty lines and comments for overview.

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

---

Introduced in v2.
---
 .../fff/fff-vpn-select/files/usr/sbin/vpn-select   | 91 ++++++++++++----------
 1 file changed, 48 insertions(+), 43 deletions(-)

Patch hide | download patch | download mbox

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 ddd21a1..4a978d8 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,51 +7,56 @@ 
 hoodfile="$1"
 
 make_config() {
-# remove old config
->/etc/config/tunneldigger
-rm /tmp/fastd_fff_peers/*
-count=0
-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 ipv4 \"${address}\" port ${port};" >> "$filename"
-		echo "" >> "$filename"
-		echo "float yes;" >> "$filename"
-		
-		# ask for Broker and select the tunnel
-		if [ "l2tp" = "$(wget -T10 "${address}/vpn.txt" -O - 2>/dev/null)" ]; then
-			# Gateway offers l2tp
-			L2PORT=$((port + 10000))
-			UUID=$hostname
+	# remove old config
+	>/etc/config/tunneldigger
+	rm /tmp/fastd_fff_peers/*
 
-			uci set tunneldigger.$count=broker
-			uci set tunneldigger.$count.address="${address}:$L2PORT"
-			uci set tunneldigger.$count.uuid="$UUID"
-			uci set tunneldigger.$count.interface="l2tp$count"
-			uci set tunneldigger.$count.enabled="1"
-			uci set tunneldigger.$count.hook_script='/etc/tunneldigger/tunneldigger.hook'
-			uci -c /tmp commit tunneldigger
-			count=$((count + 1))
-			# remove this fastd-peer
-			rm "$filename"
+	# prepare
+	count=0
+	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
+			# 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 ipv4 \"${address}\" port ${port};" >> "$filename"
+			echo "" >> "$filename"
+			echo "float yes;" >> "$filename"
+
+			# set up tunneldigger: ask for Broker and select the tunnel
+			if [ "l2tp" = "$(wget -T10 "${address}/vpn.txt" -O - 2>/dev/null)" ]; then
+				# Gateway offers l2tp
+				L2PORT=$((port + 10000))
+				UUID=$hostname
+
+				uci set tunneldigger.$count=broker
+				uci set tunneldigger.$count.address="${address}:$L2PORT"
+				uci set tunneldigger.$count.uuid="$UUID"
+				uci set tunneldigger.$count.interface="l2tp$count"
+				uci set tunneldigger.$count.enabled="1"
+				uci set tunneldigger.$count.hook_script='/etc/tunneldigger/tunneldigger.hook'
+				uci -c /tmp commit tunneldigger
+				count=$((count + 1))
+
+				# remove this fastd-peer (no connection via fastd AND tunneldigger)
+				rm "$filename"
+			fi
 		fi
-	fi
-	json_select ".." # back to vpn
-	Index=$(( Index + 1 ))
-done
-json_select ".." # back to root
+		json_select ".." # back to vpn
+		Index=$(( Index + 1 ))
+	done
+	json_select ".." # back to root
 }
 
 # main

Comments

Robert Langhammer July 30, 2018, 8:35 a.m.
H Adrian,
s. unten


Am 29.07.2018 um 12:36 schrieb Adrian Schmutzler:
> This is a purely cosmetic change to enhance the readability
> of the function.
>
> Also added some empty lines and comments for overview.
>
> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
>
> ---
>
> Introduced in v2.
> ---
>  .../fff/fff-vpn-select/files/usr/sbin/vpn-select   | 91 ++++++++++++----------
>  1 file changed, 48 insertions(+), 43 deletions(-)
>
> 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 ddd21a1..4a978d8 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,51 +7,56 @@
>  hoodfile="$1"
>  
>  make_config() {
> -# remove old config
> ->/etc/config/tunneldigger
> -rm /tmp/fastd_fff_peers/*
> -count=0
> -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 ipv4 \"${address}\" port ${port};" >> "$filename"
> -		echo "" >> "$filename"
> -		echo "float yes;" >> "$filename"
> -		
> -		# ask for Broker and select the tunnel
> -		if [ "l2tp" = "$(wget -T10 "${address}/vpn.txt" -O - 2>/dev/null)" ]; then
> -			# Gateway offers l2tp
> -			L2PORT=$((port + 10000))
> -			UUID=$hostname
> +	# remove old config
> +	>/etc/config/tunneldigger
> +	rm /tmp/fastd_fff_peers/*
>  
> -			uci set tunneldigger.$count=broker
> -			uci set tunneldigger.$count.address="${address}:$L2PORT"
> -			uci set tunneldigger.$count.uuid="$UUID"
> -			uci set tunneldigger.$count.interface="l2tp$count"
> -			uci set tunneldigger.$count.enabled="1"
> -			uci set tunneldigger.$count.hook_script='/etc/tunneldigger/tunneldigger.hook'
> -			uci -c /tmp commit tunneldigger
> -			count=$((count + 1))
> -			# remove this fastd-peer
> -			rm "$filename"
> +	# prepare
> +	count=0
> +	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
> +			# 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 ipv4 \"${address}\" port ${port};" >> "$filename"
> +			echo "" >> "$filename"
> +			echo "float yes;" >> "$filename"
> +
> +			# set up tunneldigger: ask for Broker and select the tunnel
> +			if [ "l2tp" = "$(wget -T10 "${address}/vpn.txt" -O - 2>/dev/null)" ]; then
> +				# Gateway offers l2tp
> +				L2PORT=$((port + 10000))
> +				UUID=$hostname
> +
> +				uci set tunneldigger.$count=broker
> +				uci set tunneldigger.$count.address="${address}:$L2PORT"
> +				uci set tunneldigger.$count.uuid="$UUID"
> +				uci set tunneldigger.$count.interface="l2tp$count"
> +				uci set tunneldigger.$count.enabled="1"
> +				uci set tunneldigger.$count.hook_script='/etc/tunneldigger/tunneldigger.hook'
> +				uci -c /tmp commit tunneldigger
> +				count=$((count + 1))
> +
> +				# remove this fastd-peer (no connection via fastd AND tunneldigger)
Das fastd-peer kommt weg, weil wir l2tp haben.
Die ganze Konstruktion ist ein Überbleibsel von v1. Da hatten wir als
Ausgang nur die fastd-files. Jetzt haben wir das Hoodfile. Ist natürlich
Quatsch erst das fastd-peer anlegen und dann wieder löschen, wenn wir
l2tp haben. Diese fürchterliche Krücke und Abhängigkeit L2PORT=$((port +
10000)) und das wget stammen noch aus der v1 Zeit. Da wollte man nichts
mehr am KeyX erweitern, da der dezentrale KeyX in Aussicht war.
Jetzt können wir alles schön ins Hoodfile packen und der ganze Mist
fliegt raus.
Das ist dann mal eine Aktion nach dem Release.
Darum würde ich sagen, jetzt erst mal nur den "localhoodfile bug" beheben.

Robert
> +				rm "$filename"
> +			fi
>  		fi
> -	fi
> -	json_select ".." # back to vpn
> -	Index=$(( Index + 1 ))
> -done
> -json_select ".." # back to root
> +		json_select ".." # back to vpn
> +		Index=$(( Index + 1 ))
> +	done
> +	json_select ".." # back to root
>  }
>  
>  # main