#!/usr/bin/env bash # FaceAttend setup for Linux x86_64 (CPU). Uses the offline packages in ../packages/linux when present, otherwise the internet. # Python must be 3.9.9 exactly: ~/.local/opt/python-3.9.9 or a python3.9 on the PATH that is 3.9.9 is used, otherwise 3.9.9 is built # from the bundled source. Another Python 3.9.x is never used. set -euo pipefail cd "$(dirname "$(readlink -f "$0")")" PKG="$(dirname "$PWD")/packages/linux"; MODELS_SRC="$(dirname "$PWD")/models" PYDIR="$HOME/.local/opt/python-3.9.9"; PY="" is399() { # Python 3.9.9 with the modules the app needs "$1" -c "import platform, sys, ssl, sqlite3, ctypes, lzma, bz2; sys.exit(platform.python_version() != '3.9.9')" >/dev/null 2>&1 } echo "[1/4] Python 3.9.9" for c in "$PYDIR/bin/python3.9" "$(command -v python3.9 || true)"; do if [ -n "$c" ] && is399 "$c"; then PY="$c"; break; fi done if [ -z "$PY" ]; then [ -f "$PKG/Python-3.9.9.tgz" ] || { echo "Python 3.9.9 not found and $PKG/Python-3.9.9.tgz is missing."; exit 1; } echo " Building Python 3.9.9 into $PYDIR (a few minutes). Build libraries needed (Debian/Ubuntu):" echo " sudo apt install build-essential libssl-dev zlib1g-dev libffi-dev libsqlite3-dev libbz2-dev liblzma-dev libreadline-dev uuid-dev" B="$(mktemp -d)"; tar xzf "$PKG/Python-3.9.9.tgz" -C "$B" (cd "$B/Python-3.9.9" && ./configure --prefix="$PYDIR" --with-ensurepip=install CFLAGS="-std=gnu11" >"$B/configure.log" \ && make -j"$(nproc)" >"$B/make.log" 2>&1 && make install >"$B/install.log" 2>&1) || { echo "Build failed - logs in $B"; exit 1; } rm -rf "$B"; PY="$PYDIR/bin/python3.9" is399 "$PY" || { echo "Python was built without ssl / sqlite3 / ctypes / lzma / bz2 - install the libraries above, then run setup.sh again"; exit 1; } fi echo " $("$PY" -V) ($PY)" echo "[2/4] Virtual environment" if ! { is399 .venv/bin/python && .venv/bin/python -m pip --version >/dev/null 2>&1; }; then # none yet, or of another Python: (re)build "$PY" -m venv --clear .venv fi echo "[3/4] Python packages" if ls "$PKG"/*.whl >/dev/null 2>&1; then grep -v -E '^--' requirements.txt > .venv/requirements-offline.txt # the extra index line is only for online installs .venv/bin/python -m pip install --no-index --find-links "$PKG" -r .venv/requirements-offline.txt else .venv/bin/python -m pip install -r requirements.txt fi echo "[4/4] Face recognition models" mkdir -p models if [ -d "$MODELS_SRC" ]; then cp -n "$MODELS_SRC"/*.onnx "$MODELS_SRC"/*.pt models/ 2>/dev/null || true; fi echo " Models missing here are downloaded by the app when you select them." echo echo "Setup complete. Start FaceAttend with ./run.sh" echo "(If the window does not open: sudo apt install libxcb-xinerama0 libxkbcommon-x11-0 libxcb-cursor0)"