#!/usr/bin/env bash
# /opt/retropie/configs → projects/retropie/configs 동기화 (백업용)
set -euo pipefail

SRC=/opt/retropie/configs
DST="$(cd "$(dirname "$0")/.." && pwd)/configs"

mkdir -p "$DST"

rsync -av --delete \
  --exclude 'content_*history*' \
  --exclude 'es_log.txt*' \
  --exclude 'es_temporaryinput.cfg' \
  --exclude 'skyscraper/' \
  --exclude 'gamelists/' \
  --exclude 'retroarch/assets/' \
  --exclude 'retroarch/shaders/' \
  --exclude 'retroarch/cores/' \
  --exclude 'retroarch/database/' \
  --exclude 'retroarch/downloads/' \
  --exclude 'retroarch/logs/' \
  --exclude 'retroarch/screenshots/' \
  --exclude 'retroarch/thumbnails/' \
  --exclude 'retroarch/playlists/' \
  --exclude 'retroarch/records/' \
  --exclude 'retroarch/records_config/' \
  --exclude 'retroarch/filters/' \
  --exclude 'retroarch/cheats/' \
  --exclude 'retroarch/overlay/' \
  --exclude 'retroarch/overlays/' \
  --exclude 'amiga/amiberry/whdboot/' \
  --exclude 'amiga/amiberry/nvram/' \
  --exclude 'amiga/amiberry/savestates/' \
  --exclude 'amiga/amiberry/screenshots/' \
  --exclude 'dreamcast/data/' \
  --exclude 'psp/PSP/' \
  --exclude 'msx/openmsx/share/systemroms/' \
  --exclude 'apple2/Master.dsk' \
  --exclude 'retroarch-joypads' \
  --exclude 'mame-advmame/rom/' \
  --exclude 'mame-advmame/snap/' \
  --exclude '*.bak*' \
  --exclude '.git/' \
  "$SRC/" "$DST/"

echo "Synced → $DST"
find "$DST" -type f | wc -l | xargs -I{} echo "{} files"
