aboutsummaryrefslogtreecommitdiffstats
path: root/package/network/services/openvpn/files/lib/functions/openvpn.sh
blob: 83fb1bb453e1f7b7977c262d647c1f5d2dd4dea9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/sh

get_openvpn_option() {
	local config="$1"
	local variable="$2"
	local option="$3"

	local value="$(sed -rne 's/^[ \t]*'"$option"'[ \t]+(([^ \t\\]|\\.)+)[ \t]*$/\1/p' "$config" | tail -n1 | sed -re 's/\\(.)/\1/g')"
	[ -n "$value" ] || value="$(sed -rne 's/^[ \t]*'"$option"'[ \t]+'"'([^']+)'"'[ \t]*$/\1/p' "$config" | tail -n1)"
	[ -n "$value" ] || value="$(sed -rne 's/^[ \t]*'"$option"'[ \t]+"(([^"\\]|\\.)+)"[ \t]*$/\1/p' "$config" | tail -n1 | sed -re 's/\\(.)/\1/g')"
	[ -n "$value" ] || return 1

	export -n "$variable=$value"
	return 0
}