2022-09-06 20:57:41 -06:00
|
|
|
#!/bin/bash
|
2023-04-02 13:46:52 -06:00
|
|
|
# FILE: wagon:back/lib/wg/peer/add
|
2022-09-06 20:57:41 -06:00
|
|
|
# DESCRIPTION: Add a new peer to a wireguard interface
|
|
|
|
# USAGE: add pubkey psk allowedips
|
|
|
|
|
2023-04-02 13:46:52 -06:00
|
|
|
source /etc/wagon/config
|
2022-12-04 08:53:22 -07:00
|
|
|
pubkey="${1}"; psk="${2}"; allowedips="${3}"
|
2022-09-06 20:57:41 -06:00
|
|
|
|
2022-11-27 16:00:43 -07:00
|
|
|
if ! res="$(printf '%s\n' "${psk}" | sudo /usr/bin/wg set "${TLD}" peer "${pubkey}" preshared-key /dev/stdin allowed-ips "${allowedips}")"; then
|
2022-12-03 17:07:03 -07:00
|
|
|
printf '%s %s\n' "${?}" "${res}" >&2
|
2022-12-03 18:23:13 -07:00
|
|
|
exit 1
|
2022-11-27 16:00:43 -07:00
|
|
|
fi
|