~/Projects/openvpn-go
git clone https://code.lsong.org/openvpn-go
Commit
- Commit
- fd98646e0f340a706265a06247657b1aa223a92e
- Author
- Ain Ghazal <[email protected]>
- Date
- 2022-03-18 23:00:32 +0100 +0100
- Diffstat
tests/integration/extract.sh | 36 ++++++++++++++++++++++++++++++++++++
add convenience script to extract key blocks
diff --git a/tests/integration/extract.sh b/tests/integration/extract.sh new file mode 100755 index 0000000000000000000000000000000000000000..9967e7ba33ef86fac8e9d9786b270363498c3d72 --- /dev/null +++ b/tests/integration/extract.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# (c) Ain Ghazal 2022 +# this file converts an inline openvpn config file into +# a standalone config plus separate files for the ca.crt, +# cert.pem and key.pem. + +FILE=$1 +tail=0 + +# first lets extract the inline blocks +tag=ca +f=ca.crt +sed -n "/<$tag>/,/<\/$tag>/p" $FILE > $f +n=$(wc -l $f | cut -f 1 -d ' ') +tail=$(($tail+n)) +cat $f | tail -n $(($n-1)) | head -n $(($n-2)) | tee $f + +tag=key +f=key.pem +sed -n "/<$tag>/,/<\/$tag>/p" $FILE > $f +n=$(wc -l $f | cut -f 1 -d ' ') +tail=$(($tail+n)) +cat $f | tail -n $(($n-1)) | head -n $(($n-2)) | tee $f + +tag=cert +f=cert.pem +sed -n "/<$tag>/,/<\/$tag>/p" $FILE > $f +n=$(wc -l $f | cut -f 1 -d ' ') +tail=$(($tail+n)) +cat $f | tail -n $(($n-1)) | head -n $(($n-2)) | tee $f + +all=$(wc -l $FILE | cut -f -1 -d ' ') +cp $FILE config.bk +head -n $(($all-$tail)) $FILE | tee config + +# TODO need to ignore the ta key until we do support it...