#!/bin/sh # Install host Python dependencies needed by flash-mtk.py into .flash-deps/. set -eu BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)" PYTHON_BIN="${PYTHON_BIN:-python3}" TARGET="$BASE_DIR/.flash-deps" if "$PYTHON_BIN" -c 'import usb.core, serial, Crypto, colorama' >/dev/null 2>&1; then echo "[flash-deps] pyusb, pyserial, pycryptodome, and colorama are already available." exit 0 fi if [ -d "$TARGET" ] && PYTHONPATH="$TARGET${PYTHONPATH:+:$PYTHONPATH}" \ "$PYTHON_BIN" -c 'import usb.core, serial, Crypto, colorama' >/dev/null 2>&1; then echo "[flash-deps] Using existing dependencies in $TARGET." exit 0 fi if ! "$PYTHON_BIN" -m pip --version >/dev/null 2>&1; then echo "Error: python3 pip is required to install flashing dependencies (pyusb, pyserial, pycryptodome, colorama)." >&2 exit 1 fi echo "[flash-deps] Installing pyusb, pyserial, pycryptodome, colorama into $TARGET..." mkdir -p "$TARGET" "$PYTHON_BIN" -m pip install --disable-pip-version-check --no-input \ --target "$TARGET" pyusb pyserial pycryptodome colorama echo "[flash-deps] Done."