Skip to content

Instantly share code, notes, and snippets.

@krotesk
Forked from renatolfc/ovpn-writer.sh
Last active January 27, 2021 10:50
Show Gist options
  • Save krotesk/894f79c6db0a925e2967873fdd53094d to your computer and use it in GitHub Desktop.
Save krotesk/894f79c6db0a925e2967873fdd53094d to your computer and use it in GitHub Desktop.
Script to generate an OpenVPN client configuration file in the unified format
#!/bin/sh
##
## Usage: ./ovpn-writer.sh CA_CERT CLIENT_CERT CLIENT_KEY
## File save as hostname.ovpn and yealink.tar
## using OVPN port = 636
##
server=$(wget -qO- eth0.me)
cacert=${1?"The path to the ca certificate file is required"}
client_cert=${2?"The path to the client certificate file is required"}
client_key=${3?"The path to the client private key file is required"}
hostname=$(cat /etc/hostname)
filename=${hostname}.ovpn
echo "client
dev tun
dev-type tun
proto tcp
remote ${server}
port 636
resolv-retry infinite
nobind
persist-key
persist-tun
;ns-cert-type server
;tls-auth ta.key 1
;cipher x
comp-lzo
verb 3
<ca>" > ${filename}
cat ${cacert} >> ${filename}
echo "</ca>
<cert>" >> ${filename}
cat ${client_cert} >> ${filename}
echo "</cert>
<key>" >> ${filename}
cat ${client_key} >> ${filename}
echo "</key>" >> ${filename}
/bin/cp ${filename} vpn.cnf && tar -cf yealink.tar vpn.cnf && rm vpn.cnf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment