diff options
author | Michal Hrusecky <michal@hrusecky.net> | 2020-07-23 12:10:45 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-07-23 13:10:09 +0200 |
commit | 8483bf3126583041bd6f5808978dc3b14ad15a1a (patch) | |
tree | 08df0e5d4377ff29051bbe2eae7d3a43ea5445f1 /package/network/services/openvpn/files/lib/functions | |
parent | eda9751d86927672bb86f895e31a5b8bea76cdfc (diff) | |
download | upstream-8483bf3126583041bd6f5808978dc3b14ad15a1a.tar.gz upstream-8483bf3126583041bd6f5808978dc3b14ad15a1a.tar.bz2 upstream-8483bf3126583041bd6f5808978dc3b14ad15a1a.zip |
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)
Diffstat (limited to 'package/network/services/openvpn/files/lib/functions')
-rw-r--r-- | package/network/services/openvpn/files/lib/functions/openvpn.sh | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/package/network/services/openvpn/files/lib/functions/openvpn.sh b/package/network/services/openvpn/files/lib/functions/openvpn.sh new file mode 100644 index 0000000000..83fb1bb453 --- /dev/null +++ b/package/network/services/openvpn/files/lib/functions/openvpn.sh @@ -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 +} + |