<file_sep>#!/bin/sh
# 
# ------------------------------------------------------------------------------
# ISC License http://opensource.org/licenses/isc-license.txt
# ------------------------------------------------------------------------------
# Copyright (c) 2017, <NAME> <<EMAIL>>
# 
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
# 
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

VERSION=1.0

set -e

[ -z "$1" ] && {
    echo "Version $VERSION"
    echo "Usage:";
    echo "  ./$(basename $0) <your>.ovpn"
    exit 1;
}

NAME=$(basename $1)
NAME="openvpn-${NAME%.*}"

FILE=$(realpath $1)

# container exists
[ $(docker ps -aqf "name=$NAME" | grep -cE '.+') != 0 ] || {
    docker create --name $NAME -itv $FILE:/config.ovpn \
    --net=host --cap-add=NET_ADMIN --device /dev/net/tun \
    kylemanna/openvpn openvpn --config /config.ovpn;
    EXIT_CODE=$?;
    [ $EXIT_CODE = 0 ] || { exit $EXIT_CODE; }
}

# toggle container
[ $(docker ps -qf "name=$NAME" | grep -cE '.+') != 0 ] && {
    echo "Your IP is: $(dig +short myip.opendns.com @resolver1.opendns.com)"
    echo -n "Stopping "
    docker stop $NAME;
    EXIT_CODE=$?
    docker ps -af "name=$NAME";
    for i in $(seq 3); do echo -n '.'; sleep 1; done
    echo
    echo "Your IP is: $(dig +short myip.opendns.com @resolver1.opendns.com)"
    exit $EXIT_CODE;
} || {
    echo "Your IP is: $(dig +short myip.opendns.com @resolver1.opendns.com)"
    echo -n "Starting "
    docker start $NAME;
    EXIT_CODE=$?
    docker ps -af "name=$NAME";
    for i in $(seq 4); do echo -n '.'; sleep 1; done
    echo
    echo "Your IP is: $(dig +short myip.opendns.com @resolver1.opendns.com)"
    exit $EXIT_CODE;
}
<file_sep># FIXME

https://community.openvpn.net/openvpn/wiki/SWEET32

	docker run --rm -it kylemanna/openvpn sh
	# where?
	--cipher AES-256-CBC

Answer  
https://github.com/kylemanna/docker-openvpn/issues/163#issuecomment-277008738


# Server
([Run client](#client) see bottom)

**Note:** the cert passphrase you will find in the admin.kdbx

## Setup (only once)

```shell
$ OVPN_DATA="ovpn-data"
$ docker volume create --name $OVPN_DATA
$ docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn \
    ovpn_genconfig -u udp://heisenberg.aptly.de
$ docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn ovpn_initpki
```

### Create & run OpenVPN server

```shell
$ docker run -v $OVPN_DATA:/etc/openvpn -d -p 1194:1194/udp --cap-add=NET_ADMIN \
    --name openvpn kylemanna/openvpn
```

## Start/stop OpenVPN server

```shell
$ docker start openvpn
$ docker stop openvpn
```

## Create clients (example!)

```shell
$ for CLIENTNAME in lschr mthielcke dsteiner; do \
  docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn easyrsa build-client-full $CLIENTNAME nopass; \
  docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_getclient $CLIENTNAME > $CLIENTNAME.ovpn; \
done
```

<a id="client"></a>

# Run client (Linux, your local machine)

```shell
$ sudo openvpn --config dsteiner.ovpn
$ sudo openvpn --config dsteiner.ovpn --daemon # background
```
