2016-07-05 23:25:46 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2018-07-29 12:36:36 +02:00
|
|
|
# Usage: vpn-select <path-to-hood-file>
|
2020-10-19 23:29:05 +02:00
|
|
|
# To add a new protocol, put a file with three functions to /usr/lib/vpn-select.d/ .
|
|
|
|
# The file must start with protocol=name. It is most important to use the same name here and in hoodfile.
|
|
|
|
# The old config can be cleared in function ${protocol}_clear(). It is called first once per installed protocol.
|
|
|
|
# The function ${protocol}_addpeer() is called for every selected peer in hoodfile.
|
|
|
|
# The function ${protocol}_start_stop() is called at the end once per installed protocol.
|
2018-07-29 12:36:36 +02:00
|
|
|
|
2017-10-05 15:37:45 +02:00
|
|
|
. /usr/share/libubox/jshn.sh
|
|
|
|
|
2018-07-29 12:36:36 +02:00
|
|
|
hoodfile="$1"
|
|
|
|
|
2020-10-19 23:29:05 +02:00
|
|
|
# source functions
|
|
|
|
for file in /usr/lib/vpn-select.d/*; do
|
|
|
|
[ -f $file ] && . "$file"
|
|
|
|
supported_protocols="$supported_protocols $protocol"
|
|
|
|
done
|
2020-04-17 17:54:49 +02:00
|
|
|
|
2020-10-19 23:29:05 +02:00
|
|
|
# clear old config
|
|
|
|
for protocol in $supported_protocols; do
|
|
|
|
"${protocol}_clear"
|
|
|
|
done
|
|
|
|
|
|
|
|
# configure vpn
|
|
|
|
|
|
|
|
if [ -n "$hoodfile" ] && [ -s "$hoodfile" ] ; then
|
2020-04-17 17:54:49 +02:00
|
|
|
json_load "$(cat "$hoodfile")"
|
2020-10-19 23:29:05 +02:00
|
|
|
json_select hood
|
|
|
|
json_get_var id id
|
|
|
|
json_select ".."
|
2020-04-17 17:54:49 +02:00
|
|
|
json_select vpn
|
2020-10-19 23:29:05 +02:00
|
|
|
json_get_keys vpn_keys
|
|
|
|
for key in $vpn_keys; do
|
|
|
|
json_select $key
|
2020-04-17 17:54:49 +02:00
|
|
|
json_get_var protocol protocol
|
2020-10-19 23:29:05 +02:00
|
|
|
"${protocol}_addpeer"
|
2020-04-17 17:54:49 +02:00
|
|
|
json_select ".." # back to vpn
|
|
|
|
done
|
2016-07-05 23:25:46 +02:00
|
|
|
fi
|
2020-10-19 23:29:05 +02:00
|
|
|
|
|
|
|
# start/restart/stop vpnservices
|
|
|
|
for protocol in $supported_protocols; do
|
|
|
|
"${protocol}_start_stop"
|
|
|
|
done
|