#!/bin/bash
# Shared path resolver for the Qwen-Image-Edit service scripts.
# Sourced by bootstrap.sh / run_comfyui.sh / start_api.sh.
#
# Why this exists: a Python venv CANNOT live on the NTFS (fuseblk) mount used
# on tour (/media/tour/APPS). Its interpreter symlinks turn into
# "unsupported reparse tag 0x..." after a reboot/remount, so `python`
# vanishes and every service dies. ComfyUI code and the model files are plain
# files and are fine on NTFS -- only the venv must be on a native fs.
#
# So: if BASE is on a non-native filesystem, the venv goes under $HOME (ext4);
# otherwise it stays at $BASE/venv. Override explicitly with COMFY_VENV.

ENV_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"   # .../comfyui/api
API_DIR="$ENV_DIR"
BASE="$( cd "$ENV_DIR/.." && pwd )"                           # .../comfyui
COMFY="$BASE/ComfyUI"

_basefs="$(stat -f -c %T "$BASE" 2>/dev/null || echo unknown)"
case "$_basefs" in
  fuseblk|ntfs|ntfs3|exfat|vfat|msdos|9p|cifs|smb*)
    VENV="${COMFY_VENV:-/home/mike/comfyui/venv}" ;;   # NTFS-ish BASE -> venv on home
  *)
    if [ -d "/home/mike/comfyui/venv" ]; then
        VENV="${COMFY_VENV:-/home/mike/comfyui/venv}"
    else
        VENV="${COMFY_VENV:-$BASE/venv}"
    fi
    ;;
esac
