#!/bin/sh # cad-to-bom's installer for macOS and Linux: # # curl -fsSL https://cadtobom.dev/install.sh | sh # # It makes sure uv is here (installing it with uv's own installer when it is not), installs or upgrades the # cad-to-bom command as a uv tool, and puts the cad-to-bom skill into each agent app it finds on this computer. # Run it again to update both. It takes no options. Everything happens inside main, called on the last line, so a # download cut short runs nothing. set -eu SKILL_URL="${CAD_TO_BOM_SKILL_URL:-https://cadtobom.dev/skill/SKILL.md}" # the override is for tests UV_INSTALLER="https://astral.sh/uv/install.sh" say() { printf '%s\n' "$*" >&2; } die() { say "error: $*"; exit 1; } download() { if command -v curl >/dev/null 2>&1; then curl -fsSL "$1" -o "$2" elif command -v wget >/dev/null 2>&1; then wget -qO "$2" "$1" else die "neither curl nor wget is here to download with" fi } # uv: on PATH, else where uv's installer puts it before a new shell has it on PATH. find_uv() { if command -v uv >/dev/null 2>&1; then command -v uv; return 0; fi for dir in "${UV_INSTALL_DIR:-}" "${XDG_BIN_HOME:-}" "$HOME/.local/bin" "$HOME/.cargo/bin"; do if [ -n "$dir" ] && [ -x "$dir/uv" ]; then printf '%s\n' "$dir/uv"; return 0; fi done return 1 } # The skill goes into each agent app whose folder is here: Claude Code, Codex, and the shared ~/.agents folder # that several other agents read. install_skill() { file="$1"; put="" for base in "${CLAUDE_CONFIG_DIR:-$HOME/.claude}" "${CODEX_HOME:-$HOME/.codex}" "$HOME/.agents"; do [ -d "$base" ] || continue mkdir -p "$base/skills/cad-to-bom" cp "$file" "$base/skills/cad-to-bom/SKILL.md" put="$put $base/skills/cad-to-bom" done if [ -n "$put" ]; then for p in $put; do say "Skill installed: $p"; done else mkdir -p "$HOME/.agents/skills/cad-to-bom" cp "$file" "$HOME/.agents/skills/cad-to-bom/SKILL.md" say "No agent app found; skill saved to $HOME/.agents/skills/cad-to-bom. Copy it into your agent's skills folder." fi } main() { scratch=$(mktemp -d) trap 'rm -rf "$scratch"' EXIT INT TERM if ! uv=$(find_uv); then say "Installing uv (https://docs.astral.sh/uv/)..." download "$UV_INSTALLER" "$scratch/uv-install.sh" UV_NO_MODIFY_PATH="${UV_NO_MODIFY_PATH:-}" sh "$scratch/uv-install.sh" >&2 || die "uv could not be installed" uv=$(find_uv) || die "uv was installed but could not be found; open a new shell and run this again" fi say "Installing cad-to-bom..." "$uv" tool install --upgrade --python '>=3.11' cad-to-bom >&2 || die "uv could not install cad-to-bom" if download "$SKILL_URL" "$scratch/SKILL.md"; then install_skill "$scratch/SKILL.md" else say "warning: the agent skill could not be downloaded; cad-to-bom itself is installed" fi bin=$("$uv" tool dir --bin 2>/dev/null || printf '%s' "$HOME/.local/bin") if ! command -v cad-to-bom >/dev/null 2>&1; then say "" say "cad-to-bom is in $bin, which is not on your PATH yet. Run \`$uv tool update-shell\` or open a new shell." fi say "" say "Done. Ask your agent for a BOM, or run: cad-to-bom init my-project && cad-to-bom serve -c my-project --open" say "To remove it: uv tool uninstall cad-to-bom, and delete the skills/cad-to-bom folders listed above." } main "$@"