#!/usr/bin/env bash
# web/nginx-test -- configuration test with a readable verdict
set -o pipefail
SELF=$(readlink -f "${BASH_SOURCE[0]}")
NV_BASE=$(cd "$(dirname "$SELF")/../../.." && pwd)
export NV_BASE
# shellcheck source=/dev/null
. "$NV_BASE/lib/core/bootstrap.sh"

ui_header "$(t mod_web_nginxtest)"
out=$(nginx -t 2>&1)
if printf '%s' "$out" | grep -qi 'successful'; then
    ui_ok "$(printf '%s' "$out" | tail -n 1)"
else
    ui_err "$(t nginx_test_failed)"
    printf '%s\n' "$out" | sed 's/^/    /'
    nv_log error 2201 "nginx -t failed: $(printf '%s' "$out" | head -n 1)"
fi
ui_kv "$(t col_domain)" "$(nv_site_count)"
ui_blank
exit 0
