mirror of
https://github.com/ACL4SSR/ACL4SSR.git
synced 2026-06-13 07:52:31 +00:00
fix a bug
This commit is contained in:
40
.github/workflows/update.yml
vendored
40
.github/workflows/update.yml
vendored
@@ -62,12 +62,14 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
mkdir -p Clash/mrs
|
mkdir -p Clash/mrs
|
||||||
convert_file() {
|
convert_file() {
|
||||||
local input_file=$1
|
local type=$1
|
||||||
local output_file=$2
|
local format=$2
|
||||||
|
local input_file=$3
|
||||||
|
local output_file=$4
|
||||||
local MAX_RETRIES=3
|
local MAX_RETRIES=3
|
||||||
for ((i=1; i<=MAX_RETRIES; i++)); do
|
for ((i=1; i<=MAX_RETRIES; i++)); do
|
||||||
echo "[Attempt $i/$MAX_RETRIES] Converting $input_file"
|
echo "[Attempt $i/$MAX_RETRIES] Converting $input_file ($type)"
|
||||||
if ./mihomo -f "$input_file" -in clash -out mrs -o "$output_file"; then
|
if ./mihomo convert-ruleset "$type" "$format" "$input_file" "$output_file"; then
|
||||||
echo "Success: $input_file -> $output_file"
|
echo "Success: $input_file -> $output_file"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
@@ -81,21 +83,39 @@ jobs:
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
for file in Clash/Providers/*.yaml; do
|
# 处理我们生成的分离文件
|
||||||
|
for file in Clash/Providers/*_domain.yaml Clash/Providers/*_ip.yaml; do
|
||||||
if [ -f "$file" ]; then
|
if [ -f "$file" ]; then
|
||||||
filename=$(basename "$file" .yaml)
|
filename=$(basename "$file")
|
||||||
convert_file "$file" "Clash/mrs/${filename}.mrs"
|
if [[ "$filename" == *"_domain.yaml" ]]; then
|
||||||
|
base=$(basename "$file" _domain.yaml)
|
||||||
|
convert_file "domain" "yaml" "$file" "Clash/mrs/${base}_domain.mrs"
|
||||||
|
elif [[ "$filename" == *"_ip.yaml" ]]; then
|
||||||
|
base=$(basename "$file" _ip.yaml)
|
||||||
|
convert_file "ipcidr" "yaml" "$file" "Clash/mrs/${base}_ip.mrs"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
for file in Clash/Ruleset/*.list; do
|
for file in Clash/Ruleset/*_domain.list Clash/Ruleset/*_ip.list; do
|
||||||
if [ -f "$file" ]; then
|
if [ -f "$file" ]; then
|
||||||
filename=$(basename "$file" .list)
|
filename=$(basename "$file")
|
||||||
convert_file "$file" "Clash/mrs/${filename}.mrs"
|
if [[ "$filename" == *"_domain.list" ]]; then
|
||||||
|
base=$(basename "$file" _domain.list)
|
||||||
|
convert_file "domain" "text" "$file" "Clash/mrs/${base}_domain.mrs"
|
||||||
|
elif [[ "$filename" == *"_ip.list" ]]; then
|
||||||
|
base=$(basename "$file" _ip.list)
|
||||||
|
convert_file "ipcidr" "text" "$file" "Clash/mrs/${base}_ip.mrs"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Conversion completed"
|
echo "Conversion completed"
|
||||||
|
|
||||||
|
# 清理临时文件
|
||||||
|
rm -f Clash/Providers/*_domain.yaml Clash/Providers/*_ip.yaml
|
||||||
|
rm -f Clash/Ruleset/*_domain.list Clash/Ruleset/*_ip.list
|
||||||
|
echo "Temporary files cleaned up"
|
||||||
|
|
||||||
- name: Commit and push changes
|
- name: Commit and push changes
|
||||||
uses: EndBug/add-and-commit@v9
|
uses: EndBug/add-and-commit@v9
|
||||||
|
|||||||
@@ -216,6 +216,20 @@ def generate_clash_provider_yaml(domain_list, ip_list, filename, title="payload"
|
|||||||
for rule in ip_rules:
|
for rule in ip_rules:
|
||||||
content += f" - {rule}\n"
|
content += f" - {rule}\n"
|
||||||
write_file(filename, content)
|
write_file(filename, content)
|
||||||
|
|
||||||
|
# 生成分离的临时文件用于 mrs 转换
|
||||||
|
base_name = filename.replace('.yaml', '')
|
||||||
|
# 域名规则 - YAML 格式
|
||||||
|
domain_yaml = f"{title}:\n"
|
||||||
|
for domain in unique_domains:
|
||||||
|
domain_yaml += f" - DOMAIN-SUFFIX,{domain}\n"
|
||||||
|
write_file(f"{base_name}_domain.yaml", domain_yaml)
|
||||||
|
|
||||||
|
# IP 规则 - YAML 格式
|
||||||
|
ip_yaml = f"{title}:\n"
|
||||||
|
for rule in ip_rules:
|
||||||
|
ip_yaml += f" - {rule}\n"
|
||||||
|
write_file(f"{base_name}_ip.yaml", ip_yaml)
|
||||||
|
|
||||||
def generate_clash_ruleset_list(domain_list, ip_list, filename, title="GFWList"):
|
def generate_clash_ruleset_list(domain_list, ip_list, filename, title="GFWList"):
|
||||||
unique_domains = sorted(set(domain_list))
|
unique_domains = sorted(set(domain_list))
|
||||||
@@ -227,6 +241,20 @@ def generate_clash_ruleset_list(domain_list, ip_list, filename, title="GFWList")
|
|||||||
for rule in ip_rules:
|
for rule in ip_rules:
|
||||||
content += f"{rule}\n"
|
content += f"{rule}\n"
|
||||||
write_file(filename, content)
|
write_file(filename, content)
|
||||||
|
|
||||||
|
# 生成分离的临时文件用于 mrs 转换
|
||||||
|
base_name = filename.replace('.list', '')
|
||||||
|
# 域名规则 - text 格式
|
||||||
|
domain_text = ""
|
||||||
|
for domain in unique_domains:
|
||||||
|
domain_text += f"DOMAIN-SUFFIX,{domain}\n"
|
||||||
|
write_file(f"{base_name}_domain.list", domain_text)
|
||||||
|
|
||||||
|
# IP 规则 - text 格式
|
||||||
|
ip_text = ""
|
||||||
|
for rule in ip_rules:
|
||||||
|
ip_text += f"{rule}\n"
|
||||||
|
write_file(f"{base_name}_ip.list", ip_text)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print("Fetching GFWList...")
|
print("Fetching GFWList...")
|
||||||
|
|||||||
Reference in New Issue
Block a user