Skip to content

Commit 739ee0e

Browse files
update add-vpn-user
1 parent a4f82f2 commit 739ee0e

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

vpn-client/playbooks/templates/add-vpn-user.sh

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,35 @@
22

33
set -euxo pipefail
44

5+
# Generate new client vpn configs and
6+
# write them to file
7+
# does not distribute them.
8+
59
# Configuration parameters
6-
SERVER_PUBLIC_IP=$1
7-
SERVER_PORT=$2
8-
SERVER_PUBLIC_KEY=$(wg pubkey < router-private.key)
9-
DNS=$3
10+
# Check if $1 is set and not empty
11+
if [[ $# -ge 1 ]]; then
12+
SERVER_PUBLIC_IP=$1
13+
else
14+
SERVER_PUBLIC_IP=$(ip route get 8.8.8.8 | head -n 1 | awk '{print $7}')
15+
fi
16+
17+
echo "$SERVER_PUBLIC_IP"
18+
19+
# Check if $2 is set and not empty
20+
if [[ $# -ge 2 ]]; then
21+
SERVER_PORT=$2
22+
else
23+
SERVER_PORT=3478
24+
echo Using default port
25+
fi
1026

27+
# Check if $3 is set and not empty
28+
if [[ $# -ge 3 ]]; then
29+
DNS=$3
30+
else
31+
DNS="8.8.8.8"
32+
echo Using default DNS
33+
fi
1134
# Generate client keys
1235
CLIENT_PRIVATE_KEY=$(wg genkey)
1336
CLIENT_PUBLIC_KEY=$(wg pubkey <<< "${CLIENT_PRIVATE_KEY}")

0 commit comments

Comments
 (0)