Simple Linux Panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mdserver-web/plugins/mtproxy/install.sh

139 lines
3.4 KiB

5 months ago
#!/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")
5 months ago
sysArch=`arch`
sysName=`uname`
5 months ago
bash ${rootPath}/scripts/getos.sh
5 months ago
echo "bash ${rootPath}/scripts/getos.sh"
5 months ago
OSNAME=`cat ${rootPath}/data/osname.pl`
VERSION_MIN=2.1.7
5 months ago
VERSION=v${VERSION_MIN}
sysName=$(uname | tr '[:upper:]' '[:lower:]')
5 months ago
ARCH=amd64
get_arch() {
echo "package main
import (
\"fmt\"
\"runtime\"
)
func main() { fmt.Println(runtime.GOARCH) }" > /tmp/go_arch.go
ARCH=$(go run /tmp/go_arch.go)
5 months ago
echo "ARCH:${ARCH}"
5 months ago
}
TARGET_DIR="${serverPath}/mtproxy"
get_download_url() {
5 months ago
DOWNLOAD_URL="https://github.com/9seconds/mtg/releases/download/$VERSION/mtg-${VERSION_MIN}-${sysName}-${ARCH}.tar.gz"
5 months ago
}
# 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()
{
5 months ago
mkdir -p ${serverPath}/mtproxy
mkdir -p ${serverPath}/source/mtproxy
echo "${1}" > ${serverPath}/mtproxy/version.pl
5 months ago
5 months ago
if [ "$OSNAME" == "centos" ]; then
5 months ago
yum install -y golang golang-src
5 months ago
elif [ "$OSNAME" == "amazon" ]; then
5 months ago
yum install -y golang golang-src
5 months ago
elif [ "$OSNAME" == "rocky" ]; then
5 months ago
yum install -y golang golang-src
5 months ago
elif [ "$OSNAME" == "rhel" ]; then
5 months ago
yum install -y golang golang-src
5 months ago
elif [ "$OSNAME" == "opensuse" ]; then
zypper install -y golang golang-src
5 months ago
elif [ "$sysName" == "macos" ]; then
echo "macos"
5 months ago
else
apt install -y golang golang-src
fi
5 months ago
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
5 months ago
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
5 months ago
mv ${serverPath}/mtproxy/mtg-${VERSION_MIN}-${sysName}-${ARCH} ${serverPath}/mtproxy/mtg
5 months ago
echo '安装完成'
5 months ago
#初始化
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
5 months ago
echo '卸载完成'
5 months ago
}
action=$1
if [ "${1}" == 'install' ];then
Install_app $2
else
Uninstall_app $2
fi