fix: 🐛 Persist wireguard configs

master
Keith Irwin 2023-12-01 12:43:49 -07:00
parent 9f3faf0e24
commit 8431533718
Signed by: ki9
GPG Key ID: DF773B3F4A88DA86
2 changed files with 25 additions and 10 deletions

View File

@ -1,12 +1,19 @@
#!/bin/bash
# FILE: wagon:back/lib/wg/peer/add
# FILE: wagon:back/lib/wg_peer_add
# DESCRIPTION: Add a new peer to a wireguard interface
# USAGE: add pubkey psk allowedips
# USAGE: wg_peer_add pubkey psk allowedips
source /etc/wagon/config
pubkey="${1}"; psk="${2}"; allowedips="${3}"
pubkey="${1}"; psk="${2}"; allowedips="${3}"; domain="${4}"
if ! res="$(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}" >&2
# 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
fi
# Save config
if ! res_conf="$(/usr/bin/wg-quick save ${TLD})"; then
printf '%s %s\n' "${?}" "${res_conf}" >&2
exit 1
fi

View File

@ -1,11 +1,19 @@
#!/bin/bash
# FILE: wagon:back/lib/wg/peer/del
# FILE: wagon:back/lib/wg_peer_del
# DESCRIPTION: Delete a peer from a wireguard interface
# USAGE: del pubkey
# USAGE: wg_peer_del pubkey
source /etc/wagon/config
pubkey="${1}"
if ! res="$(sudo /usr/bin/wg set "${TLD}" peer "${1}" remove)"; then
printf 'ERROR! Wireguard failed: %s\n' "${res}" >&2
# 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
if ! res_conf="$(/usr/bin/wg-quick save ${TLD})"; then
printf '%s %s\n' "${?}" "${res_conf}" >&2
exit 1
fi