Skip to content

Commit 515c38e

Browse files
authored
Detect MX Linux as platform "mx" and family "debian" (#6019)
/etc/os-release says debian, but /etc/lsb-release says mx. Signed-off-by: Tim Smith <tsmith84@gmail.com>
1 parent 38f6285 commit 515c38e

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

providers/os/detector/detector_all.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,28 @@ var mageia = &PlatformResolver{
612612
},
613613
}
614614

615+
var mxlinux = &PlatformResolver{
616+
Name: "mxlinux",
617+
IsFamily: false,
618+
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
619+
osrd := NewOSReleaseDetector(conn)
620+
lsb, err := osrd.lsbconfig()
621+
// we're not on mx if we can't read lsb
622+
if err != nil {
623+
return false, nil
624+
}
625+
626+
if len(lsb["DISTRIB_ID"]) > 0 && strings.ToLower(lsb["DISTRIB_ID"]) == "mx" {
627+
pf.Name = "mx"
628+
pf.Version = lsb["DISTRIB_RELEASE"]
629+
pf.Title = lsb["DISTRIB_DESCRIPTION"]
630+
return true, nil
631+
}
632+
633+
return false, nil
634+
},
635+
}
636+
615637
var openwrt = &PlatformResolver{
616638
Name: "openwrt",
617639
IsFamily: false,
@@ -917,7 +939,7 @@ var redhatFamily = &PlatformResolver{
917939
var debianFamily = &PlatformResolver{
918940
Name: "debian",
919941
IsFamily: true,
920-
Children: []*PlatformResolver{debian, ubuntu, raspbian, kali, linuxmint, popos, elementary},
942+
Children: []*PlatformResolver{mxlinux, debian, ubuntu, raspbian, kali, linuxmint, popos, elementary},
921943
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
922944
return true, nil
923945
},

providers/os/detector/detector_platform_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,3 +921,14 @@ func TestMageiaDetector(t *testing.T) {
921921
assert.Equal(t, "aarch64", di.Arch, "os arch should be identified")
922922
assert.Equal(t, []string{"linux", "unix", "os"}, di.Family)
923923
}
924+
925+
func TestMXLinuxDetector(t *testing.T) {
926+
di, err := detectPlatformFromMock("./testdata/detect-mx.toml")
927+
assert.Nil(t, err, "was able to create the provider")
928+
929+
assert.Equal(t, "mx", di.Name, "os name should be identified")
930+
assert.Equal(t, "MX 23.2 Libretto", di.Title, "os title should be identified")
931+
assert.Equal(t, "23.2", di.Version, "os version should be identified")
932+
assert.Equal(t, "x86_64", di.Arch, "os arch should be identified")
933+
assert.Equal(t, []string{"debian", "linux", "unix", "os"}, di.Family)
934+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[commands."uname -s"]
2+
stdout = "Linux"
3+
4+
[commands."uname -m"]
5+
stdout = "x86_64"
6+
7+
[commands."uname -r"]
8+
stdout = "6.1.0-18-amd64"
9+
10+
[files."/etc/os-release"]
11+
content = """
12+
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
13+
NAME="Debian GNU/Linux"
14+
VERSION_ID="12"
15+
VERSION="12 (bookworm)"
16+
VERSION_CODENAME=bookworm
17+
ID=debian
18+
HOME_URL="https://www.debian.org/"
19+
SUPPORT_URL="https://www.debian.org/support"
20+
BUG_REPORT_URL="https://bugs.debian.org/"
21+
"""
22+
23+
[files."/etc/lsb-release"]
24+
content = """
25+
PRETTY_NAME="MX 23.2 Libretto"
26+
DISTRIB_ID=MX
27+
DISTRIB_RELEASE=23.2
28+
DISTRIB_CODENAME="Libretto"
29+
DISTRIB_DESCRIPTION="MX 23.2 Libretto"
30+
"""

0 commit comments

Comments
 (0)