Last active
February 11, 2021 08:44
-
-
Save om26er/ada8547397a60007995bcc66adcf4049 to your computer and use it in GitHub Desktop.
Script to Deploy MTProxy on Ubuntu Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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