2024-12-01 08:51:31 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
|
|
|
|
export PATH
|
|
|
|
|
|
|
|
|
|
curPath=`pwd`
|
|
|
|
|
rootPath=$(dirname "$curPath")
|
|
|
|
|
rootPath=$(dirname "$rootPath")
|
|
|
|
|
serverPath=$(dirname "$rootPath")
|
|
|
|
|
|
2024-12-01 10:16:27 -05:00
|
|
|
sysArch=`arch`
|
|
|
|
|
sysName=`uname`
|
2024-12-01 08:51:31 -05:00
|
|
|
|
2025-08-01 07:20:39 -04:00
|
|
|
# systemctl status mtg
|
2024-12-01 13:31:43 -05:00
|
|
|
# cd /www/server/mdserver-web && python3 plugins/mtproxy/index.py url
|
|
|
|
|
# cd /www/server/mdserver-web/plugins/mtproxy && /bin/bash install.sh install 1.0
|
|
|
|
|
|
2024-12-01 08:51:31 -05:00
|
|
|
bash ${rootPath}/scripts/getos.sh
|
2024-12-01 10:16:27 -05:00
|
|
|
echo "bash ${rootPath}/scripts/getos.sh"
|
2024-12-01 08:51:31 -05:00
|
|
|
OSNAME=`cat ${rootPath}/data/osname.pl`
|
|
|
|
|
|
|
|
|
|
VERSION_MIN=2.1.7
|
2024-12-01 10:16:27 -05:00
|
|
|
VERSION=v${VERSION_MIN}
|
|
|
|
|
|
|
|
|
|
sysName=$(uname | tr '[:upper:]' '[:lower:]')
|
2024-12-01 08:51:31 -05:00
|
|
|
|
|
|
|
|
ARCH=amd64
|
|
|
|
|
get_arch() {
|
2026-06-01 06:52:36 -04:00
|
|
|
# 使用 bash 来识别架构
|
|
|
|
|
local arch=$(uname -m)
|
|
|
|
|
case $arch in
|
|
|
|
|
x86_64|amd64)
|
|
|
|
|
ARCH=amd64
|
|
|
|
|
;;
|
|
|
|
|
aarch64|arm64)
|
|
|
|
|
ARCH=arm64
|
|
|
|
|
;;
|
|
|
|
|
armv7l|armv7)
|
|
|
|
|
ARCH=armv7
|
|
|
|
|
;;
|
|
|
|
|
i686|i386)
|
|
|
|
|
ARCH=386
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
ARCH=amd64
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2024-12-01 10:16:27 -05:00
|
|
|
echo "ARCH:${ARCH}"
|
2024-12-01 08:51:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TARGET_DIR="${serverPath}/mtproxy"
|
|
|
|
|
|
|
|
|
|
get_download_url() {
|
2024-12-01 10:16:27 -05:00
|
|
|
DOWNLOAD_URL="https://github.com/9seconds/mtg/releases/download/$VERSION/mtg-${VERSION_MIN}-${sysName}-${ARCH}.tar.gz"
|
2024-12-01 08:51:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# download file
|
|
|
|
|
download_file() {
|
|
|
|
|
url="${1}"
|
|
|
|
|
destination="${2}"
|
|
|
|
|
|
|
|
|
|
printf "Fetching ${url} \n\n"
|
|
|
|
|
|
|
|
|
|
if test -x "$(command -v curl)"; then
|
|
|
|
|
code=$(curl --connect-timeout 15 -w '%{http_code}' -L "${url}" -o "${destination}")
|
|
|
|
|
elif test -x "$(command -v wget)"; then
|
|
|
|
|
code=$(wget -t2 -T15 -O "${destination}" --server-response "${url}" 2>&1 | awk '/^ HTTP/{print $2}' | tail -1)
|
|
|
|
|
else
|
|
|
|
|
printf "\e[1;31mNeither curl nor wget was available to perform http requests.\e[0m\n"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "${code}" != 200 ]; then
|
|
|
|
|
printf "\e[1;31mRequest failed with code %s\e[0m\n" $code
|
|
|
|
|
exit 1
|
|
|
|
|
else
|
|
|
|
|
printf "\n\e[1;33mDownload succeeded\e[0m\n"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# /www/server/mtproxy/mtg/mtg run /www/server/mtproxy/mt.toml
|
|
|
|
|
Install_app()
|
|
|
|
|
{
|
2024-12-01 10:16:27 -05:00
|
|
|
mkdir -p ${serverPath}/mtproxy
|
|
|
|
|
mkdir -p ${serverPath}/source/mtproxy
|
|
|
|
|
echo "${1}" > ${serverPath}/mtproxy/version.pl
|
2024-12-01 08:51:31 -05:00
|
|
|
|
2024-12-01 10:16:27 -05:00
|
|
|
if [ "$OSNAME" == "centos" ]; then
|
2024-12-01 08:51:31 -05:00
|
|
|
yum install -y golang golang-src
|
2024-12-01 10:16:27 -05:00
|
|
|
elif [ "$OSNAME" == "amazon" ]; then
|
2024-12-01 08:51:31 -05:00
|
|
|
yum install -y golang golang-src
|
2024-12-01 10:16:27 -05:00
|
|
|
elif [ "$OSNAME" == "rocky" ]; then
|
2024-12-01 09:00:04 -05:00
|
|
|
yum install -y golang golang-src
|
2024-12-01 10:16:27 -05:00
|
|
|
elif [ "$OSNAME" == "rhel" ]; then
|
2024-12-01 09:11:25 -05:00
|
|
|
yum install -y golang golang-src
|
2024-12-01 13:28:30 -05:00
|
|
|
elif [ "$OSNAME" == "opensuse" ]; then
|
|
|
|
|
zypper install -y golang golang-src
|
2024-12-01 10:16:27 -05:00
|
|
|
elif [ "$sysName" == "macos" ]; then
|
|
|
|
|
echo "macos"
|
2024-12-01 08:51:31 -05:00
|
|
|
else
|
|
|
|
|
apt install -y golang golang-src
|
|
|
|
|
fi
|
|
|
|
|
|
2024-12-01 10:16:27 -05:00
|
|
|
if [ "$sysName" == "darwin" ]; then
|
|
|
|
|
ARCH=arm64
|
|
|
|
|
DOWNLOAD_URL="https://github.com/9seconds/mtg/releases/download/$VERSION/mtg-${VERSION_MIN}-${sysName}-arm64.tar.gz"
|
|
|
|
|
elif [ "$sysName" != "macos" ]; then
|
|
|
|
|
get_arch
|
|
|
|
|
get_download_url
|
|
|
|
|
else
|
|
|
|
|
echo "else"
|
|
|
|
|
fi
|
2024-12-01 08:51:31 -05:00
|
|
|
|
|
|
|
|
DOWNLOAD_FILE="$(mktemp).tar.gz"
|
|
|
|
|
download_file $DOWNLOAD_URL $DOWNLOAD_FILE
|
|
|
|
|
|
|
|
|
|
tar -C "$TARGET_DIR" -zxf $DOWNLOAD_FILE
|
|
|
|
|
rm -rf $DOWNLOAD_FILE
|
|
|
|
|
|
|
|
|
|
if [ -d ${serverPath}/mtproxy/mtg ];then
|
|
|
|
|
rm -rf ${serverPath}/mtproxy/mtg
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# cd ${serverPath}/mtproxy
|
|
|
|
|
# curl -s https://core.telegram.org/getProxySecret -o proxy-secret
|
|
|
|
|
# curl -s https://core.telegram.org/getProxyConfig -o proxy-multi.conf
|
|
|
|
|
|
|
|
|
|
|
2024-12-01 10:16:27 -05:00
|
|
|
mv ${serverPath}/mtproxy/mtg-${VERSION_MIN}-${sysName}-${ARCH} ${serverPath}/mtproxy/mtg
|
2024-12-01 08:57:23 -05:00
|
|
|
echo '安装完成'
|
2024-12-01 08:51:31 -05:00
|
|
|
|
|
|
|
|
#初始化
|
|
|
|
|
cd ${rootPath} && python3 ${rootPath}/plugins/mtproxy/index.py start
|
|
|
|
|
cd ${rootPath} && python3 ${rootPath}/plugins/mtproxy/index.py initd_install
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Uninstall_app()
|
|
|
|
|
{
|
|
|
|
|
if [ -f /usr/lib/systemd/system/mtproxy.service ];then
|
|
|
|
|
systemctl stop mtproxy
|
|
|
|
|
rm -rf /usr/lib/systemd/system/mtproxy.service
|
|
|
|
|
systemctl daemon-reload
|
|
|
|
|
fi
|
|
|
|
|
rm -rf ${serverPath}/mtproxy
|
2024-12-01 08:57:23 -05:00
|
|
|
echo '卸载完成'
|
2024-12-01 08:51:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
action=$1
|
|
|
|
|
if [ "${1}" == 'install' ];then
|
|
|
|
|
Install_app $2
|
|
|
|
|
else
|
|
|
|
|
Uninstall_app $2
|
|
|
|
|
fi
|