#!/bin/sh
# At container start: use composer.lock.{74|83} for this PHP version, run composer install, then exec main process.
set -e
PHP_VER="${1:-}"
shift
cd /var/www/html
ENV_LOCAL=".env.local"
ENV_MAIN=".env"

# If a local override exists, copy it into .env buffer for this container
if [ -f "$ENV_LOCAL" ]; then
    cp "$ENV_LOCAL" "$ENV_MAIN"
fi

if [ -n "$PHP_VER" ] && [ -f "composer.lock.$PHP_VER" ]; then
    cp "composer.lock.$PHP_VER" composer.lock
fi
if [ -f "composer.json" ]; then
    composer install --no-interaction --prefer-dist
fi
exec "$@"
