2015-09-22 15:16:42 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -ex
|
|
|
|
OVPN_DATA=basic-data
|
|
|
|
CLIENT=travis-client
|
2015-09-22 17:22:11 +00:00
|
|
|
IMG=kylemanna/openvpn
|
2015-09-22 15:16:42 +00:00
|
|
|
|
2015-09-22 17:22:11 +00:00
|
|
|
#
|
|
|
|
# Create a docker container with the config data
|
|
|
|
#
|
2015-09-22 15:16:42 +00:00
|
|
|
docker run --name $OVPN_DATA -v /etc/openvpn busybox
|
|
|
|
|
2015-09-22 17:22:11 +00:00
|
|
|
ip addr ls
|
|
|
|
SERV_IP=$(ip -4 -o addr show scope global | awk '{print $4}' | sed -e 's:/.*::' | head -n1)
|
|
|
|
docker run --volumes-from $OVPN_DATA --rm $IMG ovpn_genconfig -u udp://$SERV_IP
|
2015-09-22 15:16:42 +00:00
|
|
|
|
|
|
|
# nopass is insecure
|
2015-09-22 17:22:11 +00:00
|
|
|
docker run --volumes-from $OVPN_DATA --rm -it -e "EASYRSA_BATCH=1" -e "EASYRSA_REQ_CN=Travis-CI Test CA" $IMG ovpn_initpki nopass
|
2015-09-22 15:16:42 +00:00
|
|
|
|
2015-09-22 17:22:11 +00:00
|
|
|
docker run --volumes-from $OVPN_DATA --rm -it $IMG easyrsa build-client-full $CLIENT nopass
|
2015-09-22 15:16:42 +00:00
|
|
|
|
2015-09-22 17:22:11 +00:00
|
|
|
docker run --volumes-from $OVPN_DATA --rm $IMG ovpn_getclient $CLIENT | tee client/config.ovpn
|
2015-09-22 15:16:42 +00:00
|
|
|
|
2016-05-11 22:35:00 +00:00
|
|
|
docker run --volumes-from $OVPN_DATA --rm $IMG ovpn_listclients | grep $CLIENT
|
|
|
|
|
2015-09-22 17:22:11 +00:00
|
|
|
#
|
|
|
|
# Fire up the server
|
|
|
|
#
|
2016-06-01 20:41:25 +00:00
|
|
|
sudo iptables -N DOCKER || echo 'Firewall already configured'
|
|
|
|
sudo iptables -I FORWARD -j DOCKER || echo 'Forward already configured'
|
2015-09-22 17:22:11 +00:00
|
|
|
# run in shell bg to get logs
|
|
|
|
docker run --name "ovpn-test" --volumes-from $OVPN_DATA --rm -p 1194:1194/udp --privileged $IMG &
|
2015-09-22 15:16:42 +00:00
|
|
|
|
2015-09-22 17:22:11 +00:00
|
|
|
#for i in $(seq 10); do
|
|
|
|
# SERV_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}')
|
|
|
|
# test -n "$SERV_IP" && break
|
|
|
|
#done
|
|
|
|
#sed -ie s:SERV_IP:$SERV_IP:g client/config.ovpn
|
|
|
|
|
|
|
|
#
|
|
|
|
# Fire up a client in a container since openvpn is disallowed by Travis-CI, don't NAT
|
|
|
|
# the host as it confuses itself:
|
|
|
|
# "Incoming packet rejected from [AF_INET]172.17.42.1:1194[2], expected peer address: [AF_INET]10.240.118.86:1194"
|
|
|
|
#
|
|
|
|
docker run --rm --net=host --privileged --volume $PWD/client:/client $IMG /client/wait-for-connect.sh
|
|
|
|
|
|
|
|
#
|
|
|
|
# Client either connected or timed out, kill server
|
|
|
|
#
|
|
|
|
kill %1
|
|
|
|
|
|
|
|
#
|
|
|
|
# Celebrate
|
|
|
|
#
|
|
|
|
cat <<EOF
|
|
|
|
___________
|
|
|
|
< it worked >
|
|
|
|
-----------
|
|
|
|
\ ^__^
|
|
|
|
\ (oo)\_______
|
|
|
|
(__)\ )\/\\
|
|
|
|
||----w |
|
|
|
|
|| ||
|
|
|
|
EOF
|