#!/bin/bash # FILE: wgapi:back/lib/wg/peer/del # DESCRIPTION: Delete a peer from a wireguard interface # USAGE: del pubkey # ERRORS: # 3: Bad usage # 4: wg binary not found # 5: config not found # 6: wg command failed # 7: Not root CONFIG_FILE='/etc/wgapi/config' if ! [ ${#} -eq 1 ]; then printf 'ERROR! Bad input: %s %s\n' "${0}" "${*}" >>"${LOGFILE}" exit 3 fi; if ! [ -x '/usr/bin/wg' ]; then printf 'ERROR! %s could not find /usr/bin/wg\n' "${0}" >>"${LOGFILE}" exit 4 fi; if ! [ -f "${CONFIG_FILE}" ]; then printf 'ERROR! %s could not find %s!\n' "${0}" "${CONFIG_FILE}" >>"${LOGFILE}" exit 5 fi source "${CONFIG_FILE}" if ! res="$(sudo /usr/bin/wg set "${TLD}" peer "${1}" remove)"; then printf 'ERROR! Wireguard failed: %s\n' "${res}" >>"${LOGFILE}" exit 6 fi