#!/bin/bash
# List of domains
DOMAINS=(
"nebula.sandbox-dev.co.uk"
)
# Loop through each domain
for DOMAIN in "${DOMAINS[@]}"; do
  echo "Setting up $DOMAIN..."
  # Create document root
#  sudo mkdir -p /var/www/$DOMAIN
#  sudo chown -R $USER:$USER /var/www/$DOMAIN
  # Create Apache config file
  VHOST_FILE="/etc/apache2/sites-available/$DOMAIN.conf"
  sudo tee $VHOST_FILE > /dev/null <<EOF
<Directory /var/www/$DOMAIN>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
<VirtualHost *:80>
    ServerName $DOMAIN
    ServerAlias $DOMAIN
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/$DOMAIN
    ErrorLog \${APACHE_LOG_DIR}/$DOMAIN-error.log
    CustomLog \${APACHE_LOG_DIR}/$DOMAIN-access.log combined
</VirtualHost>
EOF
  # Enable the site
  sudo a2ensite $DOMAIN.conf
done
# Test Apache config
echo "Testing Apache configuration..."
sudo apache2ctl configtest
# Reload Apache
echo "Reloading Apache..."
sudo systemctl reload apache2
# Install SSL using Certbot
for DOMAIN in "${DOMAINS[@]}"; do
  echo "Requesting SSL certificate for $DOMAIN..."
  sudo certbot --apache -d $DOMAIN --non-interactive --agree-tos -m admin@$DOMAIN
done
# Reload Apache after SSL installation
sudo systemctl reload apache2
echo "✅ All sites configured with SSL!"
