2020-03-02 20:37:28 +00:00
|
|
|
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package version
|
|
|
|
|
2021-04-28 16:34:13 +01:00
|
|
|
import (
|
|
|
|
"os"
|
2021-04-28 22:57:04 +01:00
|
|
|
"path/filepath"
|
2021-04-28 16:34:13 +01:00
|
|
|
"runtime"
|
|
|
|
"strings"
|
2021-04-28 22:57:04 +01:00
|
|
|
"sync/atomic"
|
2021-04-28 16:34:13 +01:00
|
|
|
)
|
2020-03-02 20:37:28 +00:00
|
|
|
|
|
|
|
// IsMobile reports whether this is a mobile client build.
|
|
|
|
func IsMobile() bool {
|
2021-04-20 05:59:55 +01:00
|
|
|
return runtime.GOOS == "android" || runtime.GOOS == "ios"
|
2020-03-02 20:37:28 +00:00
|
|
|
}
|
2020-04-01 16:49:25 +01:00
|
|
|
|
|
|
|
// OS returns runtime.GOOS, except instead of returning "darwin" it
|
|
|
|
// returns "iOS" or "macOS".
|
|
|
|
func OS() string {
|
2021-04-20 05:59:55 +01:00
|
|
|
if runtime.GOOS == "ios" {
|
2020-11-11 17:04:34 +00:00
|
|
|
return "iOS"
|
|
|
|
}
|
2020-04-01 16:49:25 +01:00
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
return "macOS"
|
|
|
|
}
|
|
|
|
return runtime.GOOS
|
|
|
|
}
|
2021-04-28 16:34:13 +01:00
|
|
|
|
|
|
|
// IsSandboxedMacOS reports whether this process is a sandboxed macOS
|
2021-04-28 22:57:04 +01:00
|
|
|
// process. It is true for the Mac App Store and macsys (System
|
2021-04-28 16:34:13 +01:00
|
|
|
// Extension) version on macOS, and false for tailscaled-on-macOS.
|
|
|
|
func IsSandboxedMacOS() bool {
|
|
|
|
if runtime.GOOS != "darwin" {
|
|
|
|
return false
|
|
|
|
}
|
2021-04-28 22:57:04 +01:00
|
|
|
if IsMacSysExt() {
|
|
|
|
return true
|
|
|
|
}
|
2021-04-28 16:34:13 +01:00
|
|
|
exe, _ := os.Executable()
|
|
|
|
return strings.HasSuffix(exe, "/Contents/MacOS/Tailscale")
|
|
|
|
}
|
2021-04-28 22:57:04 +01:00
|
|
|
|
|
|
|
var isMacSysExt atomic.Value
|
|
|
|
|
|
|
|
// IsMacSysExt whether this binary is from the standalone "System
|
|
|
|
// Extension" (a.k.a. "macsys") version of Tailscale for macOS.
|
|
|
|
func IsMacSysExt() bool {
|
|
|
|
if runtime.GOOS != "darwin" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if b, ok := isMacSysExt.Load().(bool); ok {
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
exe, err := os.Executable()
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
v := filepath.Base(exe) == "io.tailscale.ipn.macsys.network-extension"
|
|
|
|
isMacSysExt.Store(v)
|
|
|
|
return v
|
|
|
|
}
|