mirror of
https://github.com/tailscale/tailscale.git
synced 2024-12-04 15:35:38 +00:00
version/distro: detect Ubuntu separately from Debian
(for an upcoming change where I wanted to easily distinguish these two) Change-Id: Icb6a0144275cc9bf8978a7cb96b601d516d8da46 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
d8eb111ac8
commit
1a45274d4c
@ -59,8 +59,9 @@ func diagnoseLinuxTUNFailure(tunName string, logf logger.Logf, createErr error)
|
|||||||
}
|
}
|
||||||
logf("is CONFIG_TUN enabled in your kernel? `modprobe tun` failed with: %s", modprobeOut)
|
logf("is CONFIG_TUN enabled in your kernel? `modprobe tun` failed with: %s", modprobeOut)
|
||||||
|
|
||||||
switch distro.Get() {
|
dist := distro.Get()
|
||||||
case distro.Debian:
|
switch {
|
||||||
|
case dist.LikeDebian():
|
||||||
dpkgOut, err := exec.Command("dpkg", "-S", "kernel/drivers/net/tun.ko").CombinedOutput()
|
dpkgOut, err := exec.Command("dpkg", "-S", "kernel/drivers/net/tun.ko").CombinedOutput()
|
||||||
if len(bytes.TrimSpace(dpkgOut)) == 0 || err != nil {
|
if len(bytes.TrimSpace(dpkgOut)) == 0 || err != nil {
|
||||||
logf("tun module not loaded nor found on disk")
|
logf("tun module not loaded nor found on disk")
|
||||||
@ -69,7 +70,7 @@ func diagnoseLinuxTUNFailure(tunName string, logf logger.Logf, createErr error)
|
|||||||
if !bytes.Contains(dpkgOut, []byte(kernel)) {
|
if !bytes.Contains(dpkgOut, []byte(kernel)) {
|
||||||
logf("kernel/drivers/net/tun.ko found on disk, but not for current kernel; are you in middle of a system update and haven't rebooted? found: %s", dpkgOut)
|
logf("kernel/drivers/net/tun.ko found on disk, but not for current kernel; are you in middle of a system update and haven't rebooted? found: %s", dpkgOut)
|
||||||
}
|
}
|
||||||
case distro.Arch:
|
case dist == distro.Arch:
|
||||||
findOut, err := exec.Command("find", "/lib/modules/", "-path", "*/net/tun.ko*").CombinedOutput()
|
findOut, err := exec.Command("find", "/lib/modules/", "-path", "*/net/tun.ko*").CombinedOutput()
|
||||||
if len(bytes.TrimSpace(findOut)) == 0 || err != nil {
|
if len(bytes.TrimSpace(findOut)) == 0 || err != nil {
|
||||||
logf("tun module not loaded nor found on disk")
|
logf("tun module not loaded nor found on disk")
|
||||||
@ -78,7 +79,7 @@ func diagnoseLinuxTUNFailure(tunName string, logf logger.Logf, createErr error)
|
|||||||
if !bytes.Contains(findOut, []byte(kernel)) {
|
if !bytes.Contains(findOut, []byte(kernel)) {
|
||||||
logf("kernel/drivers/net/tun.ko found on disk, but not for current kernel; are you in middle of a system update and haven't rebooted? found: %s", findOut)
|
logf("kernel/drivers/net/tun.ko found on disk, but not for current kernel; are you in middle of a system update and haven't rebooted? found: %s", findOut)
|
||||||
}
|
}
|
||||||
case distro.OpenWrt:
|
case dist == distro.OpenWrt:
|
||||||
out, err := exec.Command("opkg", "list-installed").CombinedOutput()
|
out, err := exec.Command("opkg", "list-installed").CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logf("error querying OpenWrt installed packages: %s", out)
|
logf("error querying OpenWrt installed packages: %s", out)
|
||||||
|
@ -10,13 +10,16 @@
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"go4.org/mem"
|
||||||
"tailscale.com/syncs"
|
"tailscale.com/syncs"
|
||||||
|
"tailscale.com/util/lineread"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Distro string
|
type Distro string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Debian = Distro("debian")
|
Debian = Distro("debian")
|
||||||
|
Ubuntu = Distro("ubuntu")
|
||||||
Arch = Distro("arch")
|
Arch = Distro("arch")
|
||||||
Synology = Distro("synology")
|
Synology = Distro("synology")
|
||||||
OpenWrt = Distro("openwrt")
|
OpenWrt = Distro("openwrt")
|
||||||
@ -62,9 +65,20 @@ func linuxDistro() Distro {
|
|||||||
case haveDir("/usr/syno"):
|
case haveDir("/usr/syno"):
|
||||||
return Synology
|
return Synology
|
||||||
case have("/usr/local/bin/freenas-debug"):
|
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
|
return TrueNAS
|
||||||
case have("/etc/debian_version"):
|
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
|
return Debian
|
||||||
case have("/etc/arch-release"):
|
case have("/etc/arch-release"):
|
||||||
return Arch
|
return Arch
|
||||||
@ -110,3 +124,8 @@ func DSMVersion() int {
|
|||||||
v, _ := strconv.Atoi(os.Getenv("SYNOPKG_DSM_VERSION_MAJOR"))
|
v, _ := strconv.Atoi(os.Getenv("SYNOPKG_DSM_VERSION_MAJOR"))
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LikeDebian reports whether d is Debian-derived.
|
||||||
|
func (d Distro) LikeDebian() bool {
|
||||||
|
return d == Debian || d == Ubuntu
|
||||||
|
}
|
||||||
|
@ -14,3 +14,8 @@ func BenchmarkGet(b *testing.B) {
|
|||||||
}
|
}
|
||||||
_ = d
|
_ = d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGet(t *testing.T) {
|
||||||
|
d := Get()
|
||||||
|
t.Logf("Get = %q", d)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user