2014-06-04 18:13:59 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
#
|
|
|
|
# Initialize the PKI and OpenVPN configs
|
|
|
|
#
|
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
|
|
|
cn=$1
|
|
|
|
|
|
|
|
if [ -z "$cn" ]; then
|
|
|
|
echo "Common name not specified"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-06-05 00:07:07 +00:00
|
|
|
# Specify "nopass" as arg[2] to make the CA insecure
|
|
|
|
nopass=$2
|
|
|
|
|
2014-06-04 18:13:59 +00:00
|
|
|
# Provides a sufficient warning before erasing pre-existing files
|
|
|
|
easyrsa init-pki
|
|
|
|
|
2014-06-05 00:07:07 +00:00
|
|
|
# CA always has a password for protection in event server is compromised. The
|
|
|
|
# password is only needed to sign client/server certificates. No password is
|
|
|
|
# needed for normal OpenVPN operation.
|
|
|
|
easyrsa build-ca $nopass
|
2014-06-04 18:13:59 +00:00
|
|
|
|
|
|
|
easyrsa gen-dh
|
|
|
|
openvpn --genkey --secret $OPENVPN/pki/ta.key
|
|
|
|
|
2014-06-04 18:15:43 +00:00
|
|
|
# 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
|
2014-06-04 18:13:59 +00:00
|
|
|
|
|
|
|
echo "$cn" > $OPENVPN/servername
|
|
|
|
|
2014-06-05 00:07:07 +00:00
|
|
|
# For a server key with a password, manually init; this is autopilot
|
2014-06-04 18:13:59 +00:00
|
|
|
easyrsa build-server-full $cn nopass
|
|
|
|
|
2014-06-04 23:49:13 +00:00
|
|
|
ovpn_genconfig "$cn"
|