From 542e548ba7f37e73972584ed6827da0606375f40 Mon Sep 17 00:00:00 2001 From: Zoltan Papp Date: Thu, 26 Oct 2023 16:57:39 +0200 Subject: [PATCH] Download link based on installation type (#1243) Based on the registry, determine the installation source (MSI or EXE) and open the appropriate link in the update notification menu --- version/url.go | 42 ------------------------------------------ version/url_darwin.go | 33 +++++++++++++++++++++++++++++++++ version/url_linux.go | 6 ++++++ version/url_windows.go | 19 +++++++++++++++++++ 4 files changed, 58 insertions(+), 42 deletions(-) create mode 100644 version/url_darwin.go create mode 100644 version/url_linux.go create mode 100644 version/url_windows.go 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 + } +}