Update optimize shell script for Linux X86 and ARM

This commit is contained in:
Stille
2021-05-31 12:36:40 +08:00
parent 6f9ce8452b
commit 2ff4880710
3 changed files with 135 additions and 48 deletions

View File

@@ -7,25 +7,25 @@
> *docker image support for X86 and ARM* > *docker image support for X86 and ARM*
## 更新 ## 更新
**2021-05-31** 更新国内镜像方便使用
**2021-05-31** 目前 X86 群晖 DMS 7.0 可直接使用 Linux 版本脚本,已实测.由于没有 ARM 版可尝试,请自行尝试.
**2021-05-31** 更新 Linux 一键安装脚本同时支持 X86 和 ARM
**2021-05-29** 更新从`0.36.2`版本起 docker 镜像同时支持 X86 和 ARM **2021-05-29** 更新从`0.36.2`版本起 docker 镜像同时支持 X86 和 ARM
## 使用说明 ## 使用说明
以下分为四种部署方法,请根据实际情况自行选择: 以下分为四种部署方法,请根据实际情况自行选择:
- 群晖NAS docker 安装 **[支持 docker 的群晖机型首选]** - 群晖 NAS docker 安装 **[支持 docker 的群晖机型首选]** [点击查看教程](https://www.ioiox.com/archives/26.html)
- 群晖NAS 一键脚本安装 **[不支持 docker 的群晖机型]** - 群晖 NAS 一键脚本安装 **[不支持 docker 的群晖机型]** [点击查看教程](https://www.ioiox.com/archives/6.html)
- Linux 服务器 一键脚本安装 **[内网 Linux 服务器或虚拟机]** - Linux 服务器 一键脚本安装 **[内网 Linux 服务器或虚拟机]**
- Linux 服务器 docker 安装 **[内网 Linux 服务器或虚拟机]** - Linux 服务器 docker 安装 **[内网 Linux 服务器或虚拟机]**
### 群晖NAS docker 安装
[群晖NAS使用Docker安装配置frpc内网穿透教程](https://www.ioiox.com/archives/26.html)
### 群晖NAS 一键脚本安装
[群晖NAS安装配置免费frp内网穿透教程](https://www.ioiox.com/archives/6.html)
### Linux 服务器 一键脚本安装 ### Linux 服务器 一键脚本安装
> *本脚本目前同时支持 Linux X86 和 ARM 架构*
安装 安装
```shell ```shell
wget https://raw.githubusercontent.com/stilleshan/frpc/master/frpc_linux_install.sh && chmod +x frpc_linux_install.sh && ./frpc_linux_install.sh # 国内 gitee 镜像
wget https://gitee.com/stilleshan/frpc/raw/master/frpc_linux_install.sh && chmod +x frpc_linux_install.sh && ./frpc_linux_install.sh
``` ```
使用 使用
@@ -38,7 +38,8 @@ sudo systemctl restart frpc
卸载 卸载
```shell ```shell
wget https://raw.githubusercontent.com/stilleshan/frpc/master/frpc_linux_uninstall.sh && chmod +x frpc_linux_uninstall.sh && ./frpc_linux_uninstall.sh # 国内 gitee 镜像
wget https://gitee.com/stilleshan/frpc/raw/master/frpc_linux_uninstall.sh && chmod +x frpc_linux_uninstall.sh && ./frpc_linux_uninstall.sh
``` ```
### Linux 服务器 docker 安装 ### Linux 服务器 docker 安装
@@ -46,8 +47,8 @@ wget https://raw.githubusercontent.com/stilleshan/frpc/master/frpc_linux_uninsta
**git clone** 本仓库,并正确配置 **frpc.ini** 文件. **git clone** 本仓库,并正确配置 **frpc.ini** 文件.
```shell ```shell
git clone https://github.com/stilleshan/frpc.git git clone https://gitee.com/stilleshan/frpc.git
# git clone 本仓库 # git clone 本仓库 gitee 镜像
vi /root/frpc/frpc.ini vi /root/frpc/frpc.ini
# 配置 frpc.ini 文件 # 配置 frpc.ini 文件
``` ```

View File

@@ -1,28 +1,95 @@
#!/bin/sh #!/usr/bin/env bash
FRP_VERSION="0.36.2" PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
REPO="stilleshan/frpc" export PATH
WORK_PATH=$(dirname $(readlink -f $0))
# 创建frp文件夹 # fonts color
mkdir -p /usr/local/frp && \ Green="\033[32m"
# 下载并移动frpc文件 Red="\033[31m"
wget -P ${WORK_PATH} https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}/frp_${FRP_VERSION}_linux_amd64.tar.gz && \ Yellow="\033[33m"
tar -zxvf frp_${FRP_VERSION}_linux_amd64.tar.gz && \ GreenBG="\033[42;37m"
cd frp_${FRP_VERSION}_linux_amd64 && \ RedBG="\033[41;37m"
mv frpc /usr/local/frp && \ Font="\033[0m"
# 下载frpc.in和frpc.service # fonts color
wget -P /usr/local/frp https://raw.githubusercontent.com/${REPO}/master/frpc.ini && \
wget -P /lib/systemd/system https://raw.githubusercontent.com/${REPO}/master/frpc.service && \ # variable
systemctl daemon-reload && \ WORK_PATH=$(dirname $(readlink -f $0))
# 启动frpc FRP_NAME=frpc
sudo systemctl start frpc && \ FRP_VERSION=0.36.2
sudo systemctl enable frpc && \ FRP_PATH=/usr/local/frp
# 删除多余文件
cd ${WORK_PATH} && \ if [ $(uname -m) = "x86_64" ]; then
rm -rf frp_${FRP_VERSION}_linux_amd64 frp_${FRP_VERSION}_linux_amd64.tar.gz frpc_linux_install.sh export PLATFORM=amd64
echo "=======================================================" &&\ else if [ $(uname -m) = "aarch64" ]; then
echo -e "\033[32m安装成功,请先修改 frpc.ini 文件,确保格式及配置正确无误!\033[0m" && \ export PLATFORM=arm64
echo -e "\033[31mvi /usr/local/frp/frpc.ini \033[0m" && \ fi
echo -e "\033[32m修改完毕后执行以下命令重启服务:\033[0m" && \ fi
echo -e "\033[31msudo systemctl restart frpc\033[0m" && \
echo "=======================================================" FILE_NAME=frp_${FRP_VERSION}_linux_${PLATFORM}
# 判断是否安装 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}"
echo -e "${Green}检查到服务器已安装${Font} ${Red}${FRP_NAME}${Font}"
echo -e "${Green}请手动确认和删除${Font} ${Red}/usr/local/frp/${Font} ${Green}目录下的${Font} ${Red}${FRP_NAME}${Font} ${Green}${Font} ${Red}/${FRP_NAME}.ini${Font} ${Green}文件以及${Font} ${Red}/lib/systemd/system/${FRP_NAME}.service${Font} ${Green}文件,再次执行本脚本.${Font}"
echo -e "${Green}参考命令如下:${Font}"
echo -e "${Red}rm -rf /usr/local/frp/${FRP_NAME}${Font}"
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
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
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}
cat >${FRP_PATH}/${FRP_NAME}.ini <<EOF
[common]
server_addr = frp.freefrp.net
server_port = 7000
token = freefrp.net
[web1_${RANDOM}]
type = http
local_ip = 192.168.1.2
local_port = 5000
custom_domains = yourdomain${RANDOM}.com
EOF
cat >/lib/systemd/system/${FRP_NAME}.service <<EOF
[Unit]
Description=Frp Server Service
After=network.target syslog.target
Wants=network.target
[Service]
Type=simple
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/frp/${FRP_NAME} -c /usr/local/frp/${FRP_NAME}.ini
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
sudo systemctl start ${FRP_NAME}
sudo systemctl enable ${FRP_NAME}
rm -rf ${WORK_PATH}/${FILE_NAME}.tar.gz ${WORK_PATH}/${FILE_NAME} ${FRP_NAME}_linux_install.sh
echo -e "${Green}====================================================================${Font}"
echo -e "${Green}安装成功,请先修改 ${FRP_NAME}.ini 文件,确保格式及配置正确无误!${Font}"
echo -e "${Red}vi /usr/local/frp/${FRP_NAME}.ini${Font}"
echo -e "${Green}修改完毕后执行以下命令重启服务:${Font}"
echo -e "${Red}sudo systemctl restart ${FRP_NAME}${Font}"
echo -e "${Green}====================================================================${Font}"

View File

@@ -1,13 +1,32 @@
#!/bin/sh #!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# fonts color
Green="\033[32m"
Red="\033[31m"
Yellow="\033[33m"
GreenBG="\033[42;37m"
RedBG="\033[41;37m"
Font="\033[0m"
# fonts color
# variable
WORK_PATH=$(dirname $(readlink -f $0))
FRP_NAME=frpc
FRP_VERSION=0.36.2
FRP_PATH=/usr/local/frp
# 停止frpc # 停止frpc
sudo systemctl stop frpc && \ sudo systemctl stop ${FRP_NAME}
# 删除frpc # 删除frpc
rm -rf /usr/local/frp && \ rm -rf ${FRP_PATH}
# 删除frpc.service # 删除frpc.service
rm -rf /lib/systemd/system/frpc.service && \ rm -rf /lib/systemd/system/${FRP_NAME}.service
sudo systemctl daemon-reload && \ sudo systemctl daemon-reload
# 删除本文件 # 删除本文件
rm -rf frpc_linux_uninstall.sh rm -rf ${FRP_NAME}_linux_uninstall.sh
echo "============================" &&\
echo -e "\033[32m卸载成功,相关文件已清理完毕!\033[0m" && \ echo -e "${Green}============================${Font}"
echo "============================" echo -e "${Green}卸载成功,相关文件已清理完毕!${Font}"
echo -e "${Green}============================${Font}"