Files
proxy-suite-flake/pkgs/tg-ws-proxy.template.sh

52 lines
896 B
Bash

set -euo pipefail
secret=""
script_path="@src@/proxy/tg_ws_proxy.py"
args=()
while [ "$#" -gt 0 ]; do
case "$1" in
--secret-file=*)
secret=$(tr -d '\r\n' < "${1#--secret-file=}")
shift
;;
--secret-file)
secret=$(tr -d '\r\n' < "$2")
shift 2
;;
--secret=*)
secret="${1#--secret=}"
shift
;;
--secret)
secret="$2"
shift 2
;;
*)
args+=("$1")
shift
;;
esac
done
export PYTHONPATH="@src@"
if [ -n "$secret" ]; then
export TG_WS_PROXY_SECRET="$secret"
fi
exec python - "$script_path" "${args[@]}" <<'PY'
import os
import runpy
import sys
script_path = sys.argv[1]
args = sys.argv[2:]
secret = os.environ.get("TG_WS_PROXY_SECRET")
if secret is not None:
args.extend(["--secret", secret])
sys.argv = ["tg_ws_proxy.py", *args]
runpy.run_path(script_path, run_name="__main__")
PY