#!/bin/bash

# To create: ./create_client_profile.sh client

client=$1
server_ip_address="64.237.55.206"

easyrsa_directory=~/easy-rsa
output_directory=~/openvpn-clients

if [ -z "$client" ]; then
    echo "Usage: $0 client_name"
    exit 1
fi

cat > ${output_directory}/${client}.ovpn <<EOF
client
dev tun
proto udp

tun-ipv6

remote ${server_ip_address} 1194

resolv-retry infinite
nobind

persist-key
persist-tun

remote-cert-tls server
cipher AES-256-GCM

key-direction 1
verb 3

<ca>
$(cat ${easyrsa_directory}/pki/ca.crt)
</ca>

<cert>
$(sed -ne '/BEGIN CERTIFICATE/,/END CERTIFICATE/p' ${easyrsa_directory}/pki/issued/${client}.crt)
</cert>

<key>
$(cat ${easyrsa_directory}/pki/private/${client}.key)
</key>

<tls-auth>
$(cat ${easyrsa_directory}/ta.key)
</tls-auth>
EOF

echo "Profile created: ${output_directory}/${client}.ovpn"
