Skip to content

Instantly share code, notes, and snippets.

@rexcze-zz
Created April 4, 2013 15:14
Show Gist options
  • Save rexcze-zz/5311266 to your computer and use it in GitHub Desktop.
Save rexcze-zz/5311266 to your computer and use it in GitHub Desktop.
openvpn client automatization script
#!/bin/bash
#autor j.bittner
set -e
CAHOME="/etc/openvpn/easy-rsa"
/bin/echo -en "Insert clients name. Format name.domain.tld \n"
read KLIENTNAME
/bin/echo -en "Insert VPN IP address of new client"
read KLIENTIPAD
if [ -z ${KLIENTNAME} ];then
/bin/echo "You really should insert a name..."
exit 1
fi
source ${CAHOME}/vars
${CAHOME}/build-key ${KLIENTNAME}
/bin/mv ${CAHOME}/keys/${KLIENTNAME}.crt /etc/openvpn/keys/${KLIENTNAME}.crt
/bin/mv ${CAHOME}/keys/${KLIENTNAME}.key /etc/openvpn/keys/${KLIENTNAME}.key
##client configuration with its certificates put in archve and then to /var/www/openvpn
/bin/mkdir /tmp/${KLIENTNAME}
/bin/cp /etc/openvpn/keys/${KLIENTNAME}.key /tmp/${KLIENTNAME}/
/bin/cp /etc/openvpn/keys/${KLIENTNAME}.crt /tmp/${KLIENTNAME}/
/bin/cp /etc/openvpn/keys/ca.crt /tmp/${KLIENTNAME}/ca.crt
###openvpn client configuration creating
/bin/echo "client" > /tmp/${KLIENTNAME}/client.conf
/bin/echo "dev tun" >> /tmp/${KLIENTNAME}/client.conf
/bin/echo "port 1194" >> /tmp/${KLIENTNAME}/client.conf
/bin/echo "proto udp" >> /tmp/${KLIENTNAME}/client.conf
/bin/echo " " >> /tmp/${KLIENTNAME}/client.conf
/bin/echo "remote vpn.aurem.cz 1194" >> /tmp/${KLIENTNAME}/client.conf
/bin/echo "nobind" >> /tmp/${KLIENTNAME}/client.conf
/bin/echo " " >> /tmp/${KLIENTNAME}/client.conf
/bin/echo "ca /etc/openvpn/keys/ca.crt" >> /tmp/${KLIENTNAME}/client.conf
/bin/echo "cert /etc/openvpn/keys/${KLIENTNAME}.crt" >> /tmp/${KLIENTNAME}/client.conf
/bin/echo "key /etc/openvpn/keys/${KLIENTNAME}.key" >> /tmp/${KLIENTNAME}/client.conf
/bin/echo " " >> /tmp/${KLIENTNAME}/client.conf
/bin/echo "comp-lzo" >> /tmp/${KLIENTNAME}/client.conf
/bin/echo "persist-key" >> /tmp/${KLIENTNAME}/client.conf
/bin/echo "persist-tun" >> /tmp/${KLIENTNAME}/client.conf
/bin/echo " " >> /tmp/${KLIENTNAME}/client.conf
/bin/echo "verb 3" >> /tmp/${KLIENTNAME}/client.conf
### pack it and move it
cd /tmp
/bin/tar -pczf ${KLIENTNAME}.tar.gz ${KLIENTNAME}
/bin/mv ${KLIENTNAME}.tar.gz /var/www/openvpn/
/bin/rm -r /tmp/${KLIENTNAME}
###Create ccd config with ip address
/bin/echo "ifconfig-push ${KLIENTIPAD} 10.8.0.1" > /etc/openvpn/ccd/${KLIENTNAME}
###show warning
/bin/echo -ne "Keys are now stored in /etc/openvpn/keys\n"
/bin/echo -ne "Configuration for client is stored in /var/www/openvpn/${KLIENTNAME}.tar.gz\n"
/bin/echo -ne "Insert \"${KLIENTNAME},${KLIENTIPAD}\" to /etc/openvpn/ipp.txt\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment