#!/bin/bash
# First argument: Client identifier, e.g. Smartphone_ User_1
OUTPUTDIR="$1"
CONFIGNAME=$OUTPUTDIR
BASE_CONFIG="client_template.ovpn"
OUTPUT=$CONFIG_NAME.ovpn
#function() check_dir
## Parameter: $CONFIG_NAME
#{
#if [ ! -d $OUTPUTDIR ]; then
# mkdir $OUTPUTDIR
#else
# echo "Directory \"$OUTPUTDIR\" already exsists!"
# #read -p "Continue? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
#fi
#}
check_tools()
# Check, if necessary tooles are available:
{
if [ -e /usr/share/easy-rsa/easyrsa ]
then
:
else
echo "Tool: \"easyrsa\" not installed! --> EXIT"
exit 1
fi
}
# MAIN
check_tools
if [ -z "${CONFIGNAME}" ]; then
echo "\"${CONFIGNAME}\" is empty!"
echo "Please specify client config name. --> EXIT!"
exit 1
else
if [ ! -d $OUTPUTDIR ]; then
echo "ERROR: Folder for $CONFIG_NAME not found --> exit!"
exit 1
else
echo -n "Generating ${CONFIGNAME} ... "
cat ${BASE_CONFIG} \
<(echo -e '') \
$CONFIGNAME/ca.crt \
<(echo -e '\n') \
$CONFIGNAME/$CONFIGNAME.crt \
<(echo -e '\n') \
$CONFIGNAME/$CONFIGNAME.key \
<(echo -e '\n') \
$CONFIGNAME/tls-auth.key \
<(echo -e '') \
> ${CONFIGNAME}/${CONFIGNAME}.ovpn
echo "done!"
fi
fi