Browse Source

ipn/ipnlocal: add health warning for unstable builds

Like the macOS About dialog.

Change-Id: Ic27f091e66e29d5eebe4e195eda97ed331d748fd
Signed-off-by: Brad Fitzpatrick <[email protected]>
Brad Fitzpatrick 3 years ago
parent
commit
039ea51ca6
2 changed files with 33 additions and 0 deletions
  1. 3 0
      ipn/ipnlocal/local.go
  2. 30 0
      version/prop.go

+ 3 - 0
ipn/ipnlocal/local.go

@@ -579,6 +579,9 @@ func (b *LocalBackend) updateStatus(sb *ipnstate.StatusBuilder, extraLocked func
 		if m := b.sshOnButUnusableHealthCheckMessageLocked(); m != "" {
 			s.Health = append(s.Health, m)
 		}
+		if version.IsUnstableBuild() {
+			s.Health = append(s.Health, "This is an unstable (development) version of Tailscale; frequent updates and bugs are likely")
+		}
 		if b.netMap != nil {
 			s.CertDomains = append([]string(nil), b.netMap.DNS.CertDomains...)
 			s.MagicDNSSuffix = b.netMap.MagicDNSSuffix()

+ 30 - 0
version/prop.go

@@ -8,7 +8,9 @@ import (
 	"os"
 	"path/filepath"
 	"runtime"
+	"strconv"
 	"strings"
+	"sync"
 
 	"tailscale.com/syncs"
 )
@@ -74,3 +76,31 @@ func IsWindowsGUI() bool {
 	exe = filepath.Base(exe)
 	return strings.EqualFold(exe, "tailscale-ipn.exe") || strings.EqualFold(exe, "tailscale-ipn")
 }
+
+var (
+	isUnstableOnce  sync.Once
+	isUnstableBuild bool
+)
+
+// IsUnstableBuild reports whether this is an unstable build.
+// That is, whether its minor version number is odd.
+func IsUnstableBuild() bool {
+	isUnstableOnce.Do(initUnstable)
+	return isUnstableBuild
+}
+
+func initUnstable() {
+	_, rest, ok := strings.Cut(Short, ".")
+	if !ok {
+		return
+	}
+	minorStr, _, ok := strings.Cut(rest, ".")
+	if !ok {
+		return
+	}
+	minor, err := strconv.Atoi(minorStr)
+	if err != nil {
+		return
+	}
+	isUnstableBuild = minor%2 == 1
+}