Skip to content

Instantly share code, notes, and snippets.

@erdoukki
Forked from RichardBronosky/README.md
Created March 3, 2019 10:00
Show Gist options
  • Save erdoukki/854af97f0a5e3ff2aa7cb28b80e10896 to your computer and use it in GitHub Desktop.
Save erdoukki/854af97f0a5e3ff2aa7cb28b80e10896 to your computer and use it in GitHub Desktop.
Create a single-file "unified format" ovpn file from the legacy client.ovpn client.key client.crt ca.crt four-file format.

unify-ovpn.sh

  1. cd to the directory where your 4 files are. (client.ovpn, client.key, client.crt, and ca.crt)

  2. Call unify-ovpn.sh with the filename of your ovpn file

     unify-ovpn.sh client.ovpn
    
  3. A new file named client_unified.ovpn will be created

#!/bin/bash
src=$1
dst="$(basename $src .ovpn)_unified.ovpn"
gawk -f - $src > $dst << 'AWK'
BEGIN {
RS="\n|\r\n"
}
function readcert(file) {
while ((getline < file) > 0) {
contents = contents RT $0
if ($1 == "-----BEGIN")
contents = $0
if ($1 == "-----END")
break
}
close(file)
return contents
}
$1 ~ /^(ca|key|cert)$/ {
tag = $1
print "#" $0
print "<" tag ">"
print readcert($2)
print "</" tag ">"
next
}
{
print
}
AWK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment