moebiusT7/book-ocr-studio
0
1#!/usr/bin/env bash2set -euo pipefail3cd -- "$(dirname -- "$0")"4umask 0775if [[ $# -gt 1 ]]; then echo "Use one option only; see --help." >&2; exit 2; fi6case "${1:-}" in7 --help|-h)8 echo 'Usage: bash install.sh [--skip-model | --yomitoku]'9 echo 'Creates an isolated .venv; --yomitoku creates .venv-yomitoku instead.'10 echo 'Python 3.10 or 3.11 required; choose with BOOK_OCR_PYTHON.'11 echo 'Default: downloads missing Gemma 12B weights using preinstalled Ollama. --skip-model installs Python only. No sudo or browser installation.'12 exit 0;;13 '') target=.venv; requirements=requirements.txt; prepare_model=1;;14 --skip-model) target=.venv; requirements=requirements.txt; prepare_model=0;;15 --yomitoku) target=.venv-yomitoku; requirements=requirements-yomitoku.txt; prepare_model=0;;16 *) echo 'Unknown option; use --help' >&2; exit 2;;17esac18python="${BOOK_OCR_PYTHON:-python3}"19"$python" -c 'import sys; assert sys.platform == "linux", "Linux required"; assert (3,10) <= sys.version_info[:2] < (3,12), "Use Python 3.10 or 3.11"'20if [[ -e "$target" ]]; then21 echo "$target already exists; refusing to modify it. Move it aside deliberately or use a fresh directory." >&222 exit 123fi24if [[ "$prepare_model" == 1 ]] && ! command -v ollama >/dev/null 2>&1; then25 echo 'Install Ollama first (https://ollama.com/download/linux), or use --skip-model.' >&226 exit 127fi28"$python" -m venv "$target"29"$target/bin/python" -m pip install --upgrade pip30constraints=()31if [[ "$target" == .venv ]] && "$target/bin/python" -c 'import sys; sys.exit(sys.version_info[:2] != (3,10))'; then32 constraints=(-c constraints-linux-py310.txt)33fi34"$target/bin/python" -m pip install -r "$requirements" "${constraints[@]}"35"$target/bin/python" -m pip check36if [[ "$target" == .venv ]]; then37 "$target/bin/python" scripts/check_install.py38else39 "$target/bin/python" -c 'from yomitoku import DocumentAnalyzer; import cv2, torch; print("Optional engine imports OK; models not loaded")'40fi41if [[ "$prepare_model" == 1 ]]; then42 "$target/bin/python" scripts/setup_models.py43fi44echo 'Installation finished. Read INSTALL.md for drivers and Chrome. C1 OCR review is included in the application.' 45 