From 017479b5c4bb2622a191a06231923c3562eb6444 Mon Sep 17 00:00:00 2001 From: xishang0128 Date: Fri, 1 Dec 2023 16:25:26 +0800 Subject: [PATCH] add meta-rule-set --- .github/workflows/run.yml | 37 +++++++++++++++++++++++++++++++++++++ resouces/convert-clash.sh | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100755 resouces/convert-clash.sh diff --git a/.github/workflows/run.yml b/.github/workflows/run.yml index 77041186dc..3034e99173 100644 --- a/.github/workflows/run.yml +++ b/.github/workflows/run.yml @@ -243,6 +243,29 @@ jobs: chmod 755 mosdns sing-box convert.sh && ./convert.sh rm mosdns* sing-box* convert.sh geoip.dat geosite.db LICENSE README.md config.yaml + - name: Convert geo to meta-rule-set + env: + NO_SKIP: true + run: | + mkdir -p ./meta-rule/geo + cp ./geoip.dat ./custom/publish/geosite.dat ./resouces/convert-clash.sh ./meta-rule/geo/ + cd ./meta-rule/geo + wget https://github.com/IrineSistiana/mosdns/releases/download/v4.5.3/mosdns-linux-amd64.zip -O mosdns.zip && unzip mosdns.zip + chmod 755 mosdns convert-clash.sh && ./convert-clash.sh + rm mosdns* convert-clash.sh geoip.dat geosite.dat LICENSE README.md config.yaml + + + - name: Convert geo-lite to meta-rule-set + env: + NO_SKIP: true + run: | + mkdir -p ./meta-rule/geo-lite + cp ./geoip-lite.dat ./meta-rule/geo-lite/geoip.dat && cp ./community/geosite-lite.dat ./meta-rule/geo-lite/geosite.dat && cp ./resouces/convert-clash.sh ./meta-rule/geo-lite/ + cd ./meta-rule/geo-lite + wget https://github.com/IrineSistiana/mosdns/releases/download/v4.5.3/mosdns-linux-amd64.zip -O mosdns.zip && unzip mosdns.zip + chmod 755 mosdns convert-clash.sh && ./convert-clash.sh + rm mosdns* convert-clash.sh geoip.dat geosite.dat LICENSE README.md config.yaml + - name: Move and zip files run: | mkdir -p ./publish/ @@ -316,6 +339,20 @@ jobs: git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}" git push -f -u origin sing + - name: Git push assets to "meta-rule" branch + run: | + cd meta-rule || exit 1 + ls + git init + git config --local user.name "github-actions[bot]" + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + git checkout -b meta + git add . + git commit -m "Released on ${{ env.BUILDTIME }}" + git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}" + git push -f -u origin meta + + - name: Purge jsdelivr CDN run: | cd publish || exit 1 diff --git a/resouces/convert-clash.sh b/resouces/convert-clash.sh new file mode 100755 index 0000000000..3355839648 --- /dev/null +++ b/resouces/convert-clash.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +mkdir -p geoip +./mosdns v2dat unpack-ip -o ./geoip/ geoip.dat +list=($(ls ./geoip | sed 's/geoip_//g' | sed 's/\.txt//g')) +for ((i = 0; i < ${#list[@]}; i++)); do + # echo "${list[i]}" + mv ./geoip/geoip_${list[i]}.txt ./geoip/${list[i]}.list + echo "payload:" >./geoip/${list[i]}.yaml + cat ./geoip/${list[i]}.list | sed 's/^/- "/g' | sed 's/$/"/g' >>./geoip/${list[i]}.yaml +done + +mkdir -p geosite +./mosdns v2dat unpack-domain -o ./geosite/ geosite.dat +list=($(ls ./geosite | sed 's/geosite_//g' | sed 's/\.txt//g')) +for ((i = 0; i < ${#list[@]}; i++)); do + # echo "${list[i]}" + mv ./geosite/geosite_${list[i]}.txt ./geosite/${list[i]}.list + sed -i '/^#/d' geosite/${list[i]}.list + sed -i '/^keyword:/d' geosite/${list[i]}.list + sed -i '/^regexp:/d' geosite/${list[i]}.list + sed -i 's/^/+./g' ./geosite/${list[i]}.list + sed -i 's/+.full://g' ./geosite/${list[i]}.list + sed -i 's/+.domain:/+./g' ./geosite/${list[i]}.list + echo "payload:" >./geosite/${list[i]}.yaml + cat ./geosite/${list[i]}.list | sed 's/^/- "/g' | sed 's/$/"/g' >>./geosite/${list[i]}.yaml +done + +#mkdir -p mixed +#for file in $(find geoip -type f | grep -v srs | awk -F "/" '{print $NF}'); do +# if [ -n "$(find geosite -type f -iname "$file")" ]; then +# file=$(find ./geosite -type f -iname "$file" | awk -F"/" '{print $NF}' | sed 's/\.json//g') +# head -n -3 ./geoip/${file}.json >./mixed/${file}.json +# sed -i 's/]/],/g' ./mixed/${file}.json +# tail -n +5 ./geosite/${file}.json >>./mixed/${file}.json +# ./sing-box rule-set compile ./mixed/${file}.json -o ./mixed/${file}.srs +# fi +#done