From ad85e0596f41a042f5bd71cb6989786a5f1354ee Mon Sep 17 00:00:00 2001 From: xishang0128 Date: Fri, 1 Dec 2023 12:19:39 +0800 Subject: [PATCH] add sing-rule-set --- .github/workflows/run.yml | 38 ++++++++++++++++++++++++++++++++++++++ resouces/convert.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 resouces/convert.sh diff --git a/.github/workflows/run.yml b/.github/workflows/run.yml index b3b8c21e5f..77041186dc 100644 --- a/.github/workflows/run.yml +++ b/.github/workflows/run.yml @@ -218,6 +218,31 @@ jobs: geo convert ip -i v2ray -o sing -f geoip-lite.db ./geoip-lite.dat geo convert ip -i v2ray -o meta -f geoip-lite.metadb ./geoip-lite.dat + - name: Convert geo to sing-rule-set + env: + NO_SKIP: true + run: | + mkdir -p ./sing-rule/geo + cp ./geoip.dat ./geosite.db ./resouces/convert.sh ./sing-rule/geo/ + cd ./sing-rule/geo + wget https://github.com/SagerNet/sing-box/releases/download/v1.8.0-alpha.1/sing-box-1.8.0-alpha.1-linux-amd64.tar.gz -O sing-box.tar.gz && tar zxvf sing-box.tar.gz && mv sing-box-1.8.0-alpha.1-linux-amd64/sing-box ./ && rm -r sing-box-1.8.0-alpha.1-linux-amd64 + wget https://github.com/IrineSistiana/mosdns/releases/download/v4.5.3/mosdns-linux-amd64.zip -O mosdns.zip && unzip mosdns.zip + 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-lite to sing-rule-set + env: + NO_SKIP: true + run: | + mkdir -p ./sing-rule/geo-lite + cp ./geoip-lite.dat ./sing-rule/geo-lite/geoip.dat && cp ./geosite-lite.db ./sing-rule/geo-lite/geosite.db && cp ./resouces/convert.sh ./sing-rule/geo-lite/ + cd ./sing-rule/geo-lite + wget https://github.com/SagerNet/sing-box/releases/download/v1.8.0-alpha.1/sing-box-1.8.0-alpha.1-linux-amd64.tar.gz -O sing-box.tar.gz && tar zxvf sing-box.tar.gz && mv sing-box-1.8.0-alpha.1-linux-amd64/sing-box ./ && rm -r sing-box-1.8.0-alpha.1-linux-amd64 + wget https://github.com/IrineSistiana/mosdns/releases/download/v4.5.3/mosdns-linux-amd64.zip -O mosdns.zip && unzip mosdns.zip + 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: Move and zip files run: | mkdir -p ./publish/ @@ -278,6 +303,19 @@ jobs: git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}" git push -f -u origin release + - name: Git push assets to "sing-rule" branch + run: | + cd sing-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 sing + 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 sing + - name: Purge jsdelivr CDN run: | cd publish || exit 1 diff --git a/resouces/convert.sh b/resouces/convert.sh new file mode 100644 index 0000000000..a0d52faa1f --- /dev/null +++ b/resouces/convert.sh @@ -0,0 +1,31 @@ +#!/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 + sed -i 's/^/ "/g' ./geoip/geoip_${list[i]}.txt + sed -i 's/$/",/g' ./geoip/geoip_${list[i]}.txt + sed -i '1s/^/{\n "version": 1,\n "rules": [\n {\n "ip_cidr": [\n/g' ./geoip/geoip_${list[i]}.txt + sed -i '$ s/,$/\n ]\n }\n ]\n}/g' ./geoip/geoip_${list[i]}.txt + mv ./geoip/geoip_${list[i]}.txt ./geoip/${list[i]}.json + ./sing-box rule-set compile "./geoip/${list[i]}.json" -o ./geoip/${list[i]}.srs +done + +list=($(./sing-box geosite list | sed 's/ (.*)$//g')) +mkdir -p geosite +for ((i = 0; i < ${#list[@]}; i++)); do + ./sing-box geosite export ${list[i]} -o ./geosite/${list[i]}.json + ./sing-box rule-set compile ./geosite/${list[i]}.json -o ./geosite/${list[i]}.srs +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