optimize
This commit is contained in:
71
frpc_linux_install.sh
Normal file → Executable file
71
frpc_linux_install.sh
Normal file → Executable file
@@ -16,18 +16,9 @@ WORK_PATH=$(dirname $(readlink -f $0))
|
||||
FRP_NAME=frpc
|
||||
FRP_VERSION=0.39.1
|
||||
FRP_PATH=/usr/local/frp
|
||||
PROXY_URL="https://ghproxy.com/"
|
||||
|
||||
if [ $(uname -m) = "x86_64" ]; then
|
||||
export PLATFORM=amd64
|
||||
else if [ $(uname -m) = "aarch64" ]; then
|
||||
export PLATFORM=arm64
|
||||
fi
|
||||
fi
|
||||
|
||||
FILE_NAME=frp_${FRP_VERSION}_linux_${PLATFORM}
|
||||
|
||||
|
||||
# 判断是否安装 frpc
|
||||
# check frpc
|
||||
if [ -f "/usr/local/frp/${FRP_NAME}" ] || [ -f "/usr/local/frp/${FRP_NAME}.ini" ] || [ -f "/lib/systemd/system/${FRP_NAME}.service" ];then
|
||||
echo -e "${Green}=========================================================================${Font}"
|
||||
echo -e "${RedBG}当前已退出脚本.${Font}"
|
||||
@@ -38,21 +29,65 @@ if [ -f "/usr/local/frp/${FRP_NAME}" ] || [ -f "/usr/local/frp/${FRP_NAME}.ini"
|
||||
echo -e "${Red}rm -rf /usr/local/frp/${FRP_NAME}.ini${Font}"
|
||||
echo -e "${Red}rm -rf /lib/systemd/system/${FRP_NAME}.service${Font}"
|
||||
echo -e "${Green}=========================================================================${Font}"
|
||||
exit 2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
# 判断 frpc 进程并 kill
|
||||
while ! test -z "$(ps -A | grep -w ${FRP_NAME})"; do
|
||||
FRPCPID=$(ps -A | grep -w ${FRP_NAME} | awk 'NR==1 {print $1}')
|
||||
kill -9 $FRPCPID
|
||||
done
|
||||
|
||||
# check pkg
|
||||
if type apt-get >/dev/null 2>&1 ; then
|
||||
if ! type wget >/dev/null 2>&1 ; then
|
||||
apt-get install wget -y
|
||||
fi
|
||||
if ! type curl >/dev/null 2>&1 ; then
|
||||
apt-get install curl -y
|
||||
fi
|
||||
fi
|
||||
|
||||
if type yum >/dev/null 2>&1 ; then
|
||||
if ! type wget >/dev/null 2>&1 ; then
|
||||
yum install wget -y
|
||||
fi
|
||||
if ! type curl >/dev/null 2>&1 ; then
|
||||
yum install curl -y
|
||||
fi
|
||||
fi
|
||||
|
||||
# check network
|
||||
GOOGLE_HTTP_CODE=$(curl -o /dev/null --connect-timeout 5 --max-time 8 -s --head -w "%{http_code}" "https://www.google.com")
|
||||
PROXY_HTTP_CODE=$(curl -o /dev/null --connect-timeout 5 --max-time 8 -s --head -w "%{http_code}" "${PROXY_URL}")
|
||||
|
||||
# check arch
|
||||
if [ $(uname -m) = "x86_64" ]; then
|
||||
PLATFORM=amd64
|
||||
fi
|
||||
|
||||
if [ $(uname -m) = "aarch64" ]; then
|
||||
PLATFORM=arm64
|
||||
fi
|
||||
|
||||
FILE_NAME=frp_${FRP_VERSION}_linux_${PLATFORM}
|
||||
|
||||
# download
|
||||
if [ $GOOGLE_HTTP_CODE == "200" ]; then
|
||||
wget -P ${WORK_PATH} https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}/${FILE_NAME}.tar.gz -O ${FILE_NAME}.tar.gz
|
||||
else
|
||||
if [ $PROXY_HTTP_CODE == "200" ]; then
|
||||
wget -P ${WORK_PATH} ${PROXY_URL}https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}/${FILE_NAME}.tar.gz -O ${FILE_NAME}.tar.gz
|
||||
else
|
||||
echo -e "${Red}检测 GitHub Proxy 代理失效 开始使用官方地址下载${Font}"
|
||||
wget -P ${WORK_PATH} https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}/${FILE_NAME}.tar.gz -O ${FILE_NAME}.tar.gz
|
||||
fi
|
||||
fi
|
||||
tar -zxvf ${FILE_NAME}.tar.gz
|
||||
|
||||
mkdir -p ${FRP_PATH}
|
||||
wget -P ${WORK_PATH} https://ghproxy.com/https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}/${FILE_NAME}.tar.gz -O ${FILE_NAME}.tar.gz && \
|
||||
tar -zxvf ${FILE_NAME}.tar.gz && \
|
||||
mv ${FILE_NAME}/${FRP_NAME} ${FRP_PATH}
|
||||
|
||||
# configure frpc.ini
|
||||
cat >${FRP_PATH}/${FRP_NAME}.ini <<EOF
|
||||
[common]
|
||||
server_addr = frp.freefrp.net
|
||||
@@ -66,6 +101,7 @@ local_port = 5000
|
||||
custom_domains = yourdomain${RANDOM}.com
|
||||
EOF
|
||||
|
||||
# configure systemd
|
||||
cat >/lib/systemd/system/${FRP_NAME}.service <<EOF
|
||||
[Unit]
|
||||
Description=Frp Server Service
|
||||
@@ -82,9 +118,12 @@ ExecStart=/usr/local/frp/${FRP_NAME} -c /usr/local/frp/${FRP_NAME}.ini
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# finish install
|
||||
systemctl daemon-reload
|
||||
sudo systemctl start ${FRP_NAME}
|
||||
sudo systemctl enable ${FRP_NAME}
|
||||
|
||||
# clean
|
||||
rm -rf ${WORK_PATH}/${FILE_NAME}.tar.gz ${WORK_PATH}/${FILE_NAME} ${FRP_NAME}_linux_install.sh
|
||||
|
||||
echo -e "${Green}====================================================================${Font}"
|
||||
|
||||
Reference in New Issue
Block a user