wagon/back/lib/ssl_peer_del

26 lines
769 B
Plaintext
Raw Normal View History

2022-08-29 01:04:37 -06:00
#!/bin/bash
# FILE: wgapi:back/lib/ssl/peer/del
# DESCRIPTION: Delete SSL cert for a removed device
# USAGE: del hostname username
2022-09-06 20:57:41 -06:00
# ERRORS:
# 3: Bad usage
2022-09-10 16:38:11 -06:00
# 4: Missing config file
# 5: Failed to delete files
2022-08-29 01:04:37 -06:00
2022-09-10 16:38:11 -06:00
CONFIG_FILE='/etc/wgapi/config'
if ! [ ${#} -eq 2 ]; then
printf 'ERROR! Invalid number of arguments to %s: %s\n' "${0}" "${*}" >>"${LOGFILE}"
exit 3
fi; if ! [ -f "${CONFIG_FILE}" ]; then
printf 'ERROR! %s couldnt find %s\n' "${0}" "${CONFIG_FILE}" >>"${LOGFILE}"
exit 4
fi
source "${CONFIG_FILE}"
2022-09-10 16:42:02 -06:00
hostname="${1}"
username="${2}"
2022-09-10 16:38:11 -06:00
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}/" >>"${LOGFILE}"
exit 5
fi