This commit is contained in:
Ben Yanke 2016-05-11 23:51:58 +00:00
commit dbfda206fb

View File

@ -7,6 +7,8 @@
# your Debian/Ubuntu/CentOS box. It has been designed to be as unobtrusive and # your Debian/Ubuntu/CentOS box. It has been designed to be as unobtrusive and
# universal as possible. # universal as possible.
PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
VPNFOLDER="$PATH/openVpnConfigFiles"
# Detect Debian users running the script with "sh" instead of bash # Detect Debian users running the script with "sh" instead of bash
if readlink /proc/$$/exe | grep -qs "dash"; then if readlink /proc/$$/exe | grep -qs "dash"; then
@ -42,17 +44,19 @@ else
fi fi
newclient () { newclient () {
mkdir $VPNFOLDER;
# Generates the custom client.ovpn # Generates the custom client.ovpn
cp /etc/openvpn/client-common.txt ~/$1.ovpn cp /etc/openvpn/client-common.txt $VPNFOLDER/$1.ovpn
echo "<ca>" >> ~/$1.ovpn echo "<ca>" >> $VPNFOLDER/$1.ovpn
cat /etc/openvpn/easy-rsa/pki/ca.crt >> ~/$1.ovpn cat /etc/openvpn/easy-rsa/pki/ca.crt >> $VPNFOLDER/$1.ovpn
echo "</ca>" >> ~/$1.ovpn echo "</ca>" >> $VPNFOLDER/$1.ovpn
echo "<cert>" >> ~/$1.ovpn echo "<cert>" >> $VPNFOLDER/$1.ovpn
cat /etc/openvpn/easy-rsa/pki/issued/$1.crt >> ~/$1.ovpn cat /etc/openvpn/easy-rsa/pki/issued/$1.crt >> $VPNFOLDER/$1.ovpn
echo "</cert>" >> ~/$1.ovpn echo "</cert>" >> $VPNFOLDER/$1.ovpn
echo "<key>" >> ~/$1.ovpn echo "<key>" >> $VPNFOLDER/$1.ovpn
cat /etc/openvpn/easy-rsa/pki/private/$1.key >> ~/$1.ovpn cat /etc/openvpn/easy-rsa/pki/private/$1.key >> $VPNFOLDER/$1.ovpn
echo "</key>" >> ~/$1.ovpn echo "</key>" >> $VPNFOLDER/$1.ovpn
} }
# Try to get our IP from the system and fallback to the Internet. # Try to get our IP from the system and fallback to the Internet.
@ -86,7 +90,7 @@ if [[ -e /etc/openvpn/server.conf ]]; then
# Generates the custom client.ovpn # Generates the custom client.ovpn
newclient "$CLIENT" newclient "$CLIENT"
echo "" echo ""
echo "Client $CLIENT added, certs available at ~/$CLIENT.ovpn" echo "Client $CLIENT added, certs available at $VPNFOLDER/$CLIENT.ovpn"
exit exit
;; ;;
2) 2)
@ -367,6 +371,6 @@ verb 3" > /etc/openvpn/client-common.txt
echo "" echo ""
echo "Finished!" echo "Finished!"
echo "" echo ""
echo "Your client config is available at ~/$CLIENT.ovpn" echo "Your client config is available at $VPNFOLDER/$CLIENT.ovpn"
echo "If you want to add more clients, you simply need to run this script another time!" echo "If you want to add more clients, you simply need to run this script another time!"
fi fi