-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_client_keys.sh
executable file
·41 lines (33 loc) · 1.3 KB
/
generate_client_keys.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
#This scripts automates process of creating OpenVPN client keys and emails
#the keys with windows appliacation and instructions.
#run from /etc/openvpn/easy-rsa after creating server cert etc.
user=
mailto=
while getopts 'u:m:' OPTION
do
case $OPTION in
u)user="$OPTARG"
;;
m)mailto="$OPTARG"
;;
?)printf "Usage: %s: [-u username] [-m mailto] args\n" $(basename $0) >&2
exit 2
;;
esac
done
shift $(($OPTIND - 1))
printf 'Username = "%s" specified\n' "$user"
# Create OpenVPN Client Certificates
#echo "Generating client certificates for the user"
source vars
./build-key $user
#create zip file to be sent to the user with certificates and configs
mkdir client_keys/openvpn_keys_$user
cp keys/$user.crt keys/$user.key keys/ca.crt client_keys/openvpn_keys_$user
cp client.ovpn.template client_keys/openvpn_keys_$user/client.ovpn
sed -i 's/USERNAME/'$user'/g' client_keys/openvpn_keys_$user/client.ovpn
cd client_keys && zip -r openvpn_keys_$useropenvpn_keys_$user.zip openvpn_keys_$user && cd ..
#send an email to the user with certs, configs and instructions
echo "Sending autogenerated email to $user"
mutt -s "Autogenerated: OpenVPN Setup" -a client_keys/openvpn_keys_$useropenvpn_keys_$user.zip -a openvpn-2.0.9-gui-1.0.3-install.exe -- $mailto < howto_setup_openvpn_on_windows.txt