├── 1.png ├── 2.png ├── README.MD ├── install.sh └── uninstall.sh /1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FunctionClub/MTProxy-Bash/43a8750670ba0b02db5c6b8bdd406b71b35837bf/1.png -------------------------------------------------------------------------------- /2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FunctionClub/MTProxy-Bash/43a8750670ba0b02db5c6b8bdd406b71b35837bf/2.png -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | # MTProxy-Bash 2 | MTProxy 一键搭建管理脚本。 3 | MTProxy 是专门用于 Telegram 的代理软件。目前 Telegram 内部直接支持此代理软件。安装完成后生成的 `tg://` 链接可在 Telegram 内随意分享使用。代理效果非常出色。 4 | 5 | # 截图 6 | ![1.png](1.png) 7 | ![2.png](2.png) 8 | 9 | # 安装 10 | ```bash 11 | wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/MTProxy-Bash/master/install.sh && bash install.sh 12 | ``` 13 | 14 | # 卸载 15 | ```bash 16 | wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/MTProxy-Bash/master/uninstall.sh && bash uninstall.sh 17 | ``` 18 | 19 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin 3 | export PATH 4 | 5 | #Check Root 6 | [ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; } 7 | 8 | #Check OS 9 | if [ -n "$(grep 'Aliyun Linux release' /etc/issue)" -o -e /etc/redhat-release ]; then 10 | OS=CentOS 11 | [ -n "$(grep ' 7\.' /etc/redhat-release)" ] && CentOS_RHEL_version=7 12 | [ -n "$(grep ' 6\.' /etc/redhat-release)" -o -n "$(grep 'Aliyun Linux release6 15' /etc/issue)" ] && CentOS_RHEL_version=6 13 | [ -n "$(grep ' 5\.' /etc/redhat-release)" -o -n "$(grep 'Aliyun Linux release5' /etc/issue)" ] && CentOS_RHEL_version=5 14 | elif [ -n "$(grep 'Amazon Linux AMI release' /etc/issue)" -o -e /etc/system-release ]; then 15 | OS=CentOS 16 | CentOS_RHEL_version=6 17 | elif [ -n "$(grep bian /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == 'Debian' ]; then 18 | OS=Debian 19 | [ ! -e "$(which lsb_release)" ] && { apt-get -y update; apt-get -y install lsb-release; clear; } 20 | Debian_version=$(lsb_release -sr | awk -F. '{print $1}') 21 | elif [ -n "$(grep Deepin /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == 'Deepin' ]; then 22 | OS=Debian 23 | [ ! -e "$(which lsb_release)" ] && { apt-get -y update; apt-get -y install lsb-release; clear; } 24 | Debian_version=$(lsb_release -sr | awk -F. '{print $1}') 25 | elif [ -n "$(grep Ubuntu /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == 'Ubuntu' -o -n "$(grep 'Linux Mint' /etc/issue)" ]; then 26 | OS=Ubuntu 27 | [ ! -e "$(which lsb_release)" ] && { apt-get -y update; apt-get -y install lsb-release; clear; } 28 | Ubuntu_version=$(lsb_release -sr | awk -F. '{print $1}') 29 | [ -n "$(grep 'Linux Mint 18' /etc/issue)" ] && Ubuntu_version=16 30 | else 31 | echo "${CFAILURE}Does not support this OS, Please contact the author! ${CEND}" 32 | kill -9 $$ 33 | fi 34 | 35 | # 检测CPU线程数 36 | THREAD=$(grep 'processor' /proc/cpuinfo | sort -u | wc -l) 37 | 38 | # 定义终端颜色 39 | red='\033[0;31m' 40 | green='\033[0;32m' 41 | yellow='\033[0;33m' 42 | plain='\033[0m' 43 | 44 | # 打印欢迎信息 45 | clear 46 | echo "---------------------------------------------" 47 | echo " Install MTProxy For Telegram with Onekey" 48 | echo " Author: 雨落无声" 49 | echo " URL: https://ylws.me" 50 | echo " Telegram: https://t.me/ylwsclub" 51 | echo "---------------------------------------------" 52 | echo "" 53 | 54 | 55 | if [ -f "/etc/secret" ]; then 56 | IP=$(curl -4 -s ip.sb) 57 | SECRET=$(cat /etc/secret) 58 | PORT=$(cat /etc/proxy-port) 59 | echo "MTProxy 已安装" 60 | echo "服务器IP: ${IP}" 61 | echo "端口: ${PORT}" 62 | echo "Secret: ${SECRET}" 63 | echo "" 64 | echo -e "TG代理链接:${green}tg://proxy?server=${IP}&port=${PORT}&secret=${SECRET}${plain}" 65 | exit 0 66 | fi 67 | 68 | # 输入代理端口 69 | read -p "Input the Port for running MTProxy [Default: 5000]: " uport 70 | if [[ -z "${uport}" ]];then 71 | uport="5000" 72 | fi 73 | 74 | # 输入secret 75 | read -p "Input the Secret for running MTProxy [Default: Autogeneration]: " SECRET 76 | if [[ -z "${SECRET}" ]];then 77 | SECRET=$(head -c 16 /dev/urandom | xxd -ps) 78 | fi 79 | 80 | # 输入TAG 81 | read -p "Input the Tag for running MTProxy [Default: None]: " TAG 82 | if [[ -n "${TAG}" ]];then 83 | TAG="-P "${TAG} 84 | fi 85 | 86 | # 输入nat信息 87 | read -p "Input NAT infomation like : if you are using NAT network, otherwise just press ENTER directly: " NAT 88 | if [[ -n "${NAT}" ]];then 89 | NAT="--nat-info "${NAT} 90 | fi 91 | 92 | if [ ${OS} == Ubuntu ] || [ ${OS} == Debian ];then 93 | apt-get update -y 94 | apt-get install build-essential libssl-dev zlib1g-dev curl git vim-common -y 95 | apt-get install xxd -y 96 | fi 97 | 98 | if [ ${OS} == CentOS ];then 99 | yum install openssl-devel zlib-devel curl git vim-common -y 100 | yum groupinstall "Development Tools" -y 101 | fi 102 | 103 | # 获取本机 IP 地址 104 | IP=$(curl -4 -s ip.sb) 105 | 106 | # 切换至临时目录 107 | mkdir /tmp/MTProxy 108 | cd /tmp/MTProxy 109 | 110 | # 下载 MTProxy 项目源码 111 | git clone https://github.com/TelegramMessenger/MTProxy 112 | 113 | # 进入项目编译并安装至 /usr/local/bin/ 114 | pushd MTProxy 115 | make -j ${THREAD} 116 | cp objs/bin/mtproto-proxy /usr/local/bin/ 117 | 118 | # 生成密钥 119 | curl -s https://core.telegram.org/getProxySecret -o /etc/proxy-secret 120 | curl -s https://core.telegram.org/getProxyConfig -o /etc/proxy-multi.conf 121 | echo "${uport}" > /etc/proxy-port 122 | echo "${SECRET}" > /etc/secret 123 | 124 | # 设置 Systemd 服务管理配置 125 | cat << EOF > /etc/systemd/system/MTProxy.service 126 | [Unit] 127 | Description=MTProxy 128 | After=network.target 129 | 130 | [Service] 131 | Type=simple 132 | WorkingDirectory=/usr/local/bin/ 133 | ExecStart=/usr/local/bin/mtproto-proxy -u nobody -p 64335 -H ${uport} -S ${SECRET} ${TAG} ${NAT} --aes-pwd /etc/proxy-secret /etc/proxy-multi.conf 134 | Restart=on-failure 135 | 136 | [Install] 137 | WantedBy=multi-user.target 138 | EOF 139 | 140 | 141 | # 设置防火墙 142 | if [ ! -f "/etc/iptables.up.rules" ]; then 143 | iptables-save > /etc/iptables.up.rules 144 | fi 145 | 146 | if [[ ${OS} =~ ^Ubuntu$|^Debian$ ]];then 147 | iptables-restore < /etc/iptables.up.rules 148 | clear 149 | iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport $uport -j ACCEPT 150 | iptables -I INPUT -m state --state NEW -m udp -p udp --dport $uport -j ACCEPT 151 | iptables-save > /etc/iptables.up.rules 152 | fi 153 | 154 | if [[ ${OS} == CentOS ]];then 155 | if [[ $CentOS_RHEL_version == 7 ]];then 156 | systemctl status firewalld > /dev/null 2>&1 157 | if [ $? -eq 0 ]; then 158 | firewall-cmd --permanent --zone=public --add-port=${uport}/tcp 159 | firewall-cmd --permanent --zone=public --add-port=${uport}/udp 160 | firewall-cmd --reload 161 | else 162 | iptables-restore < /etc/iptables.up.rules 163 | iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport $uport -j ACCEPT 164 | iptables -I INPUT -m state --state NEW -m udp -p udp --dport $uport -j ACCEPT 165 | iptables-save > /etc/iptables.up.rules 166 | fi 167 | else 168 | iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport $uport -j ACCEPT 169 | iptables -I INPUT -m state --state NEW -m udp -p udp --dport $uport -j ACCEPT 170 | /etc/init.d/iptables save 171 | /etc/init.d/iptables restart 172 | fi 173 | fi 174 | 175 | 176 | # 设置开机自启并启动 MTProxy 177 | systemctl daemon-reload 178 | systemctl enable MTProxy.service 179 | systemctl restart MTProxy 180 | 181 | # 清理安装残留 182 | rm -rf /tmp/MTProxy >> /dev/null 183 | 184 | # 显示服务信息 185 | clear 186 | echo "MTProxy 安装成功!" 187 | echo "服务器IP: ${IP}" 188 | echo "端口: ${uport}" 189 | echo "Secret: ${SECRET}" 190 | echo "" 191 | echo -e "TG代理链接:${green}tg://proxy?server=${IP}&port=${uport}&secret=${SECRET}${plain}" 192 | 193 | -------------------------------------------------------------------------------- /uninstall.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin 3 | export PATH 4 | 5 | #Check Root 6 | [ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; } 7 | 8 | # 删除文件 9 | rm -rf /etc/proxy-secret 10 | rm -rf /etc/proxy-multi.conf 11 | rm -rf /etc/secret 12 | rm -rf /etc/proxy-port 13 | 14 | # 删除服务文件 15 | systemctl disable MTProxy.service 16 | systemctl stop MTProxy 17 | rm -rf /etc/systemd/system/MTProxy.service 18 | systemctl daemon-reload 19 | 20 | 21 | clear 22 | echo "卸载成功!" 23 | 24 | rm -rf uninstall.sh 25 | --------------------------------------------------------------------------------