Cloudflared 自动更新脚本
#!/bin/bash
CURRENT_VERSION=$(cloudflared --version | grep -oP 'version \K[^ ]+')
# 获取最新版本号
REPO="cloudflare/cloudflared"
API_URL="https://api.github.com/repos/${REPO}/releases/latest"
response=$(curl -s $API_URL)
# 提取所需的字段
LATEST_VERSION=$(echo $response | grep -oP '"tag_name": "\K[^"]+')
# 输出结果
echo "$REPO :"
echo "当前版本: $(cloudflared --version | grep -oP 'version \K[^ ]+')"
echo "最新版本: $LATEST_VERSION"
# 检查版本号
if [[ $LATEST_VERSION != $CURRENT_VERSION ]]; then
echo "发现新版本,开始更新"
cd ~
# 更新命令。此处为 AMD64 架构,发行版为 CentOS ,不同的 Linux 发行版、不同的系统架构命令不同
curl -L --output cloudflared.rpm https://ghproxy.net/https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-x86_64.rpm
sudo yum localinstall -y cloudflared.rpm
rm -f cloudflared.rpm
# 重启服务
systemctl restart cloudflared.service
echo "更新完成"
echo "当前版本: $(cloudflared --version | grep -oP 'version \K[^ ]+')"
else
echo "当前已是最新版本"
fi
1 个赞
示例1:
cloudflare/cloudflared :
当前版本: 2024.3.0
最新版本: 2024.4.0
发现新版本,开始更新
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
1 16.8M 1 211k 0 0 63740 0 0:04:38 0:00:03 0:04:35 63721
8 16.8M 8 1438k 0 0 355k 0 0:00:48 0:00:04 0:00:44 355k
34 16.8M 34 5972k 0 0 1182k 0 0:00:14 0:00:05 0:00:09 1182k
54 16.8M 54 9496k 0 0 1527k 0 0:00:11 0:00:06 0:00:05 1542k
90 16.8M 90 15.2M 0 0 2212k 0 0:00:07 0:00:07 --:--:-- 2604k
100 16.8M 100 16.8M 0 0 2357k 0 0:00:07 0:00:07 --:--:-- 4327k
Last metadata expiration check: 0:40:36 ago on Sun 14 Apr 2024 10:03:42 AM CST.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Upgrading:
cloudflared x86_64 2024.4.0-1 @commandline 17 M
Transaction Summary
================================================================================
Upgrade 1 Package
Total size: 17 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Upgrading : cloudflared-2024.4.0-1.x86_64 1/2
Running scriptlet: cloudflared-2024.4.0-1.x86_64 1/2
Cleanup : cloudflared-2024.3.0-1.x86_64 2/2
Running scriptlet: cloudflared-2024.3.0-1.x86_64 2/2
Verifying : cloudflared-2024.4.0-1.x86_64 1/2
Verifying : cloudflared-2024.3.0-1.x86_64 2/2
Upgraded:
cloudflared-2024.4.0-1.x86_64
Complete!
更新完成
当前版本: 2024.4.0
示例2:
cloudflare/cloudflared :
当前版本: 2024.4.0
最新版本: 2024.4.0
当前已是最新版本