wagon/back/lib/ssl_peer_del

26 lines
736 B
Bash
Executable File

#!/bin/bash
# FILE: wgapi:back/lib/ssl/peer/del
# DESCRIPTION: Delete SSL cert for a removed device
# USAGE: del hostname username
# ERRORS:
# 3: Bad usage
# 4: Missing config file
# 5: Failed to delete files
CONFIG_FILE='/etc/wgapi/config'
if ! [ ${#} -eq 2 ]; then
printf 'ERROR! Invalid number of arguments to %s: %s\n' "${0}" "${*}" >&2
exit 3
fi; if ! [ -f "${CONFIG_FILE}" ]; then
printf 'ERROR! %s couldnt find %s\n' "${0}" "${CONFIG_FILE}" >&2
exit 4
fi
source "${CONFIG_FILE}"
hostname="${1}"
username="${2}"
if ! sudo rm -rf "${SSL_CONFIG_DIR:?}/${username:?}/${hostname:?}/" 2>/dev/null; then
printf 'ERROR! %s failed to delete %s!\n' "${0}" "${SSL_CONFIG_DIR}/${username}/${hostname}/" >&2
exit 5
fi