cd /etc/wireguard umask 077 wg genkey | tee server.key | wg pubkey > server.pub config_file="/etc/wireguard/wg0.conf" cat > "$config_file" <> "$config_file" ### Add clients: mkdir -p /etc/wireguard/client-config function add_client() { cd /etc/wireguard name="$1" wg genkey | tee "client-config/${name}.key" | wg pubkey > "${name}.pub" wg genpsk > "${name}.psk" cp "${name}.psk" "client-config" echo "[Peer]" >> /etc/wireguard/wg0.conf echo "PublicKey = $(cat "${name}.pub")" >> /etc/wireguard/wg0.conf echo "PresharedKey = $(cat "${name}.psk")" >> /etc/wireguard/wg0.conf echo "AllowedIPs = 10.100.0.$2/32, fd08:4711::$2/128" >> /etc/wireguard/wg0.conf cd - cd /etc/wireguard/client-config echo "[Interface]" > "${name}.conf" echo "Address = 10.100.0.$2/32, fd08:4711::$2/128" >> "${name}.conf" echo "DNS = 10.100.0.1" >> "${name}.conf" echo "PrivateKey = $(cat "${name}.key")" >> "${name}.conf" echo >> "${name}.conf" <> "${name}.conf" echo "PresharedKey = $(cat "${name}.psk")" >> "${name}.conf" qrencode -t ansiutf8 < "${name}.conf" qrencode -t png -o "${name}.conf.png" < "${name}.conf" cd - } add_client "myclient" "2"