-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-key.sh
77 lines (57 loc) · 2.17 KB
/
make-key.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh
if [ ! -f ./vars ]; then
echo "You need to install these files into an easy-rsa folder!"
exit
fi
if [ -z "$1" -o -z "$2" ]; then
echo "Please specify two parameters: common name and email"
exit
fi
name="$1"
mail="$2"
. ./vars > /dev/null
setupscript="configscript/hostscripts/${name}-exitvpn-setup.sh"
export KEY_EMAIL="$mail"
./build-key $1 || {
echo "Building the key failed! Make sure easy-rsa is installed and working. Exiting."
exit
}
cat configscript/template-checkdepencies.txt > $setupscript
cat configscript/template-setup.txt >> $setupscript
# Add openvpn config
echo "cat << EOF > /etc/openvpn/exitvpn/exitvpn.conf" >> $setupscript
cat configscript/template-ovpn.txt >> $setupscript
echo "cert /etc/openvpn/exitvpn/${name}.crt" >> $setupscript
echo "key /etc/openvpn/exitvpn/${name}.key" >> $setupscript
echo "EOF" >> $setupscript
# Add up script
echo "cat << EOF > /etc/openvpn/exitvpn/up.sh" >> $setupscript
cat configscript/template-up.txt >> $setupscript
echo "EOF" >> $setupscript
# Add down script
echo "cat << EOF > /etc/openvpn/exitvpn/down.sh" >> $setupscript
cat configscript/template-down.txt >> $setupscript
echo "EOF" >> $setupscript
# Add common functions
echo "cat << EOF > /etc/openvpn/exitvpn/functions.sh" >> $setupscript
cat configscript/template-functions.txt >> $setupscript
echo "EOF" >> $setupscript
echo "chmod +x /etc/openvpn/exitvpn/up.sh" >> $setupscript
echo "chmod +x /etc/openvpn/exitvpn/down.sh" >> $setupscript
echo "chmod +x /etc/openvpn/exitvpn/functions.sh" >> $setupscript
# Add ca.crt
echo "cat << EOF > /etc/openvpn/exitvpn/ca.crt" >> $setupscript
cat keys/ca.crt >> $setupscript
echo "EOF" >> $setupscript
# add host cert
echo "cat << EOF > /etc/openvpn/exitvpn/${name}.crt" >> $setupscript
cat keys/${name}.crt >> $setupscript
echo "EOF" >> $setupscript
echo "chmod 600 /etc/openvpn/exitvpn/${name}.crt" >> $setupscript
# add host key
echo "cat << EOF > /etc/openvpn/exitvpn/${name}.key" >> $setupscript
cat keys/${name}.key >> $setupscript
echo "EOF" >> $setupscript
echo "chmod 600 /etc/openvpn/exitvpn/${name}.key" >> $setupscript
# finally add some foo to restart services
cat configscript/template-servicerestart.txt >> $setupscript