Created
March 28, 2016 15:46
-
-
Save belst/78dd0592522d5f788be5 to your computer and use it in GitHub Desktop.
Inlines Cert and Key files into open vpn config
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
#!/usr/bin/env bash | |
IP=$(hostname -I | cut -f1 -d' '); | |
if [ -z "$1" ]; then | |
echo "usage: $0 <configname>"; | |
exit 1; | |
fi; | |
echo 'Adding IP and creating config'; | |
sed -e "s/remote my-server-1 1194/remote ${IP} 1194/g" client.ovpn > ${1}.ovpn; | |
# COMMENT OUT KEYS | |
echo 'commenting out key files'; | |
sed -i "s/ca ca.crt/#ca ca.crt/g" ${1}.ovpn; | |
sed -i "s/cert client.crt/#cert client.crt/g" ${1}.ovpn; | |
sed -i "s/key client.key/#key client.crt/g" ${1}.ovpn; | |
# ADD KEYS | |
echo 'adding ca cert to config'; | |
echo '' >> ${1}.ovpn; | |
echo "<ca>" >> ${1}.ovpn; | |
cat /etc/openvpn/ca.crt >> ${1}.ovpn; | |
echo "</ca>" >> ${1}.ovpn; | |
echo 'adding client cert to config'; | |
echo "<cert>" >> ${1}.ovpn; | |
cat /etc/openvpn/easy-rsa/keys/${1}.crt >> ${1}.ovpn; | |
echo "</cert>" >> ${1}.ovpn; | |
echo 'adding client key to config'; | |
echo "<key>" >> ${1}.ovpn; | |
cat /etc/openvpn/easy-rsa/keys/${1}.key >> ${1}.ovpn; | |
echo "</key>" >> ${1}.ovpn; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment