From 43081d61f24a6e54f28297696542775bc49180d8 Mon Sep 17 00:00:00 2001 From: yoavrotems Date: Tue, 21 May 2019 19:19:49 +0300 Subject: [PATCH 1/2] gets also ubuntu version There are differences between Ubuntu 16 and Ubuntu 18 features so the system needs to know the specific version --- utils.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/utils.go b/utils.go index 5a53cc1..a8715f9 100644 --- a/utils.go +++ b/utils.go @@ -104,11 +104,16 @@ func GetLSM() (lsm string, err error) { func getPlatformVersion(output, platform string) string { flagRe := regexp.MustCompile("version_id" + `=([^ \n]*)`) vals := flagRe.FindStringSubmatch(output) - + if vals == nil { + flagRe := regexp.MustCompile("version" + `=([^ \n]*)`) + vals = flagRe.FindStringSubmatch(output) + } if len(vals) > 1 { switch platform { case "rhel": return vals[1][:1] // Get the major version only, examaple: 7.6 will return 7 + case "ubuntu": + return vals[1][:2] // Get the major version only, examaple: 18.04 will return 18 default: return "" } From c5293e858c292d4d4457b7e97c0a4e596432f258 Mon Sep 17 00:00:00 2001 From: yoavrotems Date: Thu, 30 May 2019 00:04:10 +0300 Subject: [PATCH 2/2] change the regex to catch version Taking Liz comment's https://github.com/aquasecurity/linux-bench/pull/13/files#r287555525 changes so will work on ubuntu and rhel within one line --- utils.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/utils.go b/utils.go index a8715f9..a7d3f67 100644 --- a/utils.go +++ b/utils.go @@ -102,12 +102,8 @@ func GetLSM() (lsm string, err error) { } func getPlatformVersion(output, platform string) string { - flagRe := regexp.MustCompile("version_id" + `=([^ \n]*)`) + flagRe := regexp.MustCompile(`version[_id]*=([^ \n]*)`) vals := flagRe.FindStringSubmatch(output) - if vals == nil { - flagRe := regexp.MustCompile("version" + `=([^ \n]*)`) - vals = flagRe.FindStringSubmatch(output) - } if len(vals) > 1 { switch platform { case "rhel":