1
1
#! /bin/bash
2
- set -ex
2
+ set -e
3
+
4
+ [ -n " ${DEBUG+x} " ] && set -x
5
+
3
6
OVPN_DATA=basic-data-otp
4
7
CLIENT=travis-client
5
8
IMG=kylemanna/openvpn
6
9
OTP_USER=otp
10
+ CLIENT_DIR=" $( readlink -f " $( dirname " $BASH_SOURCE " ) /../../client" ) "
11
+
7
12
# Function to fail
8
13
abort () { cat <<< " $@" 1>&2 ; exit 1; }
9
14
@@ -23,22 +28,22 @@ docker run --volumes-from $OVPN_DATA --rm -it -e "EASYRSA_BATCH=1" -e "EASYRSA_R
23
28
docker run --volumes-from $OVPN_DATA --rm -it $IMG easyrsa build-client-full $CLIENT nopass
24
29
25
30
# Generate OTP credentials for user named test, should return QR code for test user
26
- docker run --volumes-from $OVPN_DATA --rm -it $IMG ovpn_otp_user $OTP_USER | tee client /qrcode.txt
31
+ docker run --volumes-from $OVPN_DATA --rm -it $IMG ovpn_otp_user $OTP_USER | tee $CLIENT_DIR /qrcode.txt
27
32
# Ensure a chart link is printed in client OTP configuration
28
- grep ' https://www.google.com/chart' client /qrcode.txt || abort ' Link to chart not generated'
29
- grep ' Your new secret key is:' client /qrcode.txt || abort ' Secret key is missing'
33
+ grep ' https://www.google.com/chart' $CLIENT_DIR /qrcode.txt || abort ' Link to chart not generated'
34
+ grep ' Your new secret key is:' $CLIENT_DIR /qrcode.txt || abort ' Secret key is missing'
30
35
# Extract an emergency code from textual output, grepping for line and trimming spaces
31
- OTP_TOKEN=$( grep -A1 ' Your emergency scratch codes are' client /qrcode.txt | tail -1 | tr -d ' [[:space:]]' )
36
+ OTP_TOKEN=$( grep -A1 ' Your emergency scratch codes are' $CLIENT_DIR /qrcode.txt | tail -1 | tr -d ' [[:space:]]' )
32
37
# Token should be present
33
38
if [ -z $OTP_TOKEN ]; then
34
39
abort " QR Emergency Code not detected"
35
40
fi
36
41
37
42
# Store authentication credentials in config file and tell openvpn to use them
38
- echo -e " $OTP_USER \n$OTP_TOKEN " > client /credentials.txt
43
+ echo -e " $OTP_USER \n$OTP_TOKEN " > $CLIENT_DIR /credentials.txt
39
44
40
45
# Override the auth-user-pass directive to use a credentials file
41
- docker run --volumes-from $OVPN_DATA --rm $IMG ovpn_getclient $CLIENT | sed ' s/auth-user-pass/auth-user-pass \/client\/credentials.txt/' | tee client /config.ovpn
46
+ docker run --volumes-from $OVPN_DATA --rm $IMG ovpn_getclient $CLIENT | sed ' s/auth-user-pass/auth-user-pass \/client\/credentials.txt/' | tee $CLIENT_DIR /config.ovpn
42
47
43
48
#
44
49
# Fire up the server
@@ -52,14 +57,14 @@ docker run --name "ovpn-test" --volumes-from $OVPN_DATA --rm -p 1194:1194/udp --
52
57
# SERV_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}')
53
58
# test -n "$SERV_IP" && break
54
59
# done
55
- # sed -ie s:SERV_IP:$SERV_IP:g client /config.ovpn
60
+ # sed -ie s:SERV_IP:$SERV_IP:g $CLIENT_DIR /config.ovpn
56
61
57
62
#
58
63
# Fire up a client in a container since openvpn is disallowed by Travis-CI, don't NAT
59
64
# the host as it confuses itself:
60
65
# "Incoming packet rejected from [AF_INET]172.17.42.1:1194[2], expected peer address: [AF_INET]10.240.118.86:1194"
61
66
#
62
- docker run --rm --net=host --privileged --volume $PWD /client :/client $IMG /client/wait-for-connect.sh
67
+ docker run --rm --net=host --privileged --volume $CLIENT_DIR :/client $IMG /client/wait-for-connect.sh
63
68
64
69
#
65
70
# Client either connected or timed out, kill server
0 commit comments