Created
January 17, 2016 14:08
-
-
Save d-mart/1c8b8b115ce32b296102 to your computer and use it in GitHub Desktop.
Create openvpn client files with inline certs and keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SED=gsed # osx, install via brew | |
#SED=sed # linux | |
######################################################################## | |
# Name of certs and keys and client ovpn script | |
# | |
client_name="$1" | |
ca="ca.crt" | |
cert="${client_name}.crt" | |
key="${client_name}.key" | |
tlsauth="ta.key" | |
ovpnsrc="${client_name}.ovpn" | |
ovpndest="${client_name}-inline.ovpn" | |
######################################################################## | |
# Copy source as base for destination | |
cp $ovpnsrc $ovpndest | |
######################################################################## | |
# Delete existing call to keys and certs | |
# | |
$SED -i -e "/ca .*${ca}/d" $ovpndest | |
$SED -i -e "/cert .*${cert}/d" $ovpndest | |
$SED -i -e "/key .*${key}/d" $ovpndest | |
$SED -i -e "/tls-auth .*${tlsauth}/d" $ovpndest | |
######################################################################## | |
# Add keys and certs inline | |
# | |
echo "key-direction 1" >> $ovpndest | |
echo "<ca>" >> $ovpndest | |
awk /BEGIN/,/END/ < ./$ca >> $ovpndest | |
echo "</ca>" >> $ovpndest | |
echo "<cert>" >> $ovpndest | |
awk /BEGIN/,/END/ < ./$cert >> $ovpndest | |
echo "</cert>" >> $ovpndest | |
echo "<key>" >> $ovpndest | |
awk /BEGIN/,/END/ < ./$key >> $ovpndest | |
echo "</key>" >> $ovpndest | |
echo "<tls-auth>" >> $ovpndest | |
awk /BEGIN/,/END/ < ./$tlsauth >> $ovpndest | |
echo "</tls-auth>" >> $ovpndest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment