#!/bin/bash

## Initialize var (project)
test -v HOST_UID \
    && cd "/var/project/" \
    && mkdir -p vendor/ \
    && setfacl -dR -m u:www-data:rwX -m u:$HOST_UID:rwX ./  \
    && setfacl -R -m u:www-data:rwX -m u:$HOST_UID:rwX ./

## Initialize environment variables
echo '#!/bin/bash' > /etc/profile.d/zz-00-env.sh \
  && declare -p | grep -Ev 'BASHOPTS|BASH_VERSINFO|EUID|PPID|SHELLOPTS|UID' >> /etc/profile.d/zz-00-env.sh;

# Fix crontab ownership when mounted from host
if [ -f /etc/crontabs/root ]; then
    chown root:root /etc/crontabs/root
    chmod 600 /etc/crontabs/root
fi

{ test -v SUPERVISORD_ENABLED && [ "$SUPERVISORD_ENABLED" == 1 ]; } && /usr/bin/supervisord || /usr/local/sbin/php-fpm;
