-
-
Save BoeingX/a073569b8aabf856be292ed6d000cbbc to your computer and use it in GitHub Desktop.
Script to generate an OpenVPN client configuration file in the unified format
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 | |
# | |
if [ "$#" -lt 6 ]; then | |
echo "./ovpn-writer.sh <server address> <protocol> " | |
echo " <port> <ca certificate> " | |
echo " <client certificate> <client key>" | |
echo " [tls key] " | |
exit 1 | |
fi | |
server=${1?"The server address is required"} | |
protocol=${2?"The protocol is required (e.g. udp)"} | |
port=${3?"Port number is required (e.g. 1194)"} | |
cacert=${4?"The path to the ca certificate file is required"} | |
client_cert=${5?"The path to the client certificate file is required"} | |
client_key=${6?"The path to the client private key file is required"} | |
tls_key=${7} | |
cat << EOF | |
setenv FORWARD_COMPATIBLE 1 | |
client | |
dev tun | |
remote ${server} ${port} | |
resolv-retry infinite | |
nobind | |
persist-key | |
persist-tun | |
verb 3 | |
keepalive 10 600 | |
proto ${protocol} | |
cipher BF-CBC | |
<ca> | |
EOF | |
cat ${cacert} | |
cat << EOF | |
</ca> | |
<cert> | |
EOF | |
cat ${client_cert} | sed -n '/.*BEGIN.*/, /.*END.*/p' | |
cat << EOF | |
</cert> | |
<key> | |
EOF | |
cat ${client_key} | |
cat << EOF | |
</key> | |
EOF | |
if [[ -z $tls_key ]]; then | |
exit 0 | |
fi | |
cat << EOF | |
remote-cert-tls server | |
key-direction 1 | |
<tls-auth> | |
EOF | |
cat ${tls_key} | sed -n '/.*BEGIN.*/, /.*END.*/p' | |
cat << EOF | |
</tls-auth> | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment