Skip to content

Commit

Permalink
Download link based on installation type (#1243)
Browse files Browse the repository at this point in the history
Based on the registry, determine the installation source (MSI or EXE)
and open the appropriate link in the update notification menu
  • Loading branch information
pappz authored Oct 26, 2023
1 parent f513902 commit 542e548
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 42 deletions.
42 changes: 0 additions & 42 deletions version/url.go
Original file line number Diff line number Diff line change
@@ -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
}
}
33 changes: 33 additions & 0 deletions version/url_darwin.go
Original file line number Diff line number Diff line change
@@ -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
}
}
6 changes: 6 additions & 0 deletions version/url_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package version

// DownloadUrl return with the proper download link
func DownloadUrl() string {
return downloadURL
}
19 changes: 19 additions & 0 deletions version/url_windows.go
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 542e548

Please sign in to comment.