#!/bin/bash
# Step 03: Install reTerminal DM drivers (Seeed device-tree overlays)

step_03_reterminal_drivers() {
  if [[ -z "$RETERMINAL_REPO_URL" ]]; then
    log "Skipping reTerminal drivers (RETERMINAL_REPO_URL not set)"
    return 0
  fi
  local repo="/tmp/seeed-linux-dtoverlays"
  log "Cloning seeed-linux-dtoverlays ..."
  git clone --depth 1 "$RETERMINAL_REPO_URL" "$repo"
  log "Running reTerminal.sh --device $RETERMINAL_DEVICE ..."
  if ( cd "$repo" && "$repo/scripts/reTerminal.sh" --device "$RETERMINAL_DEVICE" ); then
    log "reTerminal DM drivers installed (reboot will apply)"
  else
    log "WARNING: reTerminal.sh failed; display/touch may still work"
  fi
  rm -rf "$repo"
}
