From patchwork Thu Jun 18 22:53:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v2,2/2] fff-fastd: throw the outsourced part of vpn-select into From: Robert Langhammer X-Patchwork-Id: 1400 Message-Id: <20200618225324.29501-2-rlanghammer@web.de> To: franken-dev@freifunk.net Date: Fri, 19 Jun 2020 00:53:24 +0200 This is the former configuration and start-stop part from vpn-select for fastd. Signed-off-by: Robert Langhammer --- Changes in v2 * add variable protocol=fastd * add function fastd_clear --- .../fff-fastd/files/etc/vpn-select.d/fastd | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/packages/fff/fff-fastd/files/etc/vpn-select.d/fastd -- 2.20.1 diff --git a/src/packages/fff/fff-fastd/files/etc/vpn-select.d/fastd b/src/packages/fff/fff-fastd/files/etc/vpn-select.d/fastd new file mode 100644 index 0000000..bd73761 --- /dev/null +++ b/src/packages/fff/fff-fastd/files/etc/vpn-select.d/fastd @@ -0,0 +1,35 @@ +protocol=fastd + +fastd_clear() { + rm /tmp/fastd_fff_peers/* +} + +fastd_addpeer() { + [ -d /tmp/fastd_fff_peers ] || mkdir /tmp/fastd_fff_peers + + # write fastd-config + 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" +} + +fastd_start_stop() { + /etc/init.d/fastd reload # does nothing if fastd was not running + + # fastd start/stop for various situations + # this is needed for first start and if fastd comes up or disappears in hoodfile + pidfile="/tmp/run/fastd.fff.pid" + if [ "$(ls /etc/fastd/fff/peers/* 2>/dev/null)" ]; then + ([ -s "$pidfile" ] && [ -d "/proc/$(cat "$pidfile")" ]) || /etc/init.d/fastd start + else + ([ -s "$pidfile" ] && [ -d "/proc/$(cat "$pidfile")" ]) && /etc/init.d/fastd stop + fi +} +