83fb1bb453e1f7b7977c262d647c1f5d2dd4dea9
[openwrt/openwrt.git] / package / network / services / openvpn / files / lib / functions / openvpn.sh
1 #!/bin/sh
2
3 get_openvpn_option() {
4 local config="$1"
5 local variable="$2"
6 local option="$3"
7
8 local value="$(sed -rne 's/^[ \t]*'"$option"'[ \t]+(([^ \t\\]|\\.)+)[ \t]*$/\1/p' "$config" | tail -n1 | sed -re 's/\\(.)/\1/g')"
9 [ -n "$value" ] || value="$(sed -rne 's/^[ \t]*'"$option"'[ \t]+'"'([^']+)'"'[ \t]*$/\1/p' "$config" | tail -n1)"
10 [ -n "$value" ] || value="$(sed -rne 's/^[ \t]*'"$option"'[ \t]+"(([^"\\]|\\.)+)"[ \t]*$/\1/p' "$config" | tail -n1 | sed -re 's/\\(.)/\1/g')"
11 [ -n "$value" ] || return 1
12
13 export -n "$variable=$value"
14 return 0
15 }
16