convert bm7

This commit is contained in:
xishang0128 2023-12-12 15:56:58 +08:00
parent 017479b5c4
commit fa1af62c07
No known key found for this signature in database
GPG Key ID: 44A1E10B5ADF68CB
2 changed files with 137 additions and 1 deletions

View File

@ -254,7 +254,6 @@ jobs:
chmod 755 mosdns convert-clash.sh && ./convert-clash.sh chmod 755 mosdns convert-clash.sh && ./convert-clash.sh
rm mosdns* convert-clash.sh geoip.dat geosite.dat LICENSE README.md config.yaml rm mosdns* convert-clash.sh geoip.dat geosite.dat LICENSE README.md config.yaml
- name: Convert geo-lite to meta-rule-set - name: Convert geo-lite to meta-rule-set
env: env:
NO_SKIP: true NO_SKIP: true
@ -266,6 +265,18 @@ jobs:
chmod 755 mosdns convert-clash.sh && ./convert-clash.sh chmod 755 mosdns convert-clash.sh && ./convert-clash.sh
rm mosdns* convert-clash.sh geoip.dat geosite.dat LICENSE README.md config.yaml rm mosdns* convert-clash.sh geoip.dat geosite.dat LICENSE README.md config.yaml
- name: Convert bm7-rule-set to sing-rule-set
env:
NO_SKIP: true
run: |
mkdir -p ./sing-rule/bm7
cp ./resouces/bm7.sh ./sing-rule/bm7/
cd ./sing-rule/bm7
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
ls
chmod 755 bm7.sh && ./bm7.sh
rm -r bm7.sh sing-box* rule
- name: Move and zip files - name: Move and zip files
run: | run: |
mkdir -p ./publish/ mkdir -p ./publish/

125
resouces/bm7.sh Executable file
View File

@ -0,0 +1,125 @@
#!/bin/bash
# 拉文件
if [ ! -d rule ]; then
git init
git remote add origin https://github.com/blackmatrix7/ios_rule_script.git
git config core.sparsecheckout true
echo "rule/Clash" >>.git/info/sparse-checkout
git pull --depth 1 origin master
rm -rf .git
fi
# 移动文件/目录到同一文件夹
list=($(ls ./rule/Clash/))
for ((i = 0; i < ${#list[@]}; i++)); do
if [ -z "$(ls ./rule/Clash/${list[i]} | grep '.yaml')" ]; then
directory=($(ls ./rule/Clash/${list[i]}))
for ((x = 0; x < ${#directory[@]}; x++)); do
mv ./rule/Clash/${list[i]}/${directory[x]} ./rule/Clash/${directory[x]}
done
rm -r ./rule/Clash/${list[i]}
fi
done
list=($(ls ./rule/Clash/))
for ((i = 0; i < ${#list[@]}; i++)); do
if [ -f "./rule/Clash/${list[i]}/${list[i]}_Classical.yaml" ]; then
mv ./rule/Clash/${list[i]}/${list[i]}_Classical.yaml ./rule/Clash/${list[i]}/${list[i]}.yaml
fi
done
# 处理文件
list=($(ls ./rule/Clash/))
for ((i = 0; i < ${#list[@]}; i++)); do
mkdir -p ${list[i]}
# 归类
# android package
if [ -n "$(cat ./rule/Clash/${list[i]}/${list[i]}.yaml | grep -v '#' | grep PROCESS | grep -v '\.exe' | grep '\.')" ]; then
cat ./rule/Clash/${list[i]}/${list[i]}.yaml | grep -v '#' | grep PROCESS | grep -v '\.exe' | grep '\.' | sed 's/ - PROCESS-NAME,//g' > ${list[i]}/package.json
fi
# process name
if [ -n "$(cat ./rule/Clash/${list[i]}/${list[i]}.yaml | grep -v '#' | grep PROCESS | grep -v '\.')" ]; then
cat ./rule/Clash/${list[i]}/${list[i]}.yaml | grep -v '#' | grep -v '#' | grep PROCESS | grep -v '\.' | sed 's/ - PROCESS-NAME,//g' > ${list[i]}/process.json
fi
if [ -n "$(cat ./rule/Clash/${list[i]}/${list[i]}.yaml | grep -v '#' | grep PROCESS | grep '\.exe')" ]; then
cat ./rule/Clash/${list[i]}/${list[i]}.yaml | grep -v '#' | grep -v '#' | grep PROCESS | grep '\.exe' | sed 's/ - PROCESS-NAME,//g' >> ${list[i]}/process.json
fi
# domain
if [ -n "$(cat ./rule/Clash/${list[i]}/${list[i]}.yaml | grep '\- DOMAIN-SUFFIX,')" ]; then
cat ./rule/Clash/${list[i]}/${list[i]}.yaml | grep -v '#' | grep '\- DOMAIN-SUFFIX,' | sed 's/ - DOMAIN-SUFFIX,//g' > ${list[i]}/domain.json
cat ./rule/Clash/${list[i]}/${list[i]}.yaml | grep -v '#' | grep '\- DOMAIN-SUFFIX,' | sed 's/ - DOMAIN-SUFFIX,/./g' > ${list[i]}/suffix.json
fi
if [ -n "$(cat ./rule/Clash/${list[i]}/${list[i]}.yaml | grep '\- DOMAIN,')" ]; then
cat ./rule/Clash/${list[i]}/${list[i]}.yaml | grep -v '#' | grep '\- DOMAIN,' | sed 's/ - DOMAIN,//g' >> ${list[i]}/domain.json
fi
if [ -n "$(cat ./rule/Clash/${list[i]}/${list[i]}.yaml | grep '\- DOMAIN-KEYWORD,')" ]; then
cat ./rule/Clash/${list[i]}/${list[i]}.yaml | grep -v '#' | grep '\- DOMAIN-KEYWORD,' | sed 's/ - DOMAIN-KEYWORD,//g' > ${list[i]}/keyword.json
fi
# ipcidr
if [ -n "$(cat ./rule/Clash/${list[i]}/${list[i]}.yaml | grep '\- IP-CIDR')" ]; then
cat ./rule/Clash/${list[i]}/${list[i]}.yaml | grep -v '#' | grep '\- IP-CIDR' | sed 's/ - IP-CIDR,//g' | sed 's/ - IP-CIDR6,//g' > ${list[i]}/ipcidr.json
fi
# 转成json格式
# android package
if [ -f "${list[i]}/package.json" ]; then
sed -i 's/^/ "/g' ${list[i]}/package.json
sed -i 's/$/",/g' ${list[i]}/package.json
sed -i '1s/^/ "package_name": [\n/g' ${list[i]}/package.json
sed -i '$ s/,$/\n ],/g' ${list[i]}/package.json
fi
# process name
if [ -f "${list[i]}/process.json" ]; then
sed -i 's/^/ "/g' ${list[i]}/process.json
sed -i 's/$/",/g' ${list[i]}/process.json
sed -i '1s/^/ "process_name": [\n/g' ${list[i]}/process.json
sed -i '$ s/,$/\n ],/g' ${list[i]}/process.json
fi
# domain
if [ -f "${list[i]}/domain.json" ]; then
sed -i 's/^/ "/g' ${list[i]}/domain.json
sed -i 's/$/",/g' ${list[i]}/domain.json
sed -i '1s/^/ "domain": [\n/g' ${list[i]}/domain.json
sed -i '$ s/,$/\n ],/g' ${list[i]}/domain.json
fi
if [ -f "${list[i]}/suffix.json" ]; then
sed -i 's/^/ "/g' ${list[i]}/suffix.json
sed -i 's/$/",/g' ${list[i]}/suffix.json
sed -i '1s/^/ "domain_suffix": [\n/g' ${list[i]}/suffix.json
sed -i '$ s/,$/\n ],/g' ${list[i]}/suffix.json
fi
if [ -f "${list[i]}/keyword.json" ]; then
sed -i 's/^/ "/g' ${list[i]}/keyword.json
sed -i 's/$/",/g' ${list[i]}/keyword.json
sed -i '1s/^/ "domain_keyword": [\n/g' ${list[i]}/keyword.json
sed -i '$ s/,$/\n ],/g' ${list[i]}/keyword.json
fi
# ipcidr
if [ -f "${list[i]}/ipcidr.json" ]; then
sed -i 's/^/ "/g' ${list[i]}/ipcidr.json
sed -i 's/$/",/g' ${list[i]}/ipcidr.json
sed -i '1s/^/ "ip_cidr": [\n/g' ${list[i]}/ipcidr.json
sed -i '$ s/,$/\n ],/g' ${list[i]}/ipcidr.json
fi
# 合并文件
if [ -f "${list[i]}/package.json" -a -f "${list[i]}/process.json" ]; then
mv ${list[i]}/package.json ${list[i]}.json
sed -i '$ s/,$/\n },\n {/g' ${list[i]}.json
cat ${list[i]}/process.json >> ${list[i]}.json
rm ${list[i]}/process.json
elif [ -f "${list[i]}/package.json" ]; then
mv ${list[i]}/package.json ${list[i]}.json
elif [ -f "${list[i]}/process.json" ]; then
mv ${list[i]}/process.json ${list[i]}.json
fi
if [ -f "${list[i]}.json" ]; then
sed -i '1s/^/{\n "version": 1,\n "rules": [\n {\n/g' ${list[i]}.json
sed -i '$ s/,$/\n },\n {/g' ${list[i]}.json
cat ${list[i]}/* >> ${list[i]}.json
else
cat ${list[i]}/* >> ${list[i]}.json
sed -i '1s/^/{\n "version": 1,\n "rules": [\n {\n/g' ${list[i]}.json
fi
sed -i '$ s/,$/\n }\n ]\n}/g' ${list[i]}.json
rm -r ${list[i]}
./sing-box rule-set compile ${list[i]}.json -o ${list[i]}.srs
done