From a742c2dd3cd33e0197943ff63c5cc8318f6ef150 Mon Sep 17 00:00:00 2001 From: EpLiar Date: Fri, 17 Jul 2020 15:15:25 +0800 Subject: [PATCH 01/12] Remove .cn domains from visa --- data/visa | 1 - 1 file changed, 1 deletion(-) diff --git a/data/visa b/data/visa index f17fd68c..7b20d803 100644 --- a/data/visa +++ b/data/visa @@ -24,7 +24,6 @@ visa.com.bo visa.com.br visa.com.bs visa.com.bz -visa.com.cn visa.com.co visa.com.cy visa.com.dm From 72e5e7a870f279de4fc14bbd5f6aa6f738fee2ee Mon Sep 17 00:00:00 2001 From: EpLiar Date: Fri, 17 Jul 2020 15:18:56 +0800 Subject: [PATCH 02/12] Remove .cn domains from mcdonalds --- data/mcdonalds | 3 --- 1 file changed, 3 deletions(-) diff --git a/data/mcdonalds b/data/mcdonalds index afec975a..e49e657a 100644 --- a/data/mcdonalds +++ b/data/mcdonalds @@ -1,12 +1,9 @@ # All .mcd domains - mcd # All .mcdonalds domains - mcdonalds -4008-517-517.cn aboutmcdonalds.com happymeal.co.nz happymeal.com.au From c482a6556c89a25a04e6bb43b27632e46eaa0f04 Mon Sep 17 00:00:00 2001 From: EpLiar Date: Fri, 17 Jul 2020 15:19:16 +0800 Subject: [PATCH 03/12] Remove .cn domains from ebay --- data/ebay | 1 - 1 file changed, 1 deletion(-) diff --git a/data/ebay b/data/ebay index 746728b0..7ff9f155 100644 --- a/data/ebay +++ b/data/ebay @@ -4,7 +4,6 @@ ebay.at ebay.be ebay.ca ebay.ch -ebay.cn ebay.co.nz ebay.co.uk ebay.co.ve From e3b2d04119b9046db3115c54fbde1a4501ae46fb Mon Sep 17 00:00:00 2001 From: EpLiar Date: Fri, 17 Jul 2020 15:19:54 +0800 Subject: [PATCH 04/12] Remove .cn domains from mastercard --- data/mastercard | 1 - 1 file changed, 1 deletion(-) diff --git a/data/mastercard b/data/mastercard index 10ce24f6..6568d36e 100644 --- a/data/mastercard +++ b/data/mastercard @@ -25,7 +25,6 @@ mastercard.com.au mastercard.com.bh mastercard.com.br mastercard.com.bz -mastercard.com.cn mastercard.com.co mastercard.com.cy mastercard.com.eg From f4416c1c2062125932c0065ea9fe7d1cbdb6d738 Mon Sep 17 00:00:00 2001 From: EpLiar Date: Fri, 17 Jul 2020 15:20:28 +0800 Subject: [PATCH 05/12] Remove .cn domains from bmw --- data/bmw | 1 - 1 file changed, 1 deletion(-) diff --git a/data/bmw b/data/bmw index cf1ee5aa..3f62252b 100644 --- a/data/bmw +++ b/data/bmw @@ -38,7 +38,6 @@ bmw.com bmw.com.ar bmw.com.au bmw.com.bn -bmw.com.cn bmw.com.kh bmw.com.mt bmw.com.my From 64dc8fc1d6d4598a99d98c0c1762a2f099f28dd9 Mon Sep 17 00:00:00 2001 From: EpLiar Date: Fri, 17 Jul 2020 15:21:26 +0800 Subject: [PATCH 06/12] Remove .cn domains from google-scholar --- data/google-scholar | 1 - 1 file changed, 1 deletion(-) diff --git a/data/google-scholar b/data/google-scholar index 862af472..f4efb4ac 100644 --- a/data/google-scholar +++ b/data/google-scholar @@ -6,7 +6,6 @@ scholar.google.ca scholar.google.cat scholar.google.ch scholar.google.cl -scholar.google.cn scholar.google.co.cr scholar.google.co.id scholar.google.co.il From e501671a9e313fd4c63a59bebc99e3b49b2a2e5a Mon Sep 17 00:00:00 2001 From: The Mule <19835896+Robot-DaneelOlivaw@users.noreply.github.com> Date: Fri, 17 Jul 2020 15:44:51 +0800 Subject: [PATCH 07/12] Create DNSPod --- data/dnspod | 7 +++++++ data/tencent | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 data/dnspod diff --git a/data/dnspod b/data/dnspod new file mode 100644 index 00000000..d0d29c40 --- /dev/null +++ b/data/dnspod @@ -0,0 +1,7 @@ +dns.pub +dnsapi.cn +dnspod.cn +dnspod.com +dnspod.com.cn +dnspod.org +doh.pub diff --git a/data/tencent b/data/tencent index 4a72a63d..a77f382a 100644 --- a/data/tencent +++ b/data/tencent @@ -1,3 +1,6 @@ +include:tencent-ads +include:dnspod + apcdns.net foxmail.com foxmail.com.cn @@ -28,5 +31,3 @@ tenpay.com wechat.com wegame.com weiyun.com - -include:tencent-ads From da72b5116839aa146f66680d32dd9dba82d6ce59 Mon Sep 17 00:00:00 2001 From: EpLiar Date: Fri, 17 Jul 2020 16:08:31 +0800 Subject: [PATCH 08/12] Update uber --- data/uber | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data/uber b/data/uber index 4385c6ad..104b1a59 100644 --- a/data/uber +++ b/data/uber @@ -1,2 +1,3 @@ -uber.com uber-assets.com +uber.com +ubereats.com From 4dac48c14686f850ae038fee3b97b5f9725873f7 Mon Sep 17 00:00:00 2001 From: The Mule <19835896+Robot-DaneelOlivaw@users.noreply.github.com> Date: Fri, 17 Jul 2020 16:11:51 +0800 Subject: [PATCH 09/12] Create Emojipedia --- data/emojipedia | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 data/emojipedia diff --git a/data/emojipedia b/data/emojipedia new file mode 100644 index 00000000..fa9f5a60 --- /dev/null +++ b/data/emojipedia @@ -0,0 +1,3 @@ +emojipedia.org +worldemojiawards.com +worldemojiday.com From c8d1adb68ad3e187fa4b7fd205d81c7bad3301fa Mon Sep 17 00:00:00 2001 From: The Mule <19835896+Robot-DaneelOlivaw@users.noreply.github.com> Date: Fri, 17 Jul 2020 16:16:15 +0800 Subject: [PATCH 10/12] Add Emojipedia into geolocation-!cn --- data/geolocation-!cn | 1 + 1 file changed, 1 insertion(+) diff --git a/data/geolocation-!cn b/data/geolocation-!cn index e615cd48..0d011619 100644 --- a/data/geolocation-!cn +++ b/data/geolocation-!cn @@ -228,6 +228,7 @@ include:reddit include:archive include:change include:csis +include:emojipedia include:globalsecurity include:ruleoflaw include:un From 1be8f5773f49085fdaa56457ac4c72dd8f27bc7a Mon Sep 17 00:00:00 2001 From: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Fri, 17 Jul 2020 16:35:47 +0800 Subject: [PATCH 11/12] Specify more specific `data` directory --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 28801bb5..d88e0750 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ Each file in the `data/` directory can be used as a rule in this format: `geosit - Install `golang` and `git` - Download and install project code: `go get -u -v --insecure github.com/v2ray/domain-list-community` -- Generate `dlc.dat` (without `datapath` option means to use `data` directory of this project): +- Generate `dlc.dat` (without `datapath` option means to use `data` directory of this repository in `$GOPATH`): - `$(go env GOPATH)/bin/domain-list-community` - `$(go env GOPATH)/bin/domain-list-community --datapath=/path/to/your/custom/data/directory` From 22ea807fd1552f43e5a515e2167f80b9f6b7b1cf Mon Sep 17 00:00:00 2001 From: loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Fri, 17 Jul 2020 15:41:06 +0800 Subject: [PATCH 12/12] Refine build process - Detect and set $GOPATH explicitly - Print more explicit errors - Refine output - Fail fast --- main.go | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index f846aae8..2849741e 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "errors" "flag" "fmt" + "go/build" "io/ioutil" "os" "path/filepath" @@ -15,7 +16,10 @@ import ( "v2ray.com/core/app/router" ) -var dataPath = flag.String("datapath", "", "Path to the custom data folder") +var ( + dataPath = flag.String("datapath", "", "Path to your custom 'data' directory") + defaultDataPath = filepath.Join("src", "github.com", "v2ray", "domain-list-community", "data") +) type Entry struct { Type string @@ -145,13 +149,13 @@ func parseEntry(line string) (Entry, error) { func DetectPath(path string) (string, error) { arrPath := strings.Split(path, string(filepath.ListSeparator)) for _, content := range arrPath { - fullPath := filepath.Join(content, "src", "github.com", "v2ray", "domain-list-community", "data") + fullPath := filepath.Join(content, defaultDataPath) _, err := os.Stat(fullPath) if err == nil || os.IsExist(err) { return fullPath, nil } } - err := errors.New("No file found in GOPATH") + err := fmt.Errorf("directory '%s' not found in '$GOPATH'", defaultDataPath) return "", err } @@ -218,6 +222,45 @@ func ParseList(list *List, ref map[string]*List) (*ParsedList, error) { return pl, nil } +func envFile() (string, error) { + if file := os.Getenv("GOENV"); file != "" { + if file == "off" { + return "", fmt.Errorf("GOENV=off") + } + return file, nil + } + dir, err := os.UserConfigDir() + if err != nil { + return "", err + } + if dir == "" { + return "", fmt.Errorf("missing user-config dir") + } + return filepath.Join(dir, "go", "env"), nil +} + +func getRuntimeEnv(key string) (string, error) { + file, err := envFile() + if err != nil { + return "", err + } + if file == "" { + return "", fmt.Errorf("missing runtime env file") + } + var data []byte + var runtimeEnv string + data, err = ioutil.ReadFile(file) + envStrings := strings.Split(string(data), "\n") + for _, envItem := range envStrings { + envItem = strings.TrimSuffix(envItem, "\r") + envKeyValue := strings.Split(envItem, "=") + if strings.ToLower(envKeyValue[0]) == strings.ToLower(key) { + runtimeEnv = envKeyValue[1] + } + } + return runtimeEnv, nil +} + func main() { flag.Parse() @@ -226,12 +269,23 @@ func main() { if *dataPath != "" { dir = *dataPath } else { - dir, err = DetectPath(os.Getenv("GOPATH")) + goPath, envErr := getRuntimeEnv("GOPATH") + if envErr != nil { + fmt.Println("Failed: please set '$GOPATH' manually, or use 'datapath' option to specify the path to your custom 'data' directory") + return + } + if goPath == "" { + goPath = build.Default.GOPATH + } + fmt.Println("Use $GOPATH:", goPath) + fmt.Printf("Searching directory '%s' in '%s'...\n", defaultDataPath, goPath) + dir, err = DetectPath(goPath) } if err != nil { fmt.Println("Failed: ", err) return } + fmt.Println("Use domain lists in", dir) ref := make(map[string]*List) err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { @@ -275,6 +329,6 @@ func main() { if err := ioutil.WriteFile("dlc.dat", protoBytes, 0777); err != nil { fmt.Println("Failed: ", err) } else { - fmt.Println("dlc.dat has been generated successfully.") + fmt.Println("dlc.dat has been generated successfully in the directory. You can rename 'dlc.dat' to 'geosite.dat' and use it in V2Ray.") } }