33 lines
No EOL
654 B
Bash
33 lines
No EOL
654 B
Bash
#!/bin/bash
|
|
# Author: Martijn de Boer
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "You must be a root user" 2>&1
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -f /etc/debian_version ]]; then
|
|
echo "This script only works on Debian"
|
|
exit 1
|
|
fi
|
|
|
|
set -e
|
|
|
|
generate_wireguard_config() {
|
|
local server_index="$1"
|
|
local private_key=$(wg genkey)
|
|
local public_key=$(echo "$private_key" | wg pubkey)
|
|
|
|
cat > "/etc/wireguard/wg0-$server_index.conf" <<EOL
|
|
[Interface]
|
|
PrivateKey = $private_key
|
|
Address = 10.0.0.$((server_index + 1))/24
|
|
ListenPort = 51820
|
|
|
|
[Peer]
|
|
PublicKey = $(cat /etc/wireguard/public_key)
|
|
AllowedIPs = 10.0.0.1/32
|
|
Endpoint = controlplane.habalancer.tld:51820
|
|
|
|
EOL
|
|
} |