adding ollama installer
This commit is contained in:
80
README.md
80
README.md
@@ -356,3 +356,83 @@ To add manually:
|
|||||||
sudo tmutil addexclusion ~/data/raw
|
sudo tmutil addexclusion ~/data/raw
|
||||||
sudo tmutil addexclusion ~/models
|
sudo tmutil addexclusion ~/models
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Ollama Bootstrap & Usage**
|
||||||
|
|
||||||
|
- **Bootstrap (macOS)**: Run the macOS installer/check + create model folders:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bash scripts/bootstrap_ollama_mac.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Bootstrap (Linux)**: Run the Linux helper (attempts to detect package manager and prepares model folders):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bash scripts/bootstrap_ollama_linux.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
- The scripts create the model directory referenced by the setup script as `OLLAMA_MODELS` (by default `$HOME/models/ollama`).
|
||||||
|
|
||||||
|
- Start the Ollama server inside a tmux session (helper functions):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Load helper functions (one-liner to source from dotfiles workspace)
|
||||||
|
source scripts/ollama_tmux.sh
|
||||||
|
|
||||||
|
# Start the server in a detached tmux session named 'ollama' (default command):
|
||||||
|
start_ollama_tmux
|
||||||
|
|
||||||
|
# To attach to the session:
|
||||||
|
tmux attach -t ollama
|
||||||
|
|
||||||
|
# To stop the server session:
|
||||||
|
stop_ollama_tmux
|
||||||
|
```
|
||||||
|
|
||||||
|
- Model management (two simple options):
|
||||||
|
|
||||||
|
- Pull a remote model (via the `ollama` CLI):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# example: pull a model by reference
|
||||||
|
pull_ollama_model <model-ref>
|
||||||
|
```
|
||||||
|
|
||||||
|
- Import or stage a local model into the $OLLAMA_MODELS path (creates a symlink):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
import_local_model /path/to/local/model-dir-or-file
|
||||||
|
# The helper will link it into the directory created by setup_enterprise_ai_bash.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
- Scripts referenced:
|
||||||
|
|
||||||
|
- [scripts/bootstrap_ollama_mac.sh](scripts/bootstrap_ollama_mac.sh)
|
||||||
|
- [scripts/bootstrap_ollama_linux.sh](scripts/bootstrap_ollama_linux.sh)
|
||||||
|
- [scripts/ollama_tmux.sh](scripts/ollama_tmux.sh)
|
||||||
|
|
||||||
|
- How to use Ollama from other AI applications:
|
||||||
|
|
||||||
|
- Run the server with `start_ollama_tmux` (above). By default the helper uses `ollama serve --host 127.0.0.1 --port 11434`.
|
||||||
|
- Many client apps can be pointed at the local Ollama HTTP API (default: `http://127.0.0.1:11434`). Check the Ollama docs for exact endpoints and payloads.
|
||||||
|
- Example using the `ollama` CLI to run a model directly from scripts or other programs:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Run a model locally (interactive / CLI). Replace <model> with the model name.
|
||||||
|
ollama run <model> --prompt "Write a short haiku about trees"
|
||||||
|
```
|
||||||
|
|
||||||
|
- Example (generic) using HTTP from another application (replace endpoint/payload per Ollama docs):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST "http://127.0.0.1:11434/api/generate" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"model":"<model>","prompt":"Hello from my app"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
- When integrating from other AI tooling, supply the Ollama host/port (e.g. `OLLAMA_URL=http://127.0.0.1:11434`) or call the `ollama` CLI directly from the application process.
|
||||||
|
|
||||||
|
If you want, I can also:
|
||||||
|
|
||||||
|
- Make the new scripts executable (`chmod +x`) automatically in the repo
|
||||||
|
- Attempt to detect the Ollama default model storage path and auto-configure a symlink
|
||||||
|
|||||||
40
scripts/bootstrap_ollama_linux.sh
Executable file
40
scripts/bootstrap_ollama_linux.sh
Executable file
@@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
echo "🔧 Ollama Linux bootstrap — starting"
|
||||||
|
|
||||||
|
# Load environment (MODEL_ROOT, OLLAMA_MODELS)
|
||||||
|
# Temporarily disable "nounset" when sourcing user shell files to avoid
|
||||||
|
# failures from system /etc/bashrc referencing undefined vars like PS1.
|
||||||
|
if [ -f "$HOME/.bashrc" ]; then
|
||||||
|
set +u
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
source "$HOME/.bashrc" || true
|
||||||
|
set -u
|
||||||
|
fi
|
||||||
|
|
||||||
|
: "${OLLAMA_MODELS:=$HOME/models/ollama}"
|
||||||
|
mkdir -p "$OLLAMA_MODELS"
|
||||||
|
|
||||||
|
if command -v ollama >/dev/null 2>&1; then
|
||||||
|
echo "✅ ollama already installed: $(ollama version 2>/dev/null || echo 'unknown')"
|
||||||
|
else
|
||||||
|
echo "ℹ️ Attempting to install ollama on Linux"
|
||||||
|
if command -v apt-get >/dev/null 2>&1; then
|
||||||
|
echo "Using apt to install prerequisites..."
|
||||||
|
sudo apt-get update -y || true
|
||||||
|
sudo apt-get install -y ca-certificates curl gnupg lsb-release || true
|
||||||
|
echo "⚠️ Please follow the official ollama Linux install instructions if a package is not available: https://ollama.com/docs/install"
|
||||||
|
echo "If you have a .deb from Ollama, install it with: sudo dpkg -i <file.deb>"
|
||||||
|
elif command -v dnf >/dev/null 2>&1; then
|
||||||
|
echo "Using dnf; please refer to Ollama docs for distro-specific instructions: https://ollama.com/docs/install"
|
||||||
|
else
|
||||||
|
echo "⚠️ Could not detect package manager. Please install ollama manually. See: https://ollama.com/docs/install"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "📁 Ensuring model directory exists: $OLLAMA_MODELS"
|
||||||
|
mkdir -p "$OLLAMA_MODELS"
|
||||||
|
|
||||||
|
echo "✅ Linux Ollama bootstrap complete."
|
||||||
|
echo "Next steps: run scripts/ollama_tmux.sh to start the server in tmux, and place models under $OLLAMA_MODELS"
|
||||||
41
scripts/bootstrap_ollama_mac.sh
Executable file
41
scripts/bootstrap_ollama_mac.sh
Executable file
@@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
echo "🔧 Ollama macOS bootstrap — starting"
|
||||||
|
|
||||||
|
# Load environment (MODEL_ROOT, OLLAMA_MODELS)
|
||||||
|
# Temporarily disable "nounset" when sourcing user shell files to avoid
|
||||||
|
# failures from system /etc/bashrc referencing undefined vars like PS1.
|
||||||
|
if [ -f "$HOME/.bashrc" ]; then
|
||||||
|
set +u
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
source "$HOME/.bashrc" || true
|
||||||
|
set -u
|
||||||
|
fi
|
||||||
|
|
||||||
|
: "${OLLAMA_MODELS:=$HOME/models/ollama}"
|
||||||
|
mkdir -p "$OLLAMA_MODELS"
|
||||||
|
|
||||||
|
if command -v ollama >/dev/null 2>&1; then
|
||||||
|
echo "✅ ollama already installed: $(ollama version 2>/dev/null || echo 'unknown')"
|
||||||
|
else
|
||||||
|
if command -v brew >/dev/null 2>&1; then
|
||||||
|
echo "🍺 Installing ollama via Homebrew..."
|
||||||
|
brew update || true
|
||||||
|
brew install ollama || {
|
||||||
|
echo "⚠️ Homebrew install failed. See https://ollama.com/docs/install"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
echo "✅ ollama installed"
|
||||||
|
else
|
||||||
|
echo "⚠️ Homebrew not found. Install Homebrew first: https://brew.sh"
|
||||||
|
echo "Then re-run this script: $0"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "📁 Ensuring model directory exists: $OLLAMA_MODELS"
|
||||||
|
mkdir -p "$OLLAMA_MODELS"
|
||||||
|
|
||||||
|
echo "✅ macOS Ollama bootstrap complete."
|
||||||
|
echo "Next steps: run scripts/ollama_tmux.sh to start the server in tmux, and place models under $OLLAMA_MODELS"
|
||||||
53
scripts/ollama_detect_and_link.sh
Executable file
53
scripts/ollama_detect_and_link.sh
Executable file
@@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
echo "🔍 Detecting Ollama model directories and linking into OLLAMA_MODELS"
|
||||||
|
|
||||||
|
# Load env if available
|
||||||
|
if [ -f "$HOME/.bashrc" ]; then
|
||||||
|
set +u
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
source "$HOME/.bashrc" || true
|
||||||
|
set -u
|
||||||
|
fi
|
||||||
|
|
||||||
|
OLLAMA_MODELS="${OLLAMA_MODELS:-$HOME/models/ollama}"
|
||||||
|
mkdir -p "$OLLAMA_MODELS"
|
||||||
|
|
||||||
|
candidates=(
|
||||||
|
"$HOME/.ollama/models"
|
||||||
|
"$HOME/.local/share/ollama/models"
|
||||||
|
"/var/lib/ollama/models"
|
||||||
|
"/usr/local/var/ollama/models"
|
||||||
|
"$HOME/.ollama"
|
||||||
|
)
|
||||||
|
|
||||||
|
linked=0
|
||||||
|
for cand in "${candidates[@]}"; do
|
||||||
|
if [ -d "$cand" ]; then
|
||||||
|
# skip empty directories
|
||||||
|
if [ -z "$(ls -A "$cand" 2>/dev/null)" ]; then
|
||||||
|
echo "ℹ️ Found $cand but it's empty — skipping"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
name=$(basename "$cand")
|
||||||
|
dest="$OLLAMA_MODELS/$name"
|
||||||
|
if [ -e "$dest" ]; then
|
||||||
|
echo "ℹ️ Destination exists: $dest — skipping"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
ln -sfn "$cand" "$dest"
|
||||||
|
echo "✅ Linked $cand → $dest"
|
||||||
|
linked=$((linked+1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $linked -eq 0 ]; then
|
||||||
|
echo "⚠️ No existing Ollama model directories detected in common locations."
|
||||||
|
echo "You can place models in: $OLLAMA_MODELS or run: pull_ollama_model <model-ref> (see scripts/ollama_tmux.sh)"
|
||||||
|
else
|
||||||
|
echo "🎉 Completed linking ($linked). Verify with: ls -la $OLLAMA_MODELS"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Done."
|
||||||
144
scripts/ollama_tmux.sh
Executable file
144
scripts/ollama_tmux.sh
Executable file
@@ -0,0 +1,144 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Ollama tmux helper and model utilities
|
||||||
|
# Source this file or call functions directly: source scripts/ollama_tmux.sh
|
||||||
|
|
||||||
|
# Ensure environment variables exist
|
||||||
|
if [ -f "$HOME/.bashrc" ]; then
|
||||||
|
set +u
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
source "$HOME/.bashrc" || true
|
||||||
|
set -u
|
||||||
|
fi
|
||||||
|
: "${OLLAMA_MODELS:=$HOME/models/ollama}"
|
||||||
|
|
||||||
|
start_ollama_tmux() {
|
||||||
|
session="ollama"
|
||||||
|
# Use provided command or sensible default. Ollama uses env vars (OLLAMA_HOST)
|
||||||
|
# Example: OLLAMA_HOST=0.0.0.0:11434 ollama serve
|
||||||
|
default_cmd="${OLLAMA_CMD:-ollama serve}"
|
||||||
|
cmd="${1:-$default_cmd}"
|
||||||
|
echo "Using command: $cmd"
|
||||||
|
if [ -n "${OLLAMA_HOST:-}" ]; then
|
||||||
|
echo "OLLAMA_HOST is set to: $OLLAMA_HOST"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v tmux >/dev/null 2>&1; then
|
||||||
|
echo "⚠️ tmux not installed. Install tmux and re-run."
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create models dir if needed
|
||||||
|
mkdir -p "$OLLAMA_MODELS"
|
||||||
|
|
||||||
|
if tmux has-session -t "$session" 2>/dev/null; then
|
||||||
|
echo "ℹ️ tmux session '$session' already running. Attach with: tmux attach -t $session"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "🔁 Starting ollama in tmux session '$session' with command: $cmd"
|
||||||
|
tmux new-session -d -s "$session" "$cmd"
|
||||||
|
sleep 0.5
|
||||||
|
if tmux has-session -t "$session" 2>/dev/null; then
|
||||||
|
echo "✅ Started. Attach: tmux attach -t $session"
|
||||||
|
else
|
||||||
|
echo "❌ Failed to start tmux session. Check logs or run the command directly: $cmd"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
pull_ollama_model() {
|
||||||
|
if [ "$#" -lt 1 ]; then
|
||||||
|
echo "Usage: pull_ollama_model <model-ref>"
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
if ! command -v ollama >/dev/null 2>&1; then
|
||||||
|
echo "⚠️ ollama CLI not found. Install first."
|
||||||
|
return 3
|
||||||
|
fi
|
||||||
|
model="$1"
|
||||||
|
echo "⬇️ Pulling model: $model"
|
||||||
|
ollama pull "$model"
|
||||||
|
}
|
||||||
|
|
||||||
|
import_local_model() {
|
||||||
|
if [ "$#" -lt 1 ]; then
|
||||||
|
echo "Usage: import_local_model <path-to-model-dir-or-file>"
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
src="$1"
|
||||||
|
if [ ! -e "$src" ]; then
|
||||||
|
echo "⚠️ Source not found: $src"
|
||||||
|
return 3
|
||||||
|
fi
|
||||||
|
mkdir -p "$OLLAMA_MODELS"
|
||||||
|
dest="$OLLAMA_MODELS/$(basename "$src")"
|
||||||
|
ln -sfn "$src" "$dest"
|
||||||
|
echo "🔗 Linked $src → $dest"
|
||||||
|
echo "Note: depending on your ollama installation you may need to reindex or use the ollama CLI to register the model."
|
||||||
|
}
|
||||||
|
|
||||||
|
stop_ollama_tmux() {
|
||||||
|
session="ollama"
|
||||||
|
if tmux has-session -t "$session" 2>/dev/null; then
|
||||||
|
tmux kill-session -t "$session"
|
||||||
|
echo "🛑 Stopped tmux session '$session'"
|
||||||
|
else
|
||||||
|
echo "ℹ️ No tmux session named '$session' running"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
print_usage() {
|
||||||
|
cat <<EOF
|
||||||
|
Usage: $(basename "$0") <command> [args]
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
start [<cmd>] Start ollama in tmux (optional command overrides default)
|
||||||
|
stop Stop the tmux session named 'ollama'
|
||||||
|
pull <model-ref> Pull a model using the ollama CLI
|
||||||
|
import <path> Import/link a local model directory/file into OLLAMA_MODELS
|
||||||
|
help Show this help
|
||||||
|
|
||||||
|
If you want to use these as shell functions, source this file instead:
|
||||||
|
source scripts/ollama_tmux.sh
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
|
||||||
|
# Script executed directly; provide a simple CLI wrapper
|
||||||
|
cmd="${1:-}"
|
||||||
|
case "$cmd" in
|
||||||
|
start)
|
||||||
|
# shift and pass remaining args as the command
|
||||||
|
shift || true
|
||||||
|
start_ollama_tmux "$@"
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
stop_ollama_tmux
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
pull)
|
||||||
|
shift || true
|
||||||
|
pull_ollama_model "$@"
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
import)
|
||||||
|
shift || true
|
||||||
|
import_local_model "$@"
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
help|--help|-h|"")
|
||||||
|
print_usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown command: $cmd"
|
||||||
|
print_usage
|
||||||
|
exit 2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
echo "Loaded ollama tmux helper. Functions: start_ollama_tmux, stop_ollama_tmux, pull_ollama_model, import_local_model"
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user