#!/bin/sh # Makes this Mac match the repo: Ollama's LaunchAgent, the derived models in # ollama/models, and opencode's config (symlinked, so edits land in the repo). # Safe to re-run. set -eu cd "$(dirname "$0")" repo=$(pwd) # Ollama server LaunchAgent. Only reloaded when it changed: reloading # restarts Ollama and unloads whatever models are in memory. plist=~/Library/LaunchAgents/com.ollama.server.plist if ! cmp -s ollama/com.ollama.server.plist "$plist"; then echo "Installing $plist" launchctl bootout "gui/$(id -u)" "$plist" 2>/dev/null || true cp ollama/com.ollama.server.plist "$plist" launchctl bootstrap "gui/$(id -u)" "$plist" until curl -fs localhost:11434/api/version >/dev/null; do sleep 1; done fi # Derived models: each Modelfile names its model on a "# name:" line. for f in ollama/models/*.Modelfile; do name=$(sed -n 's/^# name: *//p' "$f") base=$(sed -n 's/^FROM *//p' "$f") [ -n "$name" ] && [ -n "$base" ] || { echo "$f: needs '# name:' and FROM lines" >&2; exit 1; } ollama show "$base" >/dev/null 2>&1 || ollama pull "$base" echo "Creating $name from $f" ollama create "$name" -f "$f" >/dev/null done # ComfyUI (image generation for Open WebUI on the Tart VM), in ~/ComfyUI. comfy=~/ComfyUI comfy_tag=v0.39.2 gguf_rev=6ea2651e7df66d7585f6ffee804b20e92fb38b8a command -v uv >/dev/null || brew install uv [ -d "$comfy" ] || git clone -q --branch "$comfy_tag" --depth 1 https://github.com/comfyanonymous/ComfyUI "$comfy" [ -d "$comfy/custom_nodes/ComfyUI-GGUF" ] || { git clone -q https://github.com/city96/ComfyUI-GGUF "$comfy/custom_nodes/ComfyUI-GGUF" git -C "$comfy/custom_nodes/ComfyUI-GGUF" checkout -q "$gguf_rev" } [ -x "$comfy/.venv/bin/python" ] || { uv venv -q --python 3.12 "$comfy/.venv" uv pip install -q --python "$comfy/.venv/bin/python" \ -r "$comfy/requirements.txt" -r "$comfy/custom_nodes/ComfyUI-GGUF/requirements.txt" } grep -v '^#' comfyui/models.txt | while read -r dir hfrepo path; do [ -n "$dir" ] || continue out="$comfy/models/$dir/$(basename "$path")" [ -s "$out" ] && continue echo "Downloading $(basename "$path")" mkdir -p "$(dirname "$out")" curl -fL -C - -o "$out.part" "https://huggingface.co/$hfrepo/resolve/main/$path" && mv "$out.part" "$out" done # The server, and the job that unloads its models when idle. for name in com.comfyui.server com.comfyui.idle-unload; do plist=~/Library/LaunchAgents/$name.plist cmp -s "comfyui/$name.plist" "$plist" && continue echo "Installing $plist" launchctl bootout "gui/$(id -u)" "$plist" 2>/dev/null || true cp "comfyui/$name.plist" "$plist" launchctl bootstrap "gui/$(id -u)" "$plist" done # opencode mkdir -p ~/.config/opencode target=~/.config/opencode/opencode.json if [ -e "$target" ] && [ ! -L "$target" ]; then mv "$target" "$target.bak" echo "Moved the old $target to $target.bak" fi ln -sfn "$repo/opencode/opencode.json" "$target" echo "Linked $target"