container-openvpn/bin/ovpn_init
Kyle Manna e1902bc2cd ovpn_genconfig: Add generate config script
* Create a generate config script so that the new docker containers can
  regenerate the OpenVPN configuration without clobbering the PKI setup.
2014-06-04 16:50:53 -07:00

40 lines
849 B
Bash
Executable File

#!/bin/sh
#
# Initialize the PKI and OpenVPN configs
#
set -ex
cn=$1
if [ -z "$cn" ]; then
echo "Common name not specified"
exit 1
fi
# Provides a sufficient warning before erasing pre-existing files
easyrsa init-pki
# For a CA key with a password, manually init; this is autopilot
easyrsa build-ca nopass
easyrsa gen-dh
openvpn --genkey --secret $OPENVPN/pki/ta.key
# Was nice to autoset, but probably a bad idea in practice, users should
# have to explicitly specify the common name of their server
#if [ -z "$cn"]; then
# #TODO: Handle IPv6 (when I get a VPS with IPv6)...
# ip4=$(dig +short myip.opendns.com @resolver1.opendns.com)
# ptr=$(dig +short -x $ip4 | sed -e 's:\.$::')
#
# [ -n "$ptr" ] && cn=$ptr || cn=$ip4
#fi
echo "$cn" > $OPENVPN/servername
easyrsa build-server-full $cn nopass
ovpn_genconfig "$cn"