From cf3cd322192a2f21c4d6b141c5820e9d1619a848 Mon Sep 17 00:00:00 2001 From: uvok cheetah Date: Mon, 27 May 2024 19:08:23 +0200 Subject: Add new wireguard helper scripts --- scripts/wireguard-add-peer.sh | 19 ++++++++++++++++++ scripts/wireguard-new-client.sh | 43 +++++++++++++++++++++++++++++++++++++++++ scripts/wireguard-new-if.sh | 26 +++++++++++++++++++++++++ scripts/wireguard-new-peer.sh | 43 ----------------------------------------- 4 files changed, 88 insertions(+), 43 deletions(-) create mode 100644 scripts/wireguard-add-peer.sh create mode 100644 scripts/wireguard-new-client.sh create mode 100644 scripts/wireguard-new-if.sh delete mode 100644 scripts/wireguard-new-peer.sh diff --git a/scripts/wireguard-add-peer.sh b/scripts/wireguard-add-peer.sh new file mode 100644 index 0000000..97c3cf3 --- /dev/null +++ b/scripts/wireguard-add-peer.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -euo pipefail +IFS=$'\n\t' + +if [[ $# -ne 1 ]]; then + echo "Usage: $0 " + exit 1 +fi + +cat >> "$1" < " + 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 $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 <> "$1" <" + exit 1 +fi + +[[ -a "$1" ]] && echo "File already exists. Nope." >&2 && exit 1 + +# create client keypair +srv_privkey=$(wg genkey) +srv_pubkey=$(wg pubkey <<< "$srv_privkey") + +umask 177 + +cat >> "$1" < " - 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 $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 <> "$1" <