Combine user args with generated args
Generated arguments will be added only if matching arguments were not specified by the user. User arguments will be placed after generated arguments. This allows the user to override any generated configuration values.
This commit is contained in:
parent
097376db75
commit
d77ba5e1e8
36
bin/ovpn_run
36
bin/ovpn_run
@ -13,7 +13,29 @@ set -e
|
|||||||
cd $OPENVPN
|
cd $OPENVPN
|
||||||
|
|
||||||
# Build runtime arguments array based on environment
|
# Build runtime arguments array based on environment
|
||||||
ARGS=("--config" "$OPENVPN/openvpn.conf")
|
USER_ARGS=("${@}")
|
||||||
|
ARGS=()
|
||||||
|
|
||||||
|
# Checks if ARGS already contains the given value
|
||||||
|
function hasArg {
|
||||||
|
local element
|
||||||
|
for element in "${@:2}"; do
|
||||||
|
[ "${element}" == "${1}" ] && return 0
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Adds the given argument if it's not already specified.
|
||||||
|
function addArg {
|
||||||
|
local arg="${1}"
|
||||||
|
[ $# -ge 1 ] && local val="${2}"
|
||||||
|
if ! hasArg "${arg}" "${USER_ARGS[@]}"; then
|
||||||
|
ARGS+=("${arg}")
|
||||||
|
[ $# -ge 1 ] && ARGS+=("${val}")
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
addArg "--config" "$OPENVPN/openvpn.conf"
|
||||||
|
|
||||||
source "$OPENVPN/ovpn_env.sh"
|
source "$OPENVPN/ovpn_env.sh"
|
||||||
|
|
||||||
@ -23,7 +45,7 @@ if [ ! -c /dev/net/tun ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -d "$OPENVPN/ccd" ]; then
|
if [ -d "$OPENVPN/ccd" ]; then
|
||||||
ARGS+=("--client-config-dir" "$OPENVPN/ccd")
|
addArg "--client-config-dir" "$OPENVPN/ccd"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# When using --net=host, use this to specify nat device.
|
# When using --net=host, use this to specify nat device.
|
||||||
@ -48,7 +70,7 @@ if [ -r "$EASYRSA_PKI/crl.pem" ]; then
|
|||||||
ln "$EASYRSA_PKI/crl.pem" "$OPENVPN/crl.pem"
|
ln "$EASYRSA_PKI/crl.pem" "$OPENVPN/crl.pem"
|
||||||
chmod 644 "$OPENVPN/crl.pem"
|
chmod 644 "$OPENVPN/crl.pem"
|
||||||
fi
|
fi
|
||||||
ARGS+=("--crl-verify" "$OPENVPN/crl.pem")
|
addArg "--crl-verify" "$OPENVPN/crl.pem"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ip -6 route show default 2>/dev/null
|
ip -6 route show default 2>/dev/null
|
||||||
@ -61,8 +83,6 @@ if [ $? = 0 ]; then
|
|||||||
sysctl -w net.ipv6.conf.all.forwarding=1 || echo "Failed to enable IPv6 Forwarding"
|
sysctl -w net.ipv6.conf.all.forwarding=1 || echo "Failed to enable IPv6 Forwarding"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$#" -gt 0 ]; then
|
echo "Running 'openvpn ${ARGS[@]} ${USER_ARGS[@]}'"
|
||||||
exec openvpn "$@"
|
exec openvpn ${ARGS[@]} ${USER_ARGS[@]}
|
||||||
else
|
|
||||||
exec openvpn ${ARGS[@]}
|
|
||||||
fi
|
|
||||||
|
Loading…
Reference in New Issue
Block a user