#!/bin/sh
set -e

# Named volumes (storage/framework, bootstrap/cache) start empty, so make sure
# Laravel's runtime directories exist before php-fpm boots.
mkdir -p \
    /var/www/html/storage/framework/cache/data \
    /var/www/html/storage/framework/sessions \
    /var/www/html/storage/framework/testing/views \
    /var/www/html/storage/framework/views \
    /var/www/html/storage/logs \
    /var/www/html/bootstrap/cache 2>/dev/null || true

# On Windows / Docker Desktop bind mounts the project files are owned by root
# while php-fpm runs as www-data. Make Laravel's runtime directories writable
# so Blade compilation, logs, cache and sessions work on a fresh clone.
if [ -d /var/www/html/storage ]; then
    chmod -R 777 /var/www/html/storage /var/www/html/bootstrap/cache 2>/dev/null || true
fi

exec "$@"
