Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

run.sh 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. #
  3. # Configuration options (set by environment variables during script execution)
  4. # - MTG_CONFIG - directory where mtg stores its configuration
  5. # - MTG_IMAGENAME - a name of the docker image to use
  6. # - MTG_PORT - which port of the host system should be used
  7. # - MTG_CONTAINER - a name of the container to use
  8. #
  9. # Example:
  10. # export MTG_CONFIG="$HOME/mtg_config"
  11. # export MTG_IMAGENAME="nineseconds/mtg:latest"
  12. # curl -sfL --compressed https://raw.githubusercontent.com/9seconds/mtg/master/run.sh | bash
  13. set -eu -o pipefail
  14. export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
  15. export MTG_CONFIG="${MTG_CONFIG:-$XDG_CONFIG_HOME/mtg}"
  16. mkdir -p "$MTG_CONFIG" || true
  17. MTG_SECRET="$MTG_CONFIG/secret"
  18. MTG_ENV="$MTG_CONFIG/env"
  19. if [ ! -f "$MTG_ENV" ]; then
  20. MTG_IMAGENAME="${MTG_IMAGENAME:-nineseconds/mtg:latest}"
  21. MTG_PORT="${MTG_PORT:-3128}"
  22. MTG_CONTAINER="${MTG_CONTAINER:-mtg}"
  23. echo "MTG_IMAGENAME=${MTG_IMAGENAME}" > "$MTG_ENV"
  24. echo "MTG_PORT=${MTG_PORT}" >> "$MTG_ENV"
  25. echo "MTG_CONTAINER=${MTG_CONTAINER}" >> "$MTG_ENV"
  26. fi
  27. set -a
  28. source "$MTG_ENV"
  29. set +a
  30. docker pull "$MTG_IMAGENAME"
  31. if [ ! -f "$MTG_SECRET" ]; then
  32. docker run \
  33. --rm \
  34. "$MTG_IMAGENAME" \
  35. generate-secret tls -c "$(openssl rand -hex 16).com" \
  36. > "$MTG_SECRET"
  37. fi
  38. echo
  39. echo "Proxy secret is $(cat "$MTG_SECRET"). Port is $MTG_PORT."
  40. echo
  41. docker ps --filter "Name=$MTG_CONTAINER" -aq | xargs -r docker rm -fv
  42. docker run \
  43. -d \
  44. --restart=unless-stopped \
  45. --name "$MTG_CONTAINER" \
  46. --ulimit nofile=51200:51200 \
  47. -p "$MTG_PORT:3128" \
  48. "$MTG_IMAGENAME" run "$(cat "$MTG_SECRET")"