#!/bin/bash set -e echo "=========================================" echo " TerManager2 - Entrypoint" echo "=========================================" # ----------------------------------------------- # 0. Fix permissions & git safe directory # ----------------------------------------------- git config --global --add safe.directory /var/www/html chown -R appuser:appuser /var/www/html/storage /var/www/html/bootstrap/cache # ----------------------------------------------- # 1. Composer install # ----------------------------------------------- if [ ! -f vendor/autoload.php ]; then echo "[*] Installing Composer dependencies..." composer install --no-interaction --optimize-autoloader else echo "[✓] Composer dependencies already installed." fi # ----------------------------------------------- # 2. .env file # ----------------------------------------------- if [ ! -f .env ]; then echo "[*] Creating .env from .env.example..." cp .env.example .env else echo "[✓] .env file already exists." fi # ----------------------------------------------- # 3. Application key # ----------------------------------------------- if grep -q "^APP_KEY=$" .env; then echo "[*] Generating application key..." php artisan key:generate --ansi else echo "[✓] Application key already set." fi # ----------------------------------------------- # 4. NPM install & build assets # ----------------------------------------------- if [ ! -d node_modules ]; then echo "[*] Installing NPM dependencies..." npm ci else echo "[✓] NPM dependencies already installed." fi if [ ! -d public/build ]; then echo "[*] Building frontend assets..." npm run build else echo "[✓] Frontend assets already built." fi # ----------------------------------------------- # 5. Storage link # ----------------------------------------------- if [ ! -L public/storage ]; then echo "[*] Creating storage symlink..." php artisan storage:link else echo "[✓] Storage symlink already exists." fi # ----------------------------------------------- # 6. Create required storage directories # ----------------------------------------------- mkdir -p storage/framework/{cache,sessions,views} mkdir -p storage/logs mkdir -p bootstrap/cache # ----------------------------------------------- # 7. Run migrations # ----------------------------------------------- echo "[*] Running database migrations..." php artisan migrate --force # ----------------------------------------------- # 8. Cache config/routes/views # ----------------------------------------------- echo "[*] Caching configuration..." php artisan config:cache php artisan route:cache php artisan view:cache echo "=========================================" echo " TerManager2 - Ready!" echo "=========================================" # ----------------------------------------------- # Fix final ownership # ----------------------------------------------- chown -R appuser:appuser /var/www/html/vendor /var/www/html/node_modules /var/www/html/public/build /var/www/html/storage /var/www/html/bootstrap/cache 2>/dev/null || true # ----------------------------------------------- # Execute CMD (default: php-fpm) # ----------------------------------------------- exec "$@"