Skip to content

Commit

Permalink
openvpn.sh merge dperson#272, DRY version
Browse files Browse the repository at this point in the history
  • Loading branch information
David Personette committed Apr 21, 2020
1 parent 1991808 commit d0155e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ The vpn.conf should look like this:

### Run with openvpn client configuration and provided auth

In case you want to use your client configuration in /vpn named vpn.conf
In case you want to use your client configuration in /vpn named vpn.conf
but adding your vpn user and password by command line

sudo docker run -it --cap-add=NET_ADMIN --device /dev/net/tun --name vpn \
Expand Down
9 changes: 5 additions & 4 deletions openvpn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,11 @@ return_route() { local network="$1" gw="$(ip route |awk '/default/ {print $3}')"
# pass) password on VPN
# Return: configured auth file
vpn_auth() { local user="$1" pass="$2"

echo "$user" >$auth
echo "$pass" >>$auth
chmod 0600 $auth

export AUTH_COMMAND="--auth-user-pass $auth"
}

### vpn: setup openvpn client
Expand Down Expand Up @@ -275,7 +276,8 @@ route6="$dir/.firewall6"
[[ -f $cert ]] || { [[ $(ls -d $dir/* | egrep '\.ce?rt$' 2>&- | wc -w) -eq 1 \
]] && cert="$(ls -d $dir/* | egrep '\.ce?rt$' 2>&-)"; }

[[ "${VPN_AUTH:-""}" ]] && eval vpn_auth $(sed 's/^/"/; s/$/"/; s/;/" "/g' <<< $VPN_AUTH)
[[ "${VPN_AUTH:-""}" ]] && eval vpn_auth $(sed 's/^/"/; s/$/"/; s/;/" "/g' <<< \
$VPN_AUTH)
[[ "${CERT_AUTH:-""}" ]] && cert_auth "$CERT_AUTH"
[[ "${DNS:-""}" ]] && dns
[[ "${GROUPID:-""}" =~ ^[0-9]+$ ]] && groupmod -g $GROUPID -o vpn
Expand All @@ -294,8 +296,7 @@ done < <(env | awk '/^VPNPORT[0-9=_]/ {sub (/^[^=]*=/, "", $0); print}')
while getopts ":hc:df:a:m:o:p:R:r:v:" opt; do
case "$opt" in
h) usage ;;
a) eval vpn_auth $(sed 's/^/"/; s/$/"/; s/;/" "/g' <<< $OPTARG)
AUTH_COMMAND="--auth-user-pass $auth" ;;
a) eval vpn_auth $(sed 's/^/"/; s/$/"/; s/;/" "/g' <<< $OPTARG) ;;
c) cert_auth "$OPTARG" ;;
d) dns ;;
f) firewall "$OPTARG"; touch $route $route6 ;;
Expand Down

0 comments on commit d0155e3

Please sign in to comment.