#!/bin/bash

# To use this file add the following to your composer.json:
#
#    "scripts": {
#        "post-install-cmd": [
#            "bash post-install.sh"
#        ]
#    }

SCRIPTPATH=$( cd $(dirname $0) ; pwd -P )

if [ ! -d $SCRIPTPATH/web/sites/default/files ]
then
  echo "Create $SCRIPTPATH/web/sites/default/files folder"
  mkdir $SCRIPTPATH/web/sites/default/files
  chmod 777 $SCRIPTPATH/web/sites/default/files
fi

if [ ! -d $SCRIPTPATH/web/profiles/abbey_lodge_profile ]
then
  echo "Create symlink to abbey_lodge_profile"
  cd $SCRIPTPATH/web/profiles
  ln -s ../../src/abbey_lodge_profile ./
fi

if [ ! -f $SCRIPTPATH/web/sites/default/settings.php ]
then
  echo "Create symlink to settings.php"
  cd $SCRIPTPATH/web/sites/default
  ln -s ../../../config/settings.php ./
fi

if [ ! -f $SCRIPTPATH/config/local.settings.php ]
then
  echo "Create $SCRIPTPATH/config/local.settings.php from $SCRIPTPATH/config/drupal-vm.settings.php"
  cp $SCRIPTPATH/config/drupal-vm.settings.php $SCRIPTPATH/config/local.settings.php
fi

if grep -q "www-data" /etc/group
then
  chown -R www-data:www-data $SCRIPTPATH/web
  chown -R www-data:www-data $SCRIPTPATH/config/local.settings.php
fi
