Last active
August 13, 2020 10:50
-
-
Save morten-olsen/9c750287036e9e62c345be40e116a387 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
source "$PWD/.env" | |
SERVER_PUBLIC_KEY="foo" | |
CONFIG="${CONFIG:-/etc/wireguard/wg0.conf}" | |
CIDR="${CIDR:-32}" | |
DNS="${DNS:-1.1.1.1}" | |
[ -f "$CONFIG" ] || echo "Config not found" && exit 1 | |
function add_device() { | |
NAME=$1 | |
IP=$2 | |
PRIVATE_KEY=$(wg genkey) | |
PUBLIC_KEY=$(echo "$PRIVATE_KEY" | wg pubkey) | |
SERVER_PEER=" | |
[Peer] | |
#Name: $NAME | |
PublicKey = $PUBLIC_KEY | |
AllowedIPs = $IP/$CIDR | |
" | |
echo "$SERVER_PEER" >> "$CONFIG" | |
CLIENT_CONFIG=" | |
[Interface] | |
PrivateKey = $PRIVATE_KEY | |
Address = $IP/$CIDR | |
DNS = $DNS | |
[Peer] | |
PublicKey = $SERVER_PUBLIC_KEY | |
Endpoint = $HOST:${PORT:-51820} | |
AllowedIPs = 0.0.0.0/0, ::/0 | |
" | |
echo "Client Config | |
$CLIENT_CONFIG | |
" | |
echo "$CLIENT_CONFIG" | qrencode -t ansiutf8 | |
} | |
add_device "$1" "$2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment