# pode ser criado um arquivo .sh separado, ou ser invocado como 
# comandos diretamente no terminal
# ===============================================
#!/bin/bash
CONF_FILE="/opt/IBMHTTPServer90/conf/httpd_unipass.conf"

# 1. Extrair DocumentRoot (remove aspas se houver)
DOC_ROOT=$(grep -i "DocumentRoot" "$CONF_FILE" | head -n1 | sed -E 's/DocumentRoot\s+"?([^"]+)"?/\1/')
if [ -z "$DOC_ROOT" ]; then
  echo "DocumentRoot não encontrado!"
  exit 1
fi
echo "DocumentRoot encontrado: $DOC_ROOT"
INDEX_HTML="$DOC_ROOT/index.html"
INDEX_JSP="$DOC_ROOT/index.jsp"
if [ ! -f "$INDEX_HTML" ]; then
  echo "index.html não encontrado em $DOC_ROOT"
  exit 1
fi

# 2. Obter epoch atual
EPOCH=$(date +%s)
echo "Gerando index.jsp com header x-unipass-jsp=$EPOCH"

# 3. Criar index.jsp
cat <<EOF > "$INDEX_JSP"
<%
response.setHeader("x-unipass-jsp", "$EPOCH");
%>
$(cat "$INDEX_HTML")
EOF
echo "index.jsp criado em: $INDEX_JSP"
