wagon/back/lib/wg_peer_add

20 lines
599 B
Bash
Executable File

#!/bin/bash
# FILE: wagon:back/lib/wg_peer_add
# DESCRIPTION: Add a new peer to a wireguard interface
# USAGE: wg_peer_add pubkey psk allowedips
source /etc/wagon/config
pubkey="${1}"; psk="${2}"; allowedips="${3}"; domain="${4}"
# Add new peer to interface
if ! res_int="$(printf '%s\n' "${psk}" | sudo /usr/bin/wg set "${TLD}" peer "${pubkey}" preshared-key /dev/stdin allowed-ips "${allowedips}")"; then
printf '%s %s\n' "${?}" "${res_int}" >&2
exit 1
fi
# Save config
if ! res_conf="$(/usr/bin/wg-quick save ${TLD})"; then
printf '%s %s\n' "${?}" "${res_conf}" >&2
exit 1
fi