sing-geosite: add rule-set

This commit is contained in:
linsui 2024-04-01 23:16:45 +08:00
parent 11273b60c8
commit d25514add1
2 changed files with 34 additions and 0 deletions

View file

@ -38,6 +38,7 @@ buildGoModule {
installPhase = ''
runHook preInstall
install -Dm644 geosite.db $out/share/sing-box/geosite.db
install -Dm644 rule-set/* -t $out/share/sing-box/rule-set
runHook postInstall
'';

View file

@ -16,4 +16,37 @@ func main() {
if err != nil {
panic(err)
}
ruleSetOutput := "rule-set"
err = os.MkdirAll(ruleSetOutput, 0o755)
if err != nil {
panic(err)
}
for code, domains := range domainMap {
var headlessRule option.DefaultHeadlessRule
defaultRule := geosite.Compile(domains)
headlessRule.Domain = defaultRule.Domain
headlessRule.DomainSuffix = defaultRule.DomainSuffix
headlessRule.DomainKeyword = defaultRule.DomainKeyword
headlessRule.DomainRegex = defaultRule.DomainRegex
var plainRuleSet option.PlainRuleSet
plainRuleSet.Rules = []option.HeadlessRule{
{
Type: C.RuleTypeDefault,
DefaultOptions: headlessRule,
},
}
srsPath, _ := filepath.Abs(filepath.Join(ruleSetOutput, "geosite-"+code+".srs"))
os.Stderr.WriteString("write " + srsPath + "\n")
outputRuleSet, err := os.Create(srsPath)
if err != nil {
panic(err)
}
err = srs.Write(outputRuleSet, plainRuleSet)
if err != nil {
outputRuleSet.Close()
panic(err)
}
outputRuleSet.Close()
}
}