#!/bin/sh set -eu APP_DIR="${APP_DIR:-/srv/ptouch-web}" LABEL_DIR="${LABEL_DIR:-/data/labels}" PORT="${PORT:-8080}" PTOUCH_SRC_DIR="${PTOUCH_SRC_DIR:-/tmp/ptouch-print}" FLASK_APP="${FLASK_APP:-app.app}" export FLASK_APP cd "$APP_DIR" mkdir -p "${LABEL_DIR:-/data/labels}" echo "Starting P-Touch Web" echo "APP_DIR=${APP_DIR}" echo "LABEL_DIR=${LABEL_DIR}" echo "FLASK_APP=${FLASK_APP}" echo "PRINT_ENABLED=${PRINT_ENABLED:-1}" echo "PRINT_COMMAND=${PRINT_COMMAND:-ptouch-print --image {image}}" python3 - <<'PY' import os command = os.environ.get("PRINT_COMMAND", "ptouch-print --image {image}") try: command.format(image="/tmp/test.png", copies=1) except Exception as exc: raise SystemExit(f"ERROR: invalid PRINT_COMMAND: {exc}") PY if command -v apk >/dev/null 2>&1; then apk add --no-cache \ build-base \ cmake \ gd \ gd-dev \ gettext \ gettext-dev \ git \ libusb \ libusb-dev \ usbutils \ pkgconf \ ttf-dejavu fi if ! python3 -c "import flask, PIL, qrcode, barcode" >/dev/null 2>&1; then if [ -f requirements.txt ]; then python3 -m pip install --root-user-action=ignore --no-cache-dir -r requirements.txt else python3 -m pip install --root-user-action=ignore --no-cache-dir Flask Pillow fi fi if ! python3 -c "import qrcode, barcode" >/dev/null 2>&1; then python3 -m pip install --root-user-action=ignore --no-cache-dir qrcode python-barcode fi if ! command -v ptouch-print >/dev/null 2>&1 || ! ptouch-print --help 2>&1 | grep -q -- "--no-halfcut"; then rm -rf "$PTOUCH_SRC_DIR" git clone --depth 1 --branch farix-main https://github.com/farixembedded/ptouch-print.git "$PTOUCH_SRC_DIR" if [ -f "$APP_DIR/patches/ptouch-print-cut-options.patch" ]; then patch -d "$PTOUCH_SRC_DIR" -p1 < "$APP_DIR/patches/ptouch-print-cut-options.patch" fi cmake -S "$PTOUCH_SRC_DIR" -B "$PTOUCH_SRC_DIR/build" -DCMAKE_BUILD_TYPE=Release cmake --build "$PTOUCH_SRC_DIR/build" install -m 0755 "$PTOUCH_SRC_DIR/build/ptouch-print" /usr/local/bin/ptouch-print fi echo "ptouch-print: $(ptouch-print --version 2>/dev/null || echo installed)" if [ ! -d /dev/bus/usb ]; then echo "WARNING: /dev/bus/usb is not mounted. USB printer access will not work." else echo "USB devices visible in container:" lsusb 2>/dev/null || true find /dev/bus/usb -type c -maxdepth 3 -exec ls -l {} \; 2>/dev/null || true fi exec python3 -m flask --app "${FLASK_APP}" run --host=0.0.0.0 --port="${PORT}"