-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMTProxy-install.sh
144 lines (135 loc) · 4.85 KB
/
MTProxy-install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
#
# https://github.com/BluestarCo/MTProxy-install
#
# Copyright (c) 2018 BlueStar. Released under the MIT License.
if readlink /proc/$$/exe | grep -q "dash"; then
echo "This script needs to be run with bash, not sh"
exit
fi
if [[ "$EUID" -ne 0 ]]; then
echo "Sorry, you need to run this as root"
exit
fi
if [[ -e /etc/debian_version ]]; then
OS=debian
GROUPNAME=nogroup
RCLOCAL='/etc/rc.local'
elif [[ -e /etc/centos-release || -e /etc/redhat-release ]]; then
OS=centos
GROUPNAME=nobody
RCLOCAL='/etc/rc.d/rc.local'
else
echo "Looks like you aren't running this installer on Debian, Ubuntu or CentOS"
exit
fi
GREEN='\033[0;32m'
echo -e "${GREEN} Welcome to BluestarCo MTProxy easy install setup."
echo "Okay, that was all I needed. We are ready to set up your MTProxy server now."
read -n1 -r -p "Press any key to continue..."
clear
echo "First, provide the IPv4 address of the network interface you want MTProxy"
echo "listening to."
IP=$(ip addr | grep 'inet' | grep -v inet6 | grep -vE '127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1)
read -p "IP address: " -e -i $IP IP
# If $IP is a private IP address, the server must be behind NAT
if echo "$IP" | grep -qE '^(10\.|172\.1[6789]\.|172\.2[0-9]\.|172\.3[01]\.|192\.168)'; then
echo
echo "This server is behind NAT. What is the public IPv4 address or hostname?"
read -p "Public IP address / hostname: " -e PUBLICIP
fi
clear
echo "What port do you want MTProxy listening to?"
read -p "Port: " -e -i 443 PORT
echo "Install Updates..."
if [[ "$OS" = 'debian' ]]; then
apt-get -y update
apt-get -y upgrade
else
yum update -y
fi
clear
echo "Install Development Tools..."
if [[ "$OS" = 'debian' ]]; then
apt-get -y install build-essential libssl-dev zlib1g-dev git curl vim-common screen systemd
else
yum groupinstall "Development Tools" -y
yum install git -y
yum install openssl-devel -y
yum install curl -y
yum install vim-common
yum install screen -y
fi
cd ~/
clear
echo "Downloading MTProxy Source..."
git clone https://github.com/TelegramMessenger/MTProxy.git
cd MTProxy
clear
echo "Building MTProxy Source..."
chmod a+x Makefile
make
cd objs
cd bin
clear
echo "Build Complete , Downloading Configs..."
curl -s https://core.telegram.org/getProxySecret -o proxy-secret
curl -s https://core.telegram.org/getProxyConfig -o proxy-multi.conf
clear
echo "Making Secret Hash..."
secret=$(head -c 16 /dev/urandom | xxd -ps)
clear
echo "Adding Service to auto run list..."
echo -n > /etc/systemd/system/MTProxy.service
echo "[Unit]" >> /etc/systemd/system/MTProxy.service
echo "Description=MTProxy" >> /etc/systemd/system/MTProxy.service
echo "After=network.target" >> /etc/systemd/system/MTProxy.service
echo "" >> /etc/systemd/system/MTProxy.service
echo "[Service]" >> /etc/systemd/system/MTProxy.service
echo "Type=simple" >> /etc/systemd/system/MTProxy.service
echo "WorkingDirectory=/root/MTProxy/objs/bin" >> /etc/systemd/system/MTProxy.service
echo "ExecStart=/root/MTProxy/objs/bin/mtproto-proxy -u nobody -p 8888 -H $PORT -S $secret --aes-pwd proxy-secret proxy-multi.conf -M 1" >> /etc/systemd/system/MTProxy.service
echo "Restart=on-failure" >> /etc/systemd/system/MTProxy.service
echo "" >> /etc/systemd/system/MTProxy.service
echo "[Install]" >> /etc/systemd/system/MTProxy.service
echo "WantedBy=multi-user.target" >> /etc/systemd/system/MTProxy.service
clear
echo "Restarting services."
systemctl daemon-reload
systemctl restart MTProxy.service
systemctl enable MTProxy.service
echo -n > ~/mtproxy-status
echo "#!/bin/bash" >> ~/mtproxy-status
echo "systemctl status MTProxy.service" >> ~/mtproxy-status
echo -n > ~/mtproxy-remove
echo "#!/bin/bash" >> ~/mtproxy-remove
echo "echo Uninstalling MTProxy from your server..." >> ~/mtproxy-remove
echo "cd ~/" >> ~/mtproxy-remove
echo "rm -rf MTProxy" >> ~/mtproxy-remove
echo "rm -rf MTProxy-link.txt" >> ~/mtproxy-remove
echo "rm -rf mtproxy-status" >> ~/mtproxy-remove
echo "rm -rf /etc/systemd/system/MTProxy.service" >> ~/mtproxy-remove
clear
echo "echo Uninstalling MTProxy Completed..." >> ~/mtproxy-remove
echo "rm -rf ~/mtproxy-remove" >> ~/mtproxy-remove
clear
echo "Services started."
clear
echo
echo "Install Finished!"
echo
echo "Your MTProxy available at :"
echo "tg://proxy?server=$IP&port=$PORT&secret=$secret"
echo "tg://proxy?server=$IP&port=$PORT&secret=$secret" > /root/MTProxy-link.txt
echo
echo "Your MTProxy link writed to file and available at :"
echo "/root/MTProxy-link.txt"
echo
echo
echo "If you need to Check MTProxy status, it should be active you can run mtproxy-status located at :/root/mtproxy-status"
echo
echo "Example : sh mtproxy-status"
echo
echo "If you need to Uninstall MTProxy you can run mtproxy-remove located at :/root/mtproxy-remove"
echo
echo "Example : sh mtproxy-remove"