#!/bin/sh
set -e

cd /var/www/html

mkdir -p storage/framework/{cache,sessions,views} storage/logs bootstrap/cache
chown -R www-data:www-data storage bootstrap/cache

if [ "${AUTORUN_ENABLED:-false}" = "true" ]; then
    echo "[entrypoint] AUTORUN_ENABLED=true, menjalankan setup boot..."

    php artisan config:clear

    if [ ! -L public/storage ]; then
        php artisan storage:link
    fi

    php artisan migrate --force

    php artisan config:cache
    php artisan route:cache
    php artisan view:cache
    php artisan event:cache

    echo "[entrypoint] Setup boot selesai."
fi

exec "$@"
