#!/usr/bin/env bash set -euo pipefail script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) repo_dir=$(cd "$script_dir/.." && pwd) venv_dir="$repo_dir/.venv" launcher_dir="$HOME/.local/bin" launcher_link="$launcher_dir/cowork-local" launcher_target="$repo_dir/scripts/run_local.sh" if [[ -n "${COWORK_PYTHON:-}" ]]; then python_bin="$COWORK_PYTHON" elif command -v python3.11 >/dev/null 2>&1; then python_bin=$(command -v python3.11) else python_bin=$(command -v python3) fi "$python_bin" -c 'import sys; assert sys.version_info >= (3, 11), "Cowork Local requires Python 3.11+"' if [[ ! -x "$venv_dir/bin/python" ]]; then if command -v uv >/dev/null 2>&1; then uv venv --python "$python_bin" "$venv_dir" else "$python_bin" -m venv "$venv_dir" fi fi if command -v uv >/dev/null 2>&1; then uv pip install --python "$venv_dir/bin/python" \ -r "$repo_dir/requirements.txt" \ -r "$repo_dir/requirements-test.txt" else "$venv_dir/bin/python" -m pip install --disable-pip-version-check \ -r "$repo_dir/requirements.txt" \ -r "$repo_dir/requirements-test.txt" fi mkdir -p "$launcher_dir" if [[ ! -e "$launcher_link" && ! -L "$launcher_link" ]]; then ln -s "$launcher_target" "$launcher_link" echo "Installed launcher: $launcher_link" elif [[ -L "$launcher_link" && "$(readlink "$launcher_link")" == "$launcher_target" ]]; then echo "Launcher already installed: $launcher_link" else echo "Not replacing existing path: $launcher_link" >&2 echo "Run Cowork Local with: $launcher_target" >&2 fi echo "Cowork Local environment: $venv_dir" echo "Run: $launcher_target" echo "Or add $launcher_dir to PATH and run: cowork-local"