#!/usr/bin/env bash # Install Ollama and its Linux prerequisites for Hermes-Ollama_Models. set -Eeuo pipefail if [[ "$(uname -s)" != "Linux" ]]; then printf '%s\n' 'Automatic Ollama installation is currently supported on Linux only.' >&2 exit 1 fi is_container() { if [[ -f /.dockerenv ]]; then return 0 fi [[ -f /run/.containerenv ]] } ollama_endpoints() { if [[ -n "${OLLAMA_HOST:-}" ]]; then printf '%s\n' "${OLLAMA_HOST%/}" elif is_container; then printf '%s\n' 'http://ollama:11434' 'http://host.docker.internal:11434' else printf '%s\n' 'http://localhost:11434' fi } check_endpoint() { command -v curl >/dev/null 2>&1 || return 1 while IFS= read -r endpoint; do if curl --fail --silent --show-error --max-time 5 "${endpoint}/api/version" >/dev/null; then return 0 fi done < <(ollama_endpoints) return 1 } if [[ "${1:-}" == "--check" ]]; then if command -v ollama >/dev/null 2>&1 && ! is_container; then ollama --version >/dev/null exit 0 fi check_endpoint exit $? fi if is_container; then if check_endpoint; then exit 0 fi printf '%s\n' 'Docker/container runtime detected. Configure OLLAMA_HOST to a reachable Ollama service (for example http://ollama:11434 or http://host.docker.internal:11434); Hermes will not install Ollama inside its own container.' >&2 exit 1 fi if command -v ollama >/dev/null 2>&1; then ollama --version >/dev/null exit 0 fi if [[ "${EUID}" -ne 0 ]]; then printf '%s\n' 'Ollama installation requires the Hermes container to run as root.' >&2 exit 1 fi run_privileged() { "$@" } if ! command -v curl >/dev/null 2>&1; then if command -v apt-get >/dev/null 2>&1; then run_privileged apt-get update run_privileged apt-get install -y curl ca-certificates elif command -v dnf >/dev/null 2>&1; then run_privileged dnf install -y curl ca-certificates elif command -v yum >/dev/null 2>&1; then run_privileged yum install -y curl ca-certificates elif command -v pacman >/dev/null 2>&1; then run_privileged pacman -Sy --noconfirm curl ca-certificates else printf '%s\n' 'Could not find a supported package manager to install curl and ca-certificates.' >&2 exit 1 fi fi installer="$(mktemp)" trap 'rm -f "$installer"' EXIT curl --fail --silent --show-error --location https://ollama.com/install.sh --output "$installer" run_privileged sh "$installer" command -v ollama >/dev/null 2>&1 ollama --version >/dev/null