summaryrefslogtreecommitdiff
path: root/scripts/wireguard-new-peer.sh
blob: d810d4f007769eb881a5f5ea43dae91157f7ae1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash

set -euo pipefail
IFS=$'\n\t'

if [[ $# -ne 3 ]]; then
    echo "Usage: $0 <wg server config file> <server endpoint with port> <desired ip for client (without CIDR)>"
    exit 1
fi

# create client keypair
cli_privkey=$(wg genkey)
cli_pubkey=$(wg pubkey <<< "$cli_privkey")

# PrivateKey = ...
# if you don't leave a space, this won't work
srv_pubkey=$(awk -e '/PrivateKey/ { print $3; }' "$1"  | wg pubkey)

# create client config
echo "*** Scan this with your mobile phone ***"
qrencode -t ansiutf8 <<EOF
[Interface]
PrivateKey = $cli_privkey
Address = $3/24

[Peer]
PublicKey = $srv_pubkey
Endpoint = $2
AllowedIPs = 0.0.0.0/0, ::/0
EOF

tee -a "$1" <<EOF

# Auto-Generated
[Peer]
PublicKey = $cli_pubkey
AllowedIPs = $3/32

EOF