#!/bin/bash
# OpenVPN script for IPCop/iOS, www.magnuswedberg.com
#
# Remember to change IP+port, UDP/TCP, MTU, and comp-lzo
FILE="/var/ipcop/openvpn/certs/$1.p12"
if [ -f "$FILE" ];
then
echo "tls-client" > $1.ovpn
echo "client" >> $1.ovpn
echo "dev tun" >> $1.ovpn
echo "proto udp" >> $1.ovpn
echo "remote !!!YOUR_IP_HERE!!! 1194" >> $1.ovpn
echo "resolv-retry infinite" >> $1.ovpn
echo "nobind" >> $1.ovpn
echo "persist-key" >> $1.ovpn
echo "tun-mtu 1400" >> $1.ovpn
echo "cipher BF-CBC" >> $1.ovpn
echo "comp-lzo" >> $1.ovpn
echo "verb 3" >> $1.ovpn
echo "ns-cert-type server" >> $1.ovpn
echo "key-direction 1" >> $1.ovpn
echo "" >> $1.ovpn
sed -n 1,22p /var/ipcop/ca/cacert.pem >> $1.ovpn
echo "" >> $1.ovpn
echo "" >> $1.ovpn
openssl pkcs12 -in $FILE -clcerts -nokeys -passin pass: | head -n 30 | tail -n 23 >> $1.ovpn
echo "" >> $1.ovpn
echo "" >> $1.ovpn
openssl pkcs12 -in $FILE -nocerts -nodes -passin pass: | head -n 33 | tail -n 28 >> $1.ovpn
echo "" >> $1.ovpn
else
echo "File $FILE does not exist" >&2
echo "Syntax: ./openvpncmd CertName"
echo "CertName = what you input as cert name in the IPCop dialog"
fi