forked from juewuy/ShellCrash
-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (153 loc) · 7.14 KB
/
bin_update.yml
File metadata and controls
163 lines (153 loc) · 7.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: bin_update
on:
schedule:
- cron: "0 18 * * *" # UTC 18 = 北京时间次日凌晨 2 点
workflow_dispatch:
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Checkout update branch (ignore if missing)
uses: actions/checkout@v5
with:
ref: update
fetch-depth: 1
persist-credentials: false # 禁用默认凭据(我们用 token push)
- name: Apt Update & Update CA
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo apt-get update
sudo apt-get -y install unzip curl git tar ca-certificates
sudo update-ca-certificates
cp -f /etc/ssl/certs/ca-certificates.crt bin/fix/ca-certificates.crt
- name: Update Dashboard
run: |
DASH="$GITHUB_WORKSPACE/bin/dashboard"
TEMP="$DASH/.tmp" # 临时目录
mkdir -p "$TEMP"
echo "下载面板..."
# 下载文件到临时目录
curl -kfSL -o "$TEMP/meta_yacd.zip" https://github.com/MetaCubeX/Yacd-meta/archive/gh-pages.zip
curl -kfSL -o "$TEMP/meta_xd.zip" https://github.com/MetaCubeX/metacubexd/archive/gh-pages.zip
curl -kfSL -o "$TEMP/zashboard.zip" https://github.com/Zephyruso/zashboard/releases/latest/download/dist-cdn-fonts.zip
########################################
# Yacd-meta
########################################
unzip -o "$TEMP/meta_yacd.zip" -d "$TEMP/yacd" > /dev/null
# 删除字体文件
find "$TEMP/yacd" \( -name "*.ttf" -o -name "*.woff" -o -name "*.woff2" \) -delete
# 确认子目录名称
subdir=$(find "$TEMP/yacd" -maxdepth 1 -type d ! -path "$TEMP/yacd" | head -n1)
# 打包
tar -zcvf "$DASH/meta_yacd.tar.gz" -C "$subdir" . > /dev/null
########################################
# metacubexd
########################################
unzip -o "$TEMP/meta_xd.zip" -d "$TEMP/xd" > /dev/null
# 删除字体文件
find "$TEMP/xd" \( -name "*.ttf" -o -name "*.woff" -o -name "*.woff2" \) -delete
# 确认子目录名称
subdir=$(find "$TEMP/xd" -maxdepth 1 -type d ! -path "$TEMP/xd" | head -n1)
# 打包
tar -zcvf "$DASH/meta_xd.tar.gz" -C "$subdir" . > /dev/null
########################################
# zashboard
########################################
unzip -o "$TEMP/zashboard.zip" -d "$TEMP/zash" > /dev/null
if [ -d "$TEMP/zash/dist" ]; then
ZDIR="$TEMP/zash/dist"
elif [ -d "$TEMP/zash/dist-cdn-fonts/dist" ]; then
ZDIR="$TEMP/zash/dist-cdn-fonts/dist"
else
echo "未找到 dist 目录"
exit 1
fi
# 删除字体文件
find "$ZDIR" \( -name "*.ttf" -o -name "*.woff" -o -name "*.woff2" \) -delete
echo 'board.zash.run.place' > "$ZDIR/CNAME"
tar -zcvf "$DASH/zashboard.tar.gz" -C "$ZDIR" . > /dev/null
########################################
# 一步清理所有临时文件(核心)
########################################
rm -rf "$TEMP"
echo "面板更新完成!"
- name: Update Geodata
run: |
cd bin
curl -kfSL -o geodata/cn_mini.mmdb https://raw.githubusercontent.com/Hackl0us/GeoIP2-CN/release/Country.mmdb
curl -kfSL -o geodata/china_ip_list.txt https://raw.githubusercontent.com/ChanthMiao/China-IPv4-List/release/cn.txt
curl -kfSL -o geodata/china_ipv6_list.txt https://raw.githubusercontent.com/ChanthMiao/China-IPv6-List/release/cn6.txt
curl -kfSL -o geodata/geosite.dat https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat
curl -kfSL -o geodata/srs_geoip_cn.srs https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/cnip.srs
curl -kfSL -o geodata/srs_geosite_cn.srs https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/cn.srs
curl -kfSL -o geodata/mrs_geosite_cn.mrs https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/cn.mrs
# 下载规则集
curl -kfSL -o mihomo-ruleset.zip https://github.com/DustinWin/ruleset_geodata/archive/refs/heads/mihomo-ruleset.zip
curl -kfSL -o sing-box-ruleset.zip https://github.com/DustinWin/ruleset_geodata/archive/refs/heads/sing-box-ruleset.zip
##########################################
# 解压
unzip -o mihomo-ruleset.zip > /dev/null
unzip -o sing-box-ruleset.zip > /dev/null
##########################################
# 处理 mihomo 规则 (mrs)
if [ -d ruleset_geodata-mihomo-ruleset ]; then
cd ruleset_geodata-mihomo-ruleset
# 删除不需要的 .list和ads
find . -type f -name "*.list" -delete
find . -type f -name "ads.mrs" -delete
# 输出文件放到上级目录,避免 tar 自己包含自己
tar -zcvf ../mrs.tar.gz . > /dev/null
cd ..
else
echo "错误:未找到 ruleset_geodata-mihomo-ruleset"
fi
##########################################
# 处理 sing-box 规则 (srs)
if [ -d ruleset_geodata-sing-box-ruleset ]; then
cd ruleset_geodata-sing-box-ruleset
# 删除 .json和ads.srs
find . -type f -name "*.json" -delete
find . -type f -name "ads.srs" -delete
# 同样避免目录内生成 tar 导致 file-changed 错误
tar -zcvf ../srs.tar.gz . > /dev/null
cd ..
else
echo "错误:未找到 ruleset_geodata-sing-box-ruleset"
fi
##########################################
# 移动到 geodata
mv -f mrs.tar.gz geodata/
mv -f srs.tar.gz geodata/
# 删除目录
rm -rf ruleset_geodata-mihomo-ruleset
rm -rf ruleset_geodata-sing-box-ruleset
rm -rf mihomo-ruleset.zip
rm -rf sing-box-ruleset.zip
sed -i "s/GeoIP_v=.*/GeoIP_v=$(date '+%Y%m%d')/" version
echo 数据库及根证书文件更新完成!
- name: Rebuild update branch with no history
run: |
# 彻底删除历史记录
rm -rf .git
# 重新初始化仓库
git init
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git add .
git commit -m "自动更新最新Dashboard、Geodata数据库及根证书"
# 强制推送覆盖 update 分支
git branch -M update
git remote add origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
git push -f origin update
#刷新cdn缓存
sleep 60
find bin/dashboard bin/geodata -type f 2>/dev/null | while read -r file; do
curl -s "https://purge.jsdelivr.net/gh/juewuy/ShellClash@update/${file#bin/}" || true
done
curl -s https://purge.jsdelivr.net/gh/juewuy/ShellClash@update/bin/version || true
- name: Cleanup Workflow
uses: Mattraks/delete-workflow-runs@main
with:
retain_days: 0
keep_minimum_runs: 1