forked from freifunk-franken/firmware
Robert Langhammer
4941d6eff5
Signed-off-by: Robert Langhammer <rlanghammer@web.de> Reviewed-by: Adrian Schmutzler <freifunk@adrianschmutzler.de> [Rebased, updated PKG_RELEASE] Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de> Reviewed-by: Fabian Bläse <fabian@blaese.de>
64 lines
1.6 KiB
Bash
Executable File
64 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# Usage: vpn-select <path-to-hood-file>
|
|
|
|
. /usr/share/libubox/jshn.sh
|
|
|
|
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
|
|
}
|
|
|
|
# main
|
|
|
|
# Only do something if file is there and not empty; otherwise exit 1
|
|
if [ -s "$hoodfile" ]; then
|
|
if [ ! -d /tmp/fastd_fff_peers ]; then
|
|
# first run after reboot
|
|
mkdir /tmp/fastd_fff_peers
|
|
make_config
|
|
# start fastd only if there are some peers
|
|
[ "$(ls /etc/fastd/fff/peers/* 2>/dev/null)" ] && /etc/init.d/fastd start
|
|
else
|
|
make_config
|
|
/etc/init.d/fastd reload
|
|
|
|
# fastd start/stop for various situations
|
|
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
|
|
fi
|
|
exit 0
|
|
else
|
|
echo "vpn-select: Hood file not found or empty!"
|
|
exit 1
|
|
fi
|