openpvn: Split out config parsing code for reuse
Split out code that parses openvpn configuration file into separate file that can be later included in various scripts and reused. Signed-off-by: Michal Hrusecky <michal@hrusecky.net> (cherry picked from commit 86d8467c8ab792c79809a08c223dd9d40da6da2e)master
parent
eda9751d86
commit
8483bf3126
@ -0,0 +1,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
|
||||
}
|
||||
|
Loading…
Reference in New Issue