ollama_ai_install/00-new2.sh

137 lines
3.7 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
set -euo pipefail
### CONFIG ###
OPENWEBUI_IMAGE="ghcr.io/open-webui/open-webui:main"
### /CONFIG ###
echo "=== Step 2: Install Docker, Ollama, and Open WebUI ==="
if [[ $EUID -ne 0 ]]; then
echo "Please run this script as root, e.g.: sudo bash $0"
exit 1
fi
# Figure out the "real" user so we put Open WebUI in their home
REALUSER="${SUDO_USER:-$USER}"
USER_HOME="$(eval echo ~${REALUSER})"
OPENWEBUI_DIR="${USER_HOME}/open-webui"
echo "Real user: ${REALUSER}"
echo "User home: ${USER_HOME}"
echo "Open WebUI directory: ${OPENWEBUI_DIR}"
echo
# --- Sanity check: GPU must be visible now ---
if ! command -v nvidia-smi >/dev/null 2>&1; then
echo "WARNING: nvidia-smi not found."
echo "Make sure you ran 00-gpu-driver.sh and rebooted successfully."
echo "You can still continue, but GPU usage may not work."
else
echo "nvidia-smi output:"
nvidia-smi || true
fi
echo
echo "Step 1/3: Installing Docker Engine + Docker Compose..."
# Remove old Docker bits if present (ignore errors)
apt-get remove -y docker docker-engine docker.io containerd runc || true
# Add Dockers official GPG key
install -m 0755 -d /etc/apt/keyrings
if [ ! -f /etc/apt/keyrings/docker.gpg ]; then
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
fi
# Add Docker apt repository
UBUNTU_CODENAME="$(. /etc/os-release && echo "$VERSION_CODENAME")"
if [ ! -f /etc/apt/sources.list.d/docker.list ]; then
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
${UBUNTU_CODENAME} stable" > /etc/apt/sources.list.d/docker.list
fi
apt-get update -y
apt-get install -y \
docker-ce \
docker-ce-cli \
containerd.io \
docker-buildx-plugin \
docker-compose-plugin
systemctl enable --now docker
echo "Docker version:"
docker --version || true
echo "Docker Compose plugin version:"
docker compose version || true
echo
echo "Step 2/3: Installing Ollama (GPU-enabled)..."
# Let Ollama's installer run even if its CUDA driver step fails
set +e
curl -fsSL https://ollama.com/install.sh | sh
OLLAMA_RC=$?
set -e
if [ $OLLAMA_RC -ne 0 ]; then
echo "WARNING: Ollama installer returned non-zero (likely CUDA driver conflicts)."
echo "As long as you have a working NVIDIA driver (nvidia-smi works), you can ignore this."
fi
# Make sure the service is enabled & running
systemctl enable --now ollama || true
echo "Waiting for Ollama API on http://127.0.0.1:11434 ..."
for i in {1..30}; do
if curl -sSf http://127.0.0.1:11434/api/version >/dev/null 2>&1; then
echo "Ollama is up!"
break
fi
sleep 2
done
if ! curl -sSf http://127.0.0.1:11434/api/version >/dev/null 2>&1; then
echo "WARNING: Ollama API not responding yet. Check 'systemctl status ollama'."
fi
echo
echo "Step 3/3: Setting up Open WebUI with Docker Compose..."
mkdir -p "${OPENWEBUI_DIR}"
cd "${OPENWEBUI_DIR}"
cat > docker-compose.yml <<'EOF'
version: "3.8"
services:
open-webui:
image: ghcr.io/open-webui/open-webui:main
container_name: open-webui
restart: unless-stopped
network_mode: "host"
environment:
- OLLAMA_BASE_URL=http://127.0.0.1:11434
# Uncomment to disable auth (optional, not recommended on exposed hosts)
# - OPENWEBUI_AUTH=False
volumes:
- ./data:/app/backend/data
EOF
echo "docker-compose.yml created at ${OPENWEBUI_DIR}/docker-compose.yml"
docker compose up -d
echo
echo "==================== DONE ===================="
echo "Ollama service: systemctl status ollama"
echo "Open WebUI stack: cd ${OPENWEBUI_DIR} && docker compose ps"
echo
echo "Access Open WebUI at:"
echo " http://<your-server-ip>:8080"
echo "=============================================="