diff --git a/version/url.go b/version/url.go index 72ed83dbfa8..ed43ab04249 100644 --- a/version/url.go +++ b/version/url.go @@ -1,47 +1,5 @@ package version -import ( - "os/exec" - "runtime" -) - const ( downloadURL = "https://app.netbird.io/install" - macIntelURL = "https://pkgs.netbird.io/macos/amd64" - macM1M2URL = "https://pkgs.netbird.io/macos/arm64" ) - -// DownloadUrl return with the proper download link -func DownloadUrl() string { - switch runtime.GOOS { - case "windows": - return downloadURL - case "darwin": - return darwinDownloadUrl() - case "linux": - return downloadURL - default: - return downloadURL - } -} - -func darwinDownloadUrl() string { - cmd := exec.Command("brew", "list --formula | grep -i netbird") - if err := cmd.Start(); err != nil { - goto PKGINSTALL - } - - if err := cmd.Wait(); err == nil { - return downloadURL - } - -PKGINSTALL: - switch runtime.GOARCH { - case "amd64": - return macIntelURL - case "arm64": - return macM1M2URL - default: - return downloadURL - } -} diff --git a/version/url_darwin.go b/version/url_darwin.go new file mode 100644 index 00000000000..cb58612f52b --- /dev/null +++ b/version/url_darwin.go @@ -0,0 +1,33 @@ +package version + +import ( + "os/exec" + "runtime" +) + +const ( + urlMacIntel = "https://pkgs.netbird.io/macos/amd64" + urlMacM1M2 = "https://pkgs.netbird.io/macos/arm64" +) + +// DownloadUrl return with the proper download link +func DownloadUrl() string { + cmd := exec.Command("brew", "list --formula | grep -i netbird") + if err := cmd.Start(); err != nil { + goto PKGINSTALL + } + + if err := cmd.Wait(); err == nil { + return downloadURL + } + +PKGINSTALL: + switch runtime.GOARCH { + case "amd64": + return urlMacIntel + case "arm64": + return urlMacM1M2 + default: + return downloadURL + } +} diff --git a/version/url_linux.go b/version/url_linux.go new file mode 100644 index 00000000000..c8193e30c31 --- /dev/null +++ b/version/url_linux.go @@ -0,0 +1,6 @@ +package version + +// DownloadUrl return with the proper download link +func DownloadUrl() string { + return downloadURL +} diff --git a/version/url_windows.go b/version/url_windows.go new file mode 100644 index 00000000000..f2055b10915 --- /dev/null +++ b/version/url_windows.go @@ -0,0 +1,19 @@ +package version + +import "golang.org/x/sys/windows/registry" + +const ( + urlWinExe = "https://pkgs.netbird.io/windows/x64" +) + +var regKeyAppPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Netbird" + +// DownloadUrl return with the proper download link +func DownloadUrl() string { + _, err := registry.OpenKey(registry.LOCAL_MACHINE, regKeyAppPath, registry.QUERY_VALUE) + if err == nil { + return urlWinExe + } else { + return downloadURL + } +}