#!/usr/bin/env bash set -euo pipefail APP_SOURCE=${APP_SOURCE:-/opt/app} APP_TARGET=${APP_TARGET:-/var/www/html} APP_USER=${APP_USER:-www-data} APP_GROUP=${APP_GROUP:-www-data} SKIP_CODE_SYNC=${SKIP_CODE_SYNC:-0} sync_code() { if [[ "$SKIP_CODE_SYNC" == "1" ]]; then return fi if [[ ! -d "$APP_TARGET" ]]; then mkdir -p "$APP_TARGET" fi rsync -a --delete --omit-dir-times --no-perms --no-owner --no-group \ --exclude="storage/logs" \ --exclude="storage/framework/sessions" \ "$APP_SOURCE"/ "$APP_TARGET"/ || true chown -R "$APP_USER:$APP_GROUP" "$APP_TARGET" } ensure_helper_scripts() { if compgen -G "$APP_TARGET/docs/queue-supervisor/*.sh" > /dev/null; then chmod +x "$APP_TARGET"/docs/queue-supervisor/*.sh || true fi } prepare_storage() { cd "$APP_TARGET" if [[ ! -h public/storage ]]; then php artisan storage:link >/dev/null 2>&1 || true fi if [[ -n "${PENDING_MIGRATIONS:-}" ]]; then php artisan migrate --force >/dev/null 2>&1 || true fi } sync_code ensure_helper_scripts prepare_storage cd "$APP_TARGET" exec "$@"