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
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

run.sh 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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
  14. export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
  15. export MTG_CONFIG="${MTG_CONFIG:-$XDG_CONFIG_HOME/mtg}"
  16. if ! [ -x "$(command -v docker)" ]; then
  17. echo 'Error: docker is not installed.' >&2
  18. exit 1
  19. fi
  20. id -Gn "$USER" | grep -qw 'docker' > /dev/null
  21. if [ $? -eq 0 ] || [ "$(id -u)" -eq '0' ]; then
  22. DOCKER_CMD="$(command -v docker)"
  23. else
  24. DOCKER_CMD="sudo $(command -v docker)"
  25. fi
  26. mkdir -p "$MTG_CONFIG" || true
  27. MTG_SECRET="$MTG_CONFIG/secret"
  28. MTG_ENV="$MTG_CONFIG/env"
  29. if [ ! -f "$MTG_ENV" ]; then
  30. MTG_IMAGENAME="${MTG_IMAGENAME:-nineseconds/mtg:stable}"
  31. MTG_PORT="${MTG_PORT:-3128}"
  32. MTG_CONTAINER="${MTG_CONTAINER:-mtg}"
  33. echo "MTG_IMAGENAME=$MTG_IMAGENAME" > "$MTG_ENV"
  34. echo "MTG_PORT=$MTG_PORT" >> "$MTG_ENV"
  35. echo "MTG_CONTAINER=$MTG_CONTAINER" >> "$MTG_ENV"
  36. fi
  37. set -a
  38. source "$MTG_ENV"
  39. set +a
  40. $DOCKER_CMD pull "$MTG_IMAGENAME" > /dev/null
  41. if [ ! -f "$MTG_SECRET" ]; then
  42. $DOCKER_CMD run \
  43. --rm \
  44. "$MTG_IMAGENAME" \
  45. generate-secret tls -c "$(openssl rand -hex 16).com" \
  46. > "$MTG_SECRET"
  47. fi
  48. echo "Proxy secret is $(cat "$MTG_SECRET"). Port is $MTG_PORT."
  49. $DOCKER_CMD ps --filter "Name=$MTG_CONTAINER" -aq | xargs -r $DOCKER_CMD rm -fv > /dev/null
  50. $DOCKER_CMD run \
  51. -d \
  52. --restart=unless-stopped \
  53. --name "$MTG_CONTAINER" \
  54. --ulimit nofile=51200:51200 \
  55. -p "$MTG_PORT:3128" \
  56. "$MTG_IMAGENAME" run "$(cat "$MTG_SECRET")" > /dev/null