From d69534d28661c1660768fa4fd65db5f5d81b45aa Mon Sep 17 00:00:00 2001 From: DragonSlayer_14 Date: Sun, 6 Sep 2026 13:23:32 +0200 Subject: [PATCH] =?UTF-8?q?Feat:=20Ollama-Installation=20und=20systemd-Ser?= =?UTF-8?q?vice-Konfiguration=20mit=20anpassbarem=20Modellpfad=20hinzugef?= =?UTF-8?q?=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Junie --- AGENTS.md | 3 ++- README.md | 2 +- config/setup.conf | 6 +++++ lib/tui.sh | 2 +- lib/utils.sh | 59 +++++++++++++++++++++++++++++++++++++++++++ setup.sh | 2 +- stages/06-services.sh | 53 +++++++++++++++++++++++++++++++++++--- 7 files changed, 120 insertions(+), 7 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index daba2d3..861b943 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -41,7 +41,7 @@ Dieses Repository ist ein modulares, automatisiertes Setup- und Konfigurations-F │ ├── 03-bootloader.sh # GRUB Kernel-Parameter, Vimix-Theme, Plymouth Solar │ ├── 04-packages.sh # Installation der thematischen Paketlisten │ ├── 05-fonts.sh # Download & Installation von Coding- & Nerd-Fonts -│ ├── 06-services.sh # Aktivierung von AppArmor, Docker, Libvirt, zram +│ ├── 06-services.sh # Aktivierung von AppArmor, Docker, Libvirt, zram, Ollama │ ├── 07-skel-and-user.sh # /etc/skel Vorlagen, ZSH-Shell-Setzen, Dotfiles-Sync │ ├── 08-flatpaks-apps.sh # Flathub Setup, Flatpaks, Spotify, Waydroid, MIME-Types │ └── 09-hyprland.sh # LinuxBeginnings Debian-Hyprland Auto-Installer & Desktop-Setup @@ -121,6 +121,7 @@ Dieses Repository ist ein modulares, automatisiertes Setup- und Konfigurations-F - `require_root`: Bricht ab, wenn das Skript nicht mit Root-Rechten ausgeführt wird. - `command_exists "tool"`: Prüft, ob ein Befehl im Pfad verfügbar ist. - `prompt_target_user`: Erkennt `$SUDO_USER` oder fragt interaktiv nach dem Zielbenutzer. +- `prompt_ollama_models_path`: Fragt interaktiv nach dem Speicherort für Ollama KI-Modelle oder nutzt Standardpfad. - `get_target_home [username]`: Gibt den absoluten Pfad des Home-Verzeichnisses des Nutzers zurück. - `run_as_user "command"`: Führt einen Befehl als `$TARGET_USER` via `su - "$TARGET_USER" -c ...` aus. - `backup_file "filepath"`: Erstellt ein Backup einer Datei mit Zeitstempel. diff --git a/README.md b/README.md index 2f7b648..a25a3ad 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ sudo ./setup.sh --stages 04,05 │ ├── 03-bootloader.sh # GRUB Kernel-Parameter, Vimix-Theme, Plymouth Solar │ ├── 04-packages.sh # Installation der ausgewählten thematischen Paketlisten │ ├── 05-fonts.sh # Download & Installation von JetBrainsMono, Fantasque, VictorMono -│ ├── 06-services.sh # Aktivierung von AppArmor, Docker, Libvirt, zram +│ ├── 06-services.sh # Aktivierung von AppArmor, Docker, Libvirt, zram, Ollama │ ├── 07-skel-and-user.sh # /etc/skel Vorlagen, ZSH-Shell-Setzen, Dotfiles-Sync │ ├── 08-flatpaks-apps.sh # Flathub Setup, Flatpaks, Spotify, Waydroid, MIME-Types │ └── 09-hyprland.sh # LinuxBeginnings Debian-Hyprland Auto-Installer & Dotfiles diff --git a/config/setup.conf b/config/setup.conf index 46b4a66..ae66fcb 100644 --- a/config/setup.conf +++ b/config/setup.conf @@ -16,5 +16,11 @@ GRUB_TIMEOUT_STYLE="hidden" # Shell & Userland DEFAULT_SHELL="zsh" +# Ollama AI Configuration +OLLAMA_MODELS_DEFAULT="/mnt/Data/Software/ollama/models" +OLLAMA_FLASH_ATTENTION="1" +OLLAMA_KV_CACHE_TYPE="q8_0" +OLLAMA_KEEP_ALIVE="30m" + # Default Stages (if --all is passed or in default batch mode) ALL_STAGES="00 01 02 03 04 05 06 07 08 09" diff --git a/lib/tui.sh b/lib/tui.sh index f454f06..4d83142 100755 --- a/lib/tui.sh +++ b/lib/tui.sh @@ -32,7 +32,7 @@ tui_select_stages() { "03" "Bootloader & Theme (GRUB, Vimix, Plymouth)" ON \ "04" "Pakete (Base, Desktop, Gaming, Virtualisierung)" ON \ "05" "Coding & Nerd Fonts (JetBrainsMono, VictorMono)" ON \ - "06" "System-Dienste (AppArmor, Docker, Libvirt, zram)" ON \ + "06" "System-Dienste (AppArmor, Docker, Libvirt, zram, Ollama)" ON \ "07" "Userland & Skel (Zsh, Skel-Templates, Dotfiles)" ON \ "08" "Flatpaks & Apps (Flathub, Flatpaks, MIME)" ON \ "09" "Hyprland Desktop (LinuxBeginnings Debian-Hyprland Installer)" ON \ diff --git a/lib/utils.sh b/lib/utils.sh index 324e996..d8cdb9f 100755 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -180,6 +180,65 @@ get_target_home() { echo "$user_home" } +# Prompt for Ollama AI models storage path +prompt_ollama_models_path() { + if [[ -n "${OLLAMA_MODELS:-}" ]]; then + echo "$OLLAMA_MODELS" + return 0 + fi + + local default_path="${OLLAMA_MODELS_DEFAULT:-/mnt/Data/Software/ollama/models}" + local chosen="" + local is_interactive=0 + if [[ -t 0 || -c /dev/tty ]] && [[ "${DEBIAN_FRONTEND:-}" != "noninteractive" && "${CI:-}" != "1" && "${AUTO_CONFIRM:-}" != "1" ]]; then + is_interactive=1 + fi + + if [[ "$is_interactive" -eq 1 ]]; then + local tty_in="/dev/tty" + local tty_out="/dev/tty" + if [[ ! -c /dev/tty ]]; then + tty_in="/dev/stdin" + tty_out="/dev/stderr" + fi + + # If whiptail is available and running on an active terminal, use whiptail dialog + if command_exists whiptail && [[ -t 1 || -c /dev/tty ]]; then + local tui_input + if tui_input=$(whiptail --title "Ollama KI-Modelle Speicherort" \ + --inputbox "Bitte gib den Speicherort für die Ollama KI-Modelle an:" \ + 10 70 "$default_path" \ + 3>&1 1>&2 2>&3); then + tui_input="$(echo "$tui_input" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" + if [[ -n "$tui_input" ]]; then + chosen="$tui_input" + else + chosen="$default_path" + fi + fi + fi + + # CLI fallback if whiptail was not used or failed + if [[ -z "$chosen" ]]; then + printf "\n%bOllama KI-Modelle Speicherort:%b\n" "${CLR_CYAN}" "${CLR_RESET}" > "$tty_out" + printf "Standard-Pfad: %b%s%b\n" "${CLR_BOLD}" "$default_path" "${CLR_RESET}" > "$tty_out" + local input_path="" + read -r -p "Speicherort für Ollama-Modelle eingeben [$default_path]: " input_path < "$tty_in" > "$tty_out" 2>&1 || true + input_path="$(echo "$input_path" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" + if [[ -n "$input_path" ]]; then + chosen="$input_path" + else + chosen="$default_path" + fi + fi + else + chosen="$default_path" + fi + + export OLLAMA_MODELS="$chosen" + echo "$chosen" +} + # Run a command as the target user run_as_target_user() { local user diff --git a/setup.sh b/setup.sh index f76c3c8..71b8086 100755 --- a/setup.sh +++ b/setup.sh @@ -40,7 +40,7 @@ Available Stages: 03: Bootloader & Splash (GRUB configuration, Vimix Theme, Plymouth Solar) 04: Package Installation (Base, Desktop, Gaming, Virtualization, Multimedia) 05: Font Installation (JetBrainsMono, FantasqueSans, VictorMono) - 06: System Services (AppArmor, Docker, Libvirt, zram) + 06: System Services (AppArmor, Docker, Libvirt, zram, Ollama) 07: Skel & User Environment (Zsh, Templates, Dotfiles Sync) 08: Flatpaks & Applications (Flathub, Spotify, Waydroid, MIME types) 09: Hyprland Desktop (LinuxBeginnings Auto-Installer) diff --git a/stages/06-services.sh b/stages/06-services.sh index c695e8d..291608a 100755 --- a/stages/06-services.sh +++ b/stages/06-services.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # ============================================================================== -# stages/06-services.sh - System services activation (AppArmor, Docker, Libvirt, zram) +# stages/06-services.sh - System services activation (AppArmor, Docker, Libvirt, zram, Ollama) # ============================================================================== set -euo pipefail @@ -9,6 +9,11 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" source "$SCRIPT_DIR/lib/utils.sh" source "$SCRIPT_DIR/lib/apt.sh" +if [[ -f "$SCRIPT_DIR/config/setup.conf" ]]; then + # shellcheck source=/dev/null + source "$SCRIPT_DIR/config/setup.conf" +fi + setup_err_trap log_step "Running Stage 06: System Services Configuration & User Privileges" @@ -92,11 +97,53 @@ else log_info "No hardware virtualization extensions (VT-x/AMD-V) detected in /proc/cpuinfo." fi -# 5. User Group Memberships +# 5. Ollama AI Service & Configuration +log_substep "Configuring Ollama AI Service..." +OLLAMA_MODELS_DIR="$(prompt_ollama_models_path)" +log_info "Ollama models directory set to: $OLLAMA_MODELS_DIR" +mkdir -p "$OLLAMA_MODELS_DIR" + +log_substep "Installing / Updating Ollama..." +if curl -fsSL https://ollama.com/install.sh | sh; then + log_success "Ollama installation completed." +else + log_warn "Ollama installation script returned a non-zero exit code." +fi + +# Ensure permissions on models directory for ollama user +if id ollama >/dev/null 2>&1; then + chown -R ollama:ollama "$OLLAMA_MODELS_DIR" 2>/dev/null || true + chmod -R 775 "$OLLAMA_MODELS_DIR" 2>/dev/null || true +fi + +# Configure systemd drop-in override for Ollama service +log_substep "Configuring systemd override for Ollama service..." +mkdir -p /etc/systemd/system/ollama.service.d +cat < /etc/systemd/system/ollama.service.d/override.conf +[Service] +Environment="OLLAMA_MODELS=$OLLAMA_MODELS_DIR" +Environment="OLLAMA_FLASH_ATTENTION=${OLLAMA_FLASH_ATTENTION:-1}" +Environment="OLLAMA_KV_CACHE_TYPE=${OLLAMA_KV_CACHE_TYPE:-q8_0}" +Environment="OLLAMA_KEEP_ALIVE=${OLLAMA_KEEP_ALIVE:-30m}" +EOF +chmod 0644 /etc/systemd/system/ollama.service.d/override.conf + +if command_exists systemctl; then + systemctl daemon-reload 2>/dev/null || true + systemctl enable --now ollama.service 2>/dev/null || true + systemctl restart ollama.service 2>/dev/null || true + log_success "Ollama systemd service configured and enabled." +fi + +# 6. User Group Memberships log_substep "Updating user group memberships for $TARGET_USER..." groupadd -f sudo groupadd -f docker +groupadd -f ollama 2>/dev/null || true usermod -aG sudo,docker "$TARGET_USER" -log_success "Target user $TARGET_USER added to sudo and docker groups." +if getent group ollama >/dev/null 2>&1; then + usermod -aG ollama "$TARGET_USER" 2>/dev/null || true +fi +log_success "Target user $TARGET_USER added to sudo, docker and ollama groups." log_success "Stage 06: System services configuration completed successfully!"