Browse Source

Fixed breakage caused by splitting on SPACE in OPENVPN_CONFIG

Changed to split on comma as many openvpn configs have space in the name.

Added a bit more validation that a provider is set.

Updated docs.
master
Dean Bailey 6 years ago
parent
commit
6649edeedf
2 changed files with 13 additions and 11 deletions
  1. 2
    2
      README.md
  2. 11
    9
      openvpn/start.sh

+ 2
- 2
README.md View File

@@ -65,10 +65,10 @@ Find available OpenVPN configurations by looking in the openvpn folder of the Gi
-e "OPENVPN_CONFIG=ipvanish-AT-Vienna-vie-c02"
```

You can also provide a list of openvpn configuration filenames separated by a space.
You can also provide a comma separated list of openvpn configuration filenames.
If you provide a list, a file will be randomly chosen in the list, this is useful for redundancy setups. For example:
```
-e "OPENVPN_CONFIG=ipvanish-AT-Vienna-vie-c02 ipvanish-FR-Paris-par-a01 ipvanish-DE-Frankfurt-fra-a01"
-e "OPENVPN_CONFIG=ipvanish-AT-Vienna-vie-c02,ipvanish-FR-Paris-par-a01,ipvanish-DE-Frankfurt-fra-a01"
```
If you provide a list and the selected server goes down, after the value of ping-timeout the container will be restarted and a server will be randomly chosen, note that the faulty server can be chosen again, if this should occur, the container will be restarted again until a working server is selected.


+ 11
- 9
openvpn/start.sh View File

@@ -1,7 +1,11 @@
#!/bin/bash
VPN_PROVIDER="${OPENVPN_PROVIDER,,}"
VPN_PROVIDER_CONFIGS="/etc/openvpn/${VPN_PROVIDER}"
if [[ ! -d "${VPN_PROVIDER_CONFIGS}" ]]; then

if [[ "${OPENVPN_PROVIDER}" == "**None**" ]] || [[ -z "${OPENVPN_PROVIDER-}" ]]; then
echo "OpenVPN provider not set. Exiting."
exit 1
elif [[ ! -d "${VPN_PROVIDER_CONFIGS}" ]]; then
echo "Could not find OpenVPN provider: ${OPENVPN_PROVIDER}"
echo "Please check your settings."
exit 1
@@ -9,14 +13,12 @@ fi

echo "Using OpenVPN provider: ${OPENVPN_PROVIDER}"

if [[ ! -z "${OPENVPN_CONFIG}" ]]; then
n=$(echo "$OPENVPN_CONFIG" | wc -w)
if [ $n -gt 1 ]
then
rnd=$((RANDOM%n+1))
srv=$(echo "$OPENVPN_CONFIG" | awk -vrnd=$rnd '{print $rnd}')
echo "$n servers found in OPENVPN_CONFIG, $srv chosen randomly"
OPENVPN_CONFIG=$srv
if [[ -n "${OPENVPN_CONFIG-}" ]]; then
readarray -t OPENVPN_CONFIG_ARRAY <<< "${OPENVPN_CONFIG//,/$'\n'}"
if (( ${#OPENVPN_CONFIG_ARRAY[@]} > 1 )); then
OPENVPN_CONFIG_RANDOM=$((RANDOM%${#OPENVPN_CONFIG_ARRAY[@]}))
echo "${#OPENVPN_CONFIG_ARRAY[@]} servers found in OPENVPN_CONFIG, ${OPENVPN_CONFIG_ARRAY[${OPENVPN_CONFIG_RANDOM}]} chosen randomly"
OPENVPN_CONFIG="${OPENVPN_CONFIG_ARRAY[${OPENVPN_CONFIG_RANDOM}]}"
fi

if [[ -f "${VPN_PROVIDER_CONFIGS}/${OPENVPN_CONFIG}".ovpn ]]; then

Loading…
Cancel
Save