-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathmerge.sh
57 lines (49 loc) · 1.61 KB
/
merge.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
#!/bin/bash
#######################################################################
# Latest versions of Openvpn supports inline certs and keys
# so you have one client script, instead of script plus 4 keys and certs
#
# This tool assumes
# 1) Openvpn script and certs plus keys are in same directory
# 2) Certs are usually specified in Openvpn script like
# ca ca.crt
# or
# ca /etc/local/openvpn/ca.crt
########################################################################
# Arguments list:
# $1 - cilent name
# $2 - destination ovpn file
#
ca="ca.crt"
cert="$1.crt"
key="$1.key"
tlscrypt="ta.key"
ovpndest="$2.ovpn"
########################################################################
# Delete existing call to keys and certs
#
sed -i \
-e '/ca .*'$ca'/d' \
-e '/cert .*'$cert'/d' \
-e '/key .*'$key'/d' \
-e '/tls-crypt .*'$tlscrypt'/d' $ovpndest
########################################################################
# Add keys and certs inline
#
#echo "key-direction 1" >> $ovpndest
echo "<ca>" >> $ovpndest
awk /BEGIN/,/END/ < ./$ca >> $ovpndest
echo "</ca>" >> $ovpndest
echo "<cert>" >> $ovpndest
awk /BEGIN/,/END/ < ./$cert >> $ovpndest
echo "</cert>" >> $ovpndest
echo "<key>" >> $ovpndest
awk /BEGIN/,/END/ < ./$key >> $ovpndest
echo "</key>" >> $ovpndest
echo "<tls-crypt>" >> $ovpndest
awk /BEGIN/,/END/ < ./$tlscrypt >> $ovpndest
echo "</tls-crypt>" >> $ovpndest
########################################################################
# Delete key and cert files
#
rm $ca $cert $key $tlsauth