#!/bin/sh
client_base_conf="client_base_conf.ovpn"
ca_file="ca.crt"
tls_aut_key="ta.key"
client_crt_ext=".crt"
client_key_ext=".key"
client_conf_ext=".ovpn"
client=$1
if [ "$client" = "" ]; then
echo "missing client name" 1>&2
exit
fi
client_crt=${client}${client_crt_ext}
client_key=${client}${client_key_ext}
if [ ! -f $client_crt ]; then
echo "no such file: $client_crt" 1>&2
exit
fi
if [ ! -f $client_key ]; then
echo "no such file: $client_key" 1>&2
exit
fi
congif=${client}${client_conf_ext}.tmp
congif_file=${client}${client_conf_ext}
cat $client_base_conf > $congif
echo "" >> $congif
echo "" >> $congif
cat $ca_file | \
grep -A 100 "BEGIN CERTIFICATE" | \
grep -B 100 "END CERTIFICATE" >> $congif
echo "" >> $congif
echo "" >> $congif
cat $client_crt | \
grep -A 100 "BEGIN CERTIFICATE" | \
grep -B 100 "END CERTIFICATE" >> $congif
echo "" >> $congif
echo "" >> $congif
cat $client_key | \
grep -A 100 "BEGIN RSA PRIVATE KEY" | \
grep -B 100 "END RSA PRIVATE KEY" >> $congif
echo "" >> $congif
if [ -f $tls_aut_key ]; then
echo "key-direction 1" >> $congif
echo "" >> $congif
cat $tls_aut_key | \
grep -A 100 "BEGIN OpenVPN Static key V1" | \
grep -B 100 "END OpenVPN Static key V1" >> $congif
echo "" >> $congif
fi
tr -d '\r' < $congif > $congif_file
rm $congif
exit