[OpenWrt-Devel] [PATCH 1/2] wireguard.sh: Batch file writes

Hartmut Knaack knaack.h at gmx.de
Wed Jan 1 06:31:17 EST 2020


Rosen Penev schrieb am 01.01.2020 um 03:08:
> Speeds up config generation.
>
> Signed-off-by: Rosen Penev <rosenp at gmail.com>
> ---
>  .../utils/wireguard-tools/files/wireguard.sh  | 32 ++++++++-----------
>  1 file changed, 14 insertions(+), 18 deletions(-)
>
> diff --git a/package/network/utils/wireguard-tools/files/wireguard.sh b/package/network/utils/wireguard-tools/files/wireguard.sh
> index 4c811c6ba9..1e424e7959 100644
> --- a/package/network/utils/wireguard-tools/files/wireguard.sh
> +++ b/package/network/utils/wireguard-tools/files/wireguard.sh
> @@ -42,13 +42,12 @@ proto_wireguard_setup_peer() {
>  	config_get endpoint_port "${peer_config}" "endpoint_port"
>  	config_get persistent_keepalive "${peer_config}" "persistent_keepalive"
>
> -	echo "[Peer]" >> "${wg_cfg}"
> -	echo "PublicKey=${public_key}" >> "${wg_cfg}"
> -	if [ "${preshared_key}" ]; then
> -		echo "PresharedKey=${preshared_key}" >> "${wg_cfg}"
> -	fi
> +	{
> +	echo "[Peer]"
> +	echo "PublicKey=${public_key}"
> +	[ "${preshared_key}" ] && echo "PresharedKey=${preshared_key}"
>  	for allowed_ip in $allowed_ips; do
> -		echo "AllowedIPs=${allowed_ip}" >> "${wg_cfg}"
> +		echo "AllowedIPs=${allowed_ip}"
>  	done
>  	if [ "${endpoint_host}" ]; then
>  		case "${endpoint_host}" in
> @@ -64,11 +63,10 @@ proto_wireguard_setup_peer() {
>  		else
>  			endpoint="${endpoint}:51820"
>  		fi
> -		echo "Endpoint=${endpoint}" >> "${wg_cfg}"
> -	fi
> -	if [ "${persistent_keepalive}" ]; then
> -		echo "PersistentKeepalive=${persistent_keepalive}" >> "${wg_cfg}"
> +		echo "Endpoint=${endpoint}"
>  	fi
> +	[ "${persistent_keepalive}" ] && echo "PersistentKeepalive=${persistent_keepalive}"
> +	} >> "${wg_cfg}"
>

Hi,
I would prefer to have the above code block indented, as well.

>  	if [ ${route_allowed_ips} -ne 0 ]; then
>  		for allowed_ip in ${allowed_ips}; do
> @@ -119,14 +117,12 @@ proto_wireguard_setup() {
>
>  	umask 077
>  	mkdir -p "${wg_dir}"
> -	echo "[Interface]" > "${wg_cfg}"
> -	echo "PrivateKey=${private_key}" >> "${wg_cfg}"
> -	if [ "${listen_port}" ]; then
> -		echo "ListenPort=${listen_port}" >> "${wg_cfg}"
> -	fi
> -	if [ "${fwmark}" ]; then
> -		echo "FwMark=${fwmark}" >> "${wg_cfg}"
> -	fi
> +	{
> +		echo "[Interface]"
> +		echo "PrivateKey=${private_key}"
> +		[ "${listen_port}" ] && echo "ListenPort=${listen_port}"
> +		[ "${fwmark}" ] && echo "FwMark=${fwmark}"
> +	} > "${wg_cfg}"
>  	config_foreach proto_wireguard_setup_peer "wireguard_${config}"
>
>  	# apply configuration file
>


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list