#!/usr/bin/env bash # tg-ws-proxy for Windows: Flowseal's source (the headless proxy, not the tray app) on the # official embeddable CPython, with its dependencies as pinned win_amd64 wheels. Everything is # verified: the Python archive and every wheel by hash, the source by its commit. # # tools/build-tg-ws-proxy.sh OUT_DIR (needs curl, git, unzip, pip) set -euo pipefail . "$(dirname "$0")/lib.sh" OUT=$(realpath -m "${1:?output directory}") cd "$(dirname "$0")" PY_VERSION=3.12.10 PY_URL=https://www.python.org/ftp/python/$PY_VERSION/python-$PY_VERSION-embed-amd64.zip PY_SHA256=4acbed6dd1c744b0376e3b1cf57ce906f9dc9e95e68824584c8099a63025a3c3 TG_TAG=v1.11.2 TG_COMMIT=307a384ab7f522e34bb1a045884d0bd90f40bee5 WORK=$(mktemp -d) trap 'rm -rf "$WORK"' EXIT rm -rf "$OUT" && mkdir -p "$OUT/python" "$OUT/app" curl -sSfL -o "$WORK/python.zip" "$PY_URL" echo "$PY_SHA256 $WORK/python.zip" | sha256sum -c --quiet unzip -q "$WORK/python.zip" -d "$OUT/python" pip download -q --require-hashes --no-deps --only-binary=:all: --platform win_amd64 \ --python-version 3.12 --implementation cp --dest "$WORK/wheels" -r tg-ws-proxy-requirements.txt mkdir -p "$OUT/python/Lib/site-packages" for w in "$WORK"/wheels/*.whl; do unzip -q -o "$w" -d "$OUT/python/Lib/site-packages"; done clone_tag https://github.com/Flowseal/tg-ws-proxy "$TG_TAG" "$WORK/src" [ "$(git -C "$WORK/src" rev-parse HEAD)" = "$TG_COMMIT" ] || { echo "tag $TG_TAG moved off $TG_COMMIT"; exit 1; } cp -r "$WORK/src/proxy" "$WORK/src/utils" "$WORK/src/LICENSE" "$OUT/app/" # The embeddable Python reads its path from this file alone: the standard library, the # wheels, and the source. printf 'python312.zip\n.\nLib\\site-packages\n..\\app\nimport site\n' > "$OUT/python/python312._pth" echo "${TG_TAG#v}+py$PY_VERSION" > "$OUT/.version" echo "tg-ws-proxy ${TG_TAG#v} on Python $PY_VERSION in $OUT"