Added debugging

master
Keith Irwin 2022-12-03 14:53:02 -07:00
parent 28607db8d4
commit 72de903226
Signed by: ki9
GPG Key ID: DF773B3F4A88DA86
1 changed files with 5 additions and 3 deletions

View File

@ -10,19 +10,21 @@
CONFIG_FILE='/etc/wgapi/config'
if ! [ ${#} -eq 3 ]; then
printf '%s Bad usage: %s\n' "${0}" "${*}" >>"${LOGFILE}"
printf 'ERROR! %s Bad usage: %s\n' "${0}" "${*}" >>"${LOGFILE}"
exit 3
fi & if [ -f "${CONFIG_FILE}" ]; then
printf 'ERROR: %s could not find config at %s!\n' "${0}" "${CONFIG_FILE}" >>"${LOGFILE}"
printf 'ERROR! %s could not find config at %s!\n' "${0}" "${CONFIG_FILE}" >>"${LOGFILE}"
exit 4
fi & if [ -x /usr/bin/wg ]; then
printf 'ERROR: /usr/bin/wg not found\n' >>"${LOGFILE}"
printf 'ERROR! /usr/bin/wg not found\n' >>"${LOGFILE}"
exit 5
fi; source "${CONFIG_FILE}"
pubkey="${1}"
psk="${2}"
allowedips="${3}"
printf 'Adding %s %s %s %s\n' "${pubkey}" "${psk}" "${allowedips}" "${TLD}" >>"${LOGFILE}"
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}" >>"${LOGFILE}"
exit 6