#!/bin/bash #Script : ollama_up.sh #Apps : MRDEVS TOOLS #Description : Ejecutar ollama (IA) en modo local #Author : Mauro Rosero Pérez #Company Email : mauro@rosero.one #Personal Email : mauro.rosero@gmail.com #Created : 2025/03/21 19:27:08 #Modified : 2025/03/21 19:27:08 #Version : 1.3.0 #============================================================================== # Derechos de Autor [2025] [Mauro Rosero P. ] #============================================================================== # Este programa es software libre: usted puede redistribuirlo y/o modificarlo # bajo los términos de la Licencia Pública Affero General de GNU tal como # lo publica la Free Software Foundation, ya sea la versión 3 de la licencia, # o (a su elección) cualquier versión posterior. # # Este programa se distribuye con la esperanza de que sea útil, # pero SIN NINGUNA GARANTÍA; sin siquiera la garantía implícita de # COMERCIABILIDAD o IDONEIDAD PARA UN PROPÓSITO PARTICULAR. Consulte la # Licencia Pública Affero General de GNU para obtener más detalles. # # Debería haber recibido una copia de la Licencia Pública Affero General # junto con este programa. Si no la recibió, consulte . # Configuración inicial # Usar DEVELOPER_DIR de base.lib SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" BIN_BASE="bin" BIN_LIBS="lib" BIN_MESG="msg" BIN_CFGS="config" # Leer DEVSPATH desde el archivo de configuración o usar "devs" por defecto if [ -f "$SCRIPT_DIR/config/devspath.dat" ]; then DEVSPATH=$(cat "$SCRIPT_DIR/$BIN_CFGS/devspath.dat") else DEVSPATH="devs" fi BIN_HOME="$HOME/$DEVSPATH" BIN_PATH=$BIN_HOME/$BIN_BASE VERSION=$(cat "$BIN_HOME/$BIN_BASE/$BIN_CFGS/version") # CHECK SHELL LANGUAGE BIN_LANG=${LANG:0:2} set -e # Importar bibliotecas necesarias source "${BIN_HOME}/${BIN_BASE}/${BIN_LIBS}/base.lib" # Cargar mensajes en el idioma del sistema o español por defecto load_messages "${BIN_HOME}/${BIN_BASE}" "${BIN_MESG}" "${BIN_LANG}" "head" title="${head_000} ${head_002}" # Create the directory for Ollama in the development directory mkdir -p "${BIN_HOME}/ollama" # Check if we should use podman or docker (prefer podman) if command -v podman >/dev/null 2>&1; then CONTAINER_CMD="podman" elif command -v docker >/dev/null 2>&1; then CONTAINER_CMD="docker" else echo "Error: Neither podman nor docker is installed" exit 1 fi # Check if compose command exists if command -v ${CONTAINER_CMD}-compose >/dev/null 2>&1; then COMPOSE_CMD="${CONTAINER_CMD}-compose" elif command -v podman-compose >/dev/null 2>&1; then COMPOSE_CMD="podman-compose" elif command -v docker-compose >/dev/null 2>&1; then COMPOSE_CMD="docker-compose" else echo "Error: No compose command found (podman-compose or docker-compose)" exit 1 fi echo "Using ${COMPOSE_CMD} to start Ollama service..." # Copy compose file if it doesn't exist in the new location if [ ! -f "${BIN_HOME}/ollama/podman-compose.yml" ] && [ -f "${BIN_HOME}/${BIN_BASE}/ollama/podman-compose.yml" ]; then cp "${BIN_HOME}/${BIN_BASE}/ollama/podman-compose.yml" "${BIN_HOME}/ollama/" fi # Change to the directory containing the compose file cd "${BIN_HOME}/ollama" # Create a subdirectory for Ollama data mkdir -p "${BIN_HOME}/ollama/data" # Update the compose file to use ollama/data directory if [ -f "${BIN_HOME}/ollama/podman-compose.yml" ]; then # Update the volume mount to use ollama/data instead of data sed -i 's|../../data:/root/.ollama|../ollama/data:/root/.ollama|g' "${BIN_HOME}/ollama/podman-compose.yml" sed -i 's|${BIN_HOME}/data:/root/.ollama|${BIN_HOME}/ollama/data:/root/.ollama|g' "${BIN_HOME}/ollama/podman-compose.yml" # Start Ollama service with compose ${COMPOSE_CMD} -f podman-compose.yml up -d else # Create a basic compose file if none exists cat > "${BIN_HOME}/ollama/podman-compose.yml" </dev/null || ! ${CONTAINER_CMD} ps | grep -q ollama; then echo "Warning: Container may not be running properly. Trying direct container command..." # Try to start it directly if it exists if ${CONTAINER_CMD} container exists ollama 2>/dev/null; then echo "Starting existing ollama container..." ${CONTAINER_CMD} start ollama else echo "Creating ollama container directly..." ${CONTAINER_CMD} run -d --name ollama \ --privileged \ -p 11434:11434 \ -v "${BIN_HOME}/ollama/data:/root/.ollama" \ --restart unless-stopped \ docker.io/ollama/ollama:latest fi fi echo "${head_002} Ollama service started successfully"