#!/bin/bash
# Generate Grav config and pages for all sites

declare -A SITES=(
    ["charters.turnsys.com"]="TSYS Group Charters"
    ["plan.afabn.org"]="AFABN Business Plan"
    ["plan.ap4ap.org"]="AP4AP Business Plan"
    ["plan.ezeda.org"]="EzEDA Business Plan"
    ["plan.ezpodstack.org"]="EzPodStack Business Plan"
    ["plan.hfnoc.net"]="High Flight NOC Business Plan"
    ["plan.knownelement.com"]="Known Element Business Plan"
    ["plan.meetmorse.com"]="MeetMorse Business Plan"
    ["plan.merchantsofhope.org"]="Merchants of Hope Business Plan"
    ["plan.rackrental.net"]="RackRental Business Plan"
    ["plan.redwfo.com"]="Redwood Family Office Business Plan"
    ["plan.rwscp.net"]="RWSCP Business Plan"
    ["plan.sidedoorgroup.org"]="Side Door Group Business Plan"
    ["plan.sol-calc.com"]="Sol-Calc Business Plan"
    ["plan.suborbital-systems.com"]="Suborbital Systems Business Plan"
    ["plan.teamrental.net"]="TeamRental Business Plan"
    ["plan.thecampustradingcompany.com"]="Campus Trading Company Business Plan"
    ["plan.thepeernet.com"]="The Peer Network Business Plan"
    ["plan.turnsys.com"]="TSYS Business Plan"
    ["plan.yourdreamnamehere.com"]="Your Dream Name Here Business Plan"
    ["plan.startinglineproductions.com"]="Starting Line Productions Business Plan"
    ["staticsites.turnsys.com"]="TSYS Static Sites"
)

BASE="/var/www/html/user/env"

for FQDN in "${!SITES[@]}"; do
    TITLE="${SITES[$FQDN]}"
    SITE_PATH="$BASE/$FQDN"

    # Create system.yaml
    cat > "$SITE_PATH/config/system.yaml" << EOF
absolute_urls: true
home:
  alias: '/home'
pages:
  theme: quark
  markdown:
    extra: true
  process:
    markdown: true
    twig: false
cache:
  enabled: true
  check:
    method: file
  driver: auto
  prefix: 'g'
EOF

    # Create site.yaml
    cat > "$SITE_PATH/config/site.yaml" << EOF
title: '$TITLE'
author:
  name: 'TSYS Group'
  email: 'admin@turnsys.com'
taxonomies: [category, tag]
metadata:
  description: '$TITLE'
EOF

    # Create home page
    mkdir -p "$SITE_PATH/pages/01.home"
    cat > "$SITE_PATH/pages/01.home/default.md" << EOF
---
title: '$TITLE'
---

## $TITLE

This site is powered by Grav CMS.

Content migrated from mdbook coming soon...
EOF

    echo "Configured: $FQDN"
done

chown -R www-data:www-data "$BASE"
echo "All sites configured."
