2022-09-06 20:57:41 -06:00
|
|
|
#!/bin/bash
|
2023-12-01 12:43:49 -07:00
|
|
|
# FILE: wagon:back/lib/wg_peer_del
|
2022-09-06 20:57:41 -06:00
|
|
|
# DESCRIPTION: Delete a peer from a wireguard interface
|
2023-12-01 12:43:49 -07:00
|
|
|
# USAGE: wg_peer_del pubkey
|
2022-09-06 20:57:41 -06:00
|
|
|
|
2023-04-02 13:46:52 -06:00
|
|
|
source /etc/wagon/config
|
2023-12-01 12:43:49 -07:00
|
|
|
pubkey="${1}"
|
2022-09-06 20:57:41 -06:00
|
|
|
|
2023-12-01 12:43:49 -07:00
|
|
|
# Delete peer from interface
|
|
|
|
if ! res_int="$(sudo /usr/bin/wg set "${TLD}" peer "${pubkey}" remove)"; then
|
|
|
|
printf 'ERROR! Wireguard failed: %s\n' "${res_int}" >&2
|
|
|
|
exit 1
|
|
|
|
fi &
|
|
|
|
|
|
|
|
# Save config
|
2023-12-02 18:50:17 -07:00
|
|
|
if ! res_conf="$(sudo /usr/bin/wg-quick save ${TLD})"; then
|
2023-12-01 12:43:49 -07:00
|
|
|
printf '%s %s\n' "${?}" "${res_conf}" >&2
|
2022-12-03 18:23:13 -07:00
|
|
|
exit 1
|
2022-09-10 16:26:06 -06:00
|
|
|
fi
|