Skip to content

Instantly share code, notes, and snippets.

@om26er
Last active February 11, 2021 08:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save om26er/ada8547397a60007995bcc66adcf4049 to your computer and use it in GitHub Desktop.
Save om26er/ada8547397a60007995bcc66adcf4049 to your computer and use it in GitHub Desktop.
Script to Deploy MTProxy on Ubuntu Server
#!/bin/sh
if [ $(id -u) -ne 0 ]; then
echo "This script must be run as root"
exit 1
fi
USERNAME=mtproxy
PORT=8000
SERVICE=mtproxy
snap install mtproxy
useradd $USERNAME -m
sudo -u $USERNAME mkdir /home/$USERNAME/proxyconfig
sudo -u $USERNAME curl -s https://core.telegram.org/getProxySecret -o /home/$USERNAME/proxyconfig/proxy-secret
sudo -u $USERNAME curl -s https://core.telegram.org/getProxyConfig -o /home/$USERNAME/proxyconfig/proxy-multi.conf
ACCESS_SECRET=$(head -c 16 /dev/urandom | xxd -ps)
echo "
[Unit]
Description=MTProxy
After=network.target
[Service]
Type=simple
User=mtproxy
WorkingDirectory=/home/$USERNAME/proxyconfig
ExecStart=/snap/bin/mtproxy -u $USERNAME -p 8888 -H $PORT -S $ACCESS_SECRET --aes-pwd proxy-secret proxy-multi.conf -M 1
Restart=on-failure
[Install]
WantedBy=multi-user.target
" >> /etc/systemd/system/$SERVICE.service
systemctl enable $SERVICE
systemctl start $SERVICE
systemctl status $SERVICE --no-pager
echo "$USERNAME ALL=(ALL) NOPASSWD: /bin/systemctl restart $SERVICE" | EDITOR='tee -a' visudo
crontab -u $USERNAME -l 2>/dev/null; echo "0 0 * * * curl -s https://core.telegram.org/getProxyConfig -o /home/$USERNAME/proxyconfig/proxy-multi.conf && sudo /bin/systemctl restart $SERVICE" | crontab -u $USERNAME -
echo "Secret for client: $ACCESS_SECRET"
echo "Port for client: $PORT"
echo "IP address should probably be the public IP of your VPS (or whatever)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment