#!/usr/bin/env bash
# Unified pull — EtherGold fixture + DyzineFrame when ~/EtherGold/sync is present.
# Falls back to DyzineFrame-only staging when bench Pi has no EtherGold sync tree.
#
# Manual one-shot (stage only):
#   bash pull_from_dropbox.sh
#   PROMOTE_NOW=1 bash pull_from_dropbox.sh   # bench: promote immediately

if grep -q $'\r' "${BASH_SOURCE[0]}" 2>/dev/null; then
  sed -i 's/\r$//' "${BASH_SOURCE[0]}"
  exec bash "${BASH_SOURCE[0]}" "$@"
fi

set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
EG_SYNC="${ETHERGOLD_SYNC:-${HOME}/EtherGold/sync}"

if [[ -f "${EG_SYNC}/pull_all_from_dropbox.sh" ]]; then
  exec bash "${EG_SYNC}/pull_all_from_dropbox.sh" "$@"
fi

echo "pull_from_dropbox: no ${EG_SYNC}/pull_all_from_dropbox.sh — DyzineFrame only"
exec bash "${ROOT}/pull_dyzineframe_from_dropbox.sh" "$@"
