#!/bin/bash

# Ensure ~/.local/bin is on PATH
export PATH=$PATH:$HOME/.local/bin

# If cbdep isn't already installed, get uv and use it to install cbdep
if [ ! -x ~/.local/bin/cbdep ]; then

    # If uv isn't already installed, install it - use curl or wget
    if ! command -v uv 2>&1 >/dev/null; then
        if command -v curl 2>&1 >/dev/null; then
            curl -qLsSf https://astral.sh/uv/install.sh | INSTALLER_PRINT_QUIET=1 sh
        elif command -v wget 2>&1 >/dev/null; then
            wget -qO- https://astral.sh/uv/install.sh | INSTALLER_PRINT_QUIET=1 sh
        else
            echo "Either curl or wget is required to install cbdep"
            exit 1
        fi
    fi

    # Use uv to install cbdep
    uv tool install --quiet cbdep
fi

# Invoke cbdep
exec ~/.local/bin/cbdep "$@"
