Skip to content

bin_update

bin_update #69

Workflow file for this run

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