#!/usr/bin/env bash
# Sync backend code to BE sshfs mount (skip data/ — permissions).
# Usage: ./scripts/deploy-to-be-mount.sh [DEST]
set -euo pipefail
SRC="$(cd "$(dirname "$0")/.." && pwd)"
REPO_EXAMPLES="$(cd "$SRC/../.." && pwd)"
BE_ROOT="${BE_ROOT:-$(cd "$REPO_EXAMPLES/../../tmp/BE_alpine/var/www/localhost/htdocs/apps/app/androidcast_project/android_cast" 2>/dev/null && pwd || true)}"
DEST="${1:-$(cd "$SRC/../../../tmp/BE_alpine/var/www/localhost/htdocs/apps/app/androidcast_project/android_cast/examples/crash_reporter/backend" 2>/dev/null && pwd || true)}"
if [[ -z "$DEST" || ! -d "$DEST" ]]; then
  echo "DEST not found. Pass BE mount path as first argument." >&2
  exit 1
fi
rsync -a --no-group --no-owner \
  --exclude 'data/' --exclude 'config/config.php' \
  "$SRC/" "$DEST/"
if [[ -n "$BE_ROOT" && -d "$BE_ROOT" ]]; then
  rsync -a --no-group --no-owner \
    "$REPO_EXAMPLES/platform/" "$BE_ROOT/examples/platform/"
  echo "Synced platform/ to $BE_ROOT/examples/platform/"
fi
echo "Synced to $DEST (config.php and data/ untouched)."
