#!/usr/bin/env bash
# 新本番 (tools.kachiumaai.com) の phpMyAdmin を有効化する。
# Web の Basic 認証は使わない（MariaDB ログインのみ）。
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONF="/etc/httpd/conf.d/phpMyAdmin.conf"
DISABLED="/etc/httpd/conf.d/phpMyAdmin.conf.disabled"
TEMPLATE="${SCRIPT_DIR}/phpMyAdmin.conf.no-web-gate"

if [[ ! -f "$TEMPLATE" ]]; then
  echo "missing template: $TEMPLATE" >&2
  exit 1
fi

install -m 0644 "$TEMPLATE" "$CONF"
rm -f "$DISABLED"

apachectl configtest
systemctl reload httpd

echo "enabled: $CONF (no web gate)"
echo "verify: curl -sI https://tools.kachiumaai.com/phpmyadmin/ | head -1"
curl -sI "https://tools.kachiumaai.com/phpmyadmin/" 2>/dev/null | head -1 || true
