sing-geosite: add rule-set
This commit is contained in:
parent
11273b60c8
commit
d25514add1
2 changed files with 34 additions and 0 deletions
|
@ -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
|
||||
'';
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue