Add 02-ollama_install_v2.sh

This commit is contained in:
RomanNum3ral 2025-09-28 23:18:16 +00:00
parent 65646cf258
commit 85e48b687f
1 changed files with 46 additions and 0 deletions

46
02-ollama_install_v2.sh Normal file
View File

@ -0,0 +1,46 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
trap 'echo "[ERROR] Line ${LINENO}: command failed"; exit 1' ERR
ARCH=$(uname -m)
case "$ARCH" in
x86_64|aarch64|arm64) ;;
*)
echo "[FATAL] Unsupported architecture: $ARCH"
exit 2
;;
esac
if command -v apt >/dev/null 2>&1; then
PKG="curl ca-certificates"
sudo apt-get update -y
sudo apt-get install -y $PKG
fi
echo "[STEP] Installing Ollama (official one-liner)"
curl -fsSL https://ollama.com/install.sh | sh
echo "[STEP] Ensuring ollama service is running"
if command -v systemctl >/dev/null 2>&1; then
sudo systemctl enable --now ollama || true
sudo systemctl status --no-pager ollama || true
else
# Non-systemd: try launching in background
nohup ollama serve >/var/log/ollama-serve.log 2>&1 &
sleep 2
fi
echo "[STEP] Testing API on localhost:11434"
for i in {1..10}; do
if curl -fsS http://127.0.0.1:11434/api/version >/dev/null 2>&1; then
echo "[OK] Ollama API is reachable."
exit 0
fi
sleep 1
done
echo "[WARN] Ollama API not reachable yet. Check logs: journalctl -u ollama -e"
exit 0