-
-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
4 changed files
with
58 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |