summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruvok cheetah2024-04-06 19:42:57 +0200
committeruvok cheetah2024-04-06 19:42:57 +0200
commit95ba2359a009b979fb5962bea42943a2a39c935a (patch)
tree4dffe315a6a2016cd04ca23f6157e5ced8a1324c
parent2d9cd8474fa2c13314cd207af59f16174bf1e7bd (diff)
wg: Get rid of hostname/port - use system provided
also, extract Pubkey properly
-rw-r--r--scripts/wireguard-new-peer.sh17
1 files changed, 10 insertions, 7 deletions
diff --git a/scripts/wireguard-new-peer.sh b/scripts/wireguard-new-peer.sh
index d810d4f..28ca90e 100644
--- a/scripts/wireguard-new-peer.sh
+++ b/scripts/wireguard-new-peer.sh
@@ -3,8 +3,8 @@
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)>"
+if [[ $# -ne 2 ]]; then
+ echo "Usage: $0 <wg server config file> <desired ip for client (without CIDR)>"
exit 1
fi
@@ -14,27 +14,30 @@ 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)
+#srv_pubkey=$(awk -e '/PrivateKey/ { print $2; }' "$1" | wg pubkey)
+srv_pubkey=$(awk -e 'match($0, /^PrivateKey\s*=\s*(.*)$/, ar) { print ar[1]; }' "$1" | wg pubkey)
+srv_port=$(awk -e 'match($0, /^ListenPort\s*=\s*(.*)$/, ar) { print ar[1]; }' "$1")
# create client config
echo "*** Scan this with your mobile phone ***"
qrencode -t ansiutf8 <<EOF
[Interface]
PrivateKey = $cli_privkey
-Address = $3/24
+Address = $2/24
[Peer]
PublicKey = $srv_pubkey
-Endpoint = $2
+Endpoint = $(hostname --fqdn):${srv_port}
AllowedIPs = 0.0.0.0/0, ::/0
+PersistentKeepalive = 30
EOF
-tee -a "$1" <<EOF
+cat >> "$1" <<EOF
# Auto-Generated
[Peer]
PublicKey = $cli_pubkey
-AllowedIPs = $3/32
+AllowedIPs = $2/32
EOF