571c71e6f7
We are migrating packages that meet below requirements: 1. using `callPackage` 2. called path is a directory 3. overriding set is empty (`{ }`) 4. not containing path expressions other than relative path (to makenixpkgs-vet happy) 5. not referenced by nix files outside of the directory, other than`pkgs/top-level/all-packages.nix` 6. not referencing nix files outside of the directory 7. not referencing `default.nix` (since it's changed to `package.nix`) 8. `outPath` doesn't change after migration The tool is here: https://github.com/Aleksanaa/by-name-migrate.
69 lines
1.5 KiB
Go
69 lines
1.5 KiB
Go
func main() {
|
|
var err error
|
|
|
|
input := os.Args[1]
|
|
ruleSetOutput := "rule-set"
|
|
|
|
binary, err := os.ReadFile(input)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
metadata, countryMap, err := parse(binary)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
allCodes := make([]string, 0, len(countryMap))
|
|
for code := range countryMap {
|
|
allCodes = append(allCodes, code)
|
|
}
|
|
|
|
writer, err := newWriter(metadata, allCodes)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
err = write(writer, countryMap, "geoip.db", nil)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
writer, err = newWriter(metadata, []string{"cn"})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
err = write(writer, countryMap, "geoip-cn.db", []string{"cn"})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
err = os.MkdirAll(ruleSetOutput, 0o755)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
for countryCode, ipNets := range countryMap {
|
|
var headlessRule option.DefaultHeadlessRule
|
|
headlessRule.IPCIDR = make([]string, 0, len(ipNets))
|
|
for _, cidr := range ipNets {
|
|
headlessRule.IPCIDR = append(headlessRule.IPCIDR, cidr.String())
|
|
}
|
|
var plainRuleSet option.PlainRuleSet
|
|
plainRuleSet.Rules = []option.HeadlessRule{
|
|
{
|
|
Type: C.RuleTypeDefault,
|
|
DefaultOptions: headlessRule,
|
|
},
|
|
}
|
|
srsPath, _ := filepath.Abs(filepath.Join(ruleSetOutput, "geoip-"+countryCode+".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()
|
|
}
|
|
}
|