#!/usr/bin/env bash # Stops and removes the Gemma 3 vLLM stack. Optional --purge removes local model/cache data. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" PURGE=0 log() { printf '[uninstall] %s\n' "$*" } err() { printf '[uninstall][error] %s\n' "$*" >&2 } load_env_file() { if [[ ! -f "${ENV_FILE}" ]]; then return fi set -a # shellcheck disable=SC1090 source "${ENV_FILE}" set +a } usage() { cat <<'EOF' Usage: scripts/uninstall.sh [--purge] Options: --purge Remove local Hugging Face cache directory and ./models data in addition to containers/volumes. -h, --help Show this help message. EOF } while [[ $# -gt 0 ]]; do case "$1" in --purge) PURGE=1 ;; -h|--help) usage exit 0 ;; *) err "Unknown argument: $1" usage exit 1 ;; esac shift done if [[ ! -f "${REPO_ROOT}/docker-compose.yml" ]]; then err "docker-compose.yml not found at ${REPO_ROOT}." exit 1 fi ENV_FILE="${REPO_ROOT}/.env" if [[ ! -f "${ENV_FILE}" ]]; then ENV_FILE="${REPO_ROOT}/.env.example" fi load_env_file log "Stopping stack and removing containers, networks, and named/anonymous volumes." docker compose -f "${REPO_ROOT}/docker-compose.yml" --env-file "${ENV_FILE}" down -v || true if [[ ${PURGE} -eq 1 ]]; then log "Purge requested. Removing local data directories used by this stack." huggingface_cache_dir="${HUGGINGFACE_CACHE_DIR:-}" open_webui_data_dir="${OPEN_WEBUI_DATA_DIR:-./frontend/data/open-webui}" if [[ -n "${huggingface_cache_dir}" ]]; then if [[ "${huggingface_cache_dir}" == ./* ]]; then huggingface_cache_dir="${REPO_ROOT}/${huggingface_cache_dir#./}" fi if [[ -d "${huggingface_cache_dir}" ]]; then log "Removing Hugging Face cache directory: ${huggingface_cache_dir}" rm -rf "${huggingface_cache_dir}" else log "Hugging Face cache directory not found: ${huggingface_cache_dir}" fi fi if [[ "${open_webui_data_dir}" == ./* ]]; then open_webui_data_dir="${REPO_ROOT}/${open_webui_data_dir#./}" fi if [[ -d "${open_webui_data_dir}" ]]; then log "Removing Open WebUI data directory: ${open_webui_data_dir}" rm -rf "${open_webui_data_dir}" fi if [[ -d "${REPO_ROOT}/models" ]]; then log "Removing local models directory: ${REPO_ROOT}/models" rm -rf "${REPO_ROOT}/models" fi else log "Safe mode enabled (default). Local model/cache data was preserved." fi log "Uninstall complete."