#!/bin/bash
# ===========================================================================
# Copyright (c) 2021 Eclipse Foundation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
#    Christopher Guindon (Eclipse Foundation)
# ==========================================================================

# Print the PHP version
php --version

# Build the website and copy settings
drush make /home/devops/build/drupal.make . --working-copy --force-gitinfofile --prepare-install
cp /home/devops/build/settings.php /var/www/html/sites/default/settings.php
cp /home/devops/php/configs/shared-settings.php /var/www/html/sites/default/shared-settings.php

# Copy the accounts.eclipse.org setting file if it's there
if [[ -f "/home/devops/build/settings-accounts.php" ]]
then
  mkdir -p /var/www/html/sites/accounts.eclipse.dev.docker
  cp /home/devops/build/settings-accounts.php /var/www/html/sites/accounts.eclipse.dev.docker/settings.php
fi

# Copy the sites.php file if it's there
if [[ -f "/home/devops/build/sites.php" ]]
then
  cp /home/devops/build/sites.php /var/www/html/sites/sites.php
fi

# Setting lose permission to allow file edit on host
chown -R 1000:33 /var/www/html /localsite /home
chmod -R g+w /var/www/html /localsite /home