diff options
| author | Brad Fitzpatrick <bradfitz@tailscale.com> | 2022-09-18 10:28:00 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@tailscale.com> | 2022-09-18 10:28:00 -0700 |
| commit | 1a45274d4c45ec805e6d0cffd5da33e8e15643fd (patch) | |
| tree | b7214f77895a156aa105da0bac05462479d9b7b3 /version | |
| parent | d8eb111ac8993b67a644941628e539c9640830de (diff) | |
| download | tailscale-bradfitz/distro_ubuntu.tar.xz tailscale-bradfitz/distro_ubuntu.zip | |
version/distro: detect Ubuntu separately from Debianbradfitz/distro_ubuntu
(for an upcoming change where I wanted to easily distinguish these
two)
Change-Id: Icb6a0144275cc9bf8978a7cb96b601d516d8da46
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Diffstat (limited to 'version')
| -rw-r--r-- | version/distro/distro.go | 21 | ||||
| -rw-r--r-- | version/distro/distro_test.go | 5 |
2 files changed, 25 insertions, 1 deletions
diff --git a/version/distro/distro.go b/version/distro/distro.go index 3b1d36378..ca7a761fa 100644 --- a/version/distro/distro.go +++ b/version/distro/distro.go @@ -10,13 +10,16 @@ import ( "runtime" "strconv" + "go4.org/mem" "tailscale.com/syncs" + "tailscale.com/util/lineread" ) type Distro string const ( Debian = Distro("debian") + Ubuntu = Distro("ubuntu") Arch = Distro("arch") Synology = Distro("synology") OpenWrt = Distro("openwrt") @@ -62,9 +65,20 @@ func linuxDistro() Distro { case haveDir("/usr/syno"): return Synology case have("/usr/local/bin/freenas-debug"): - // TrueNAS Scale runs on debian + // TrueNAS Scale runs on debian so test for it before Debian. return TrueNAS case have("/etc/debian_version"): + // Ubuntu also has an /etc/debian_version file, so see if it's actually Ubuntu. + isUbuntu := false + lineread.File("/etc/os-release", func(line []byte) error { + if mem.HasPrefix(mem.B(line), mem.S("ID=ubuntu")) { + isUbuntu = true + } + return nil + }) + if isUbuntu { + return Ubuntu + } return Debian case have("/etc/arch-release"): return Arch @@ -110,3 +124,8 @@ func DSMVersion() int { v, _ := strconv.Atoi(os.Getenv("SYNOPKG_DSM_VERSION_MAJOR")) return v } + +// LikeDebian reports whether d is Debian-derived. +func (d Distro) LikeDebian() bool { + return d == Debian || d == Ubuntu +} diff --git a/version/distro/distro_test.go b/version/distro/distro_test.go index bc4e8c5b4..1f91d97f2 100644 --- a/version/distro/distro_test.go +++ b/version/distro/distro_test.go @@ -14,3 +14,8 @@ func BenchmarkGet(b *testing.B) { } _ = d } + +func TestGet(t *testing.T) { + d := Get() + t.Logf("Get = %q", d) +} |
