8
8
"github.com/microsoft/azurelinux/toolkit/tools/internal/logger"
9
9
)
10
10
11
- func getVersionsOfToolDeps () {
11
+ func logVersionsOfToolDeps () {
12
12
// Map of version flags with corresponding packages
13
13
versionFlags := map [string ][]string {
14
14
"--version" : {
@@ -25,41 +25,48 @@ func getVersionsOfToolDeps() {
25
25
"-V" : {
26
26
"mkfs.ext4" , "mkfs.xfs" , "e2fsck" , "xfs_repair" , "xfs_admin" ,
27
27
},
28
- "none " : {
28
+ "" : {
29
29
"mkfs.vfat" , "resize2fs" , "tune2fs" ,
30
30
},
31
31
}
32
32
33
33
// Get distro and version
34
34
distro , version := getDistroAndVersion ()
35
- logger .Log .Debugf ("Distro: %s, Version: %s\n " , distro , version )
35
+ logger .Log .Debugf ("Distro: %s, Version: %s" , distro , version )
36
36
37
37
// Get versions of packages
38
38
logger .Log .Debugf ("Tool Dependencies:" )
39
39
for versionFlag , pkgList := range versionFlags {
40
40
for _ , pkg := range pkgList {
41
41
version , err := getPackageVersion (pkg , versionFlag )
42
42
if err != nil {
43
- logger .Log .Debugf ("%s: not installed or error retrieving version\n " , pkg )
43
+ logger .Log .Debugf ("%s: not installed or error retrieving version" , pkg )
44
44
} else {
45
45
logger .Log .Debugf ("%s: %s" , pkg , version )
46
46
}
47
47
}
48
48
}
49
49
}
50
50
51
- // Function to get the distribution and version of host machine
51
+ // Function to get the distribution and version of the host machine
52
52
func getDistroAndVersion () (string , string ) {
53
- output , err := exec .Command ("lsb_release " , "-si " ).Output ()
53
+ output , err := exec .Command ("cat " , "/etc/os-release " ).Output ()
54
54
if err != nil {
55
- output = [] byte ( "Unknown Distro" )
55
+ return "Unknown Distro" , "Unknown Version"
56
56
}
57
- distro := strings .TrimSpace (string (output ))
58
- output , err = exec .Command ("lsb_release" , "-sr" ).Output ()
59
- if err != nil {
60
- output = []byte ("Unknown Version" )
57
+
58
+ lines := strings .Split (string (output ), "\n " )
59
+ distro := "Unknown Distro"
60
+ version := "Unknown Version"
61
+
62
+ for _ , line := range lines {
63
+ if strings .HasPrefix (line , "NAME=" ) {
64
+ distro = strings .Trim (strings .TrimPrefix (line , "NAME=" ), "\" " )
65
+ } else if strings .HasPrefix (line , "VERSION=" ) {
66
+ version = strings .Trim (strings .TrimPrefix (line , "VERSION=" ), "\" " )
67
+ }
61
68
}
62
- version := strings . TrimSpace ( string ( output ))
69
+
63
70
return distro , version
64
71
}
65
72
@@ -68,17 +75,12 @@ func getPackageVersion(pkg string, versionFlagParameter string) (string, error)
68
75
var cmd * exec.Cmd
69
76
var pkgVersion string
70
77
71
- // If the package does not have a parameter, we call the package alone and extract the version from the output
72
- if versionFlagParameter == "none" {
73
- cmd = exec .Command (pkg )
74
- } else {
75
- cmd = exec .Command (pkg , versionFlagParameter )
76
- }
77
-
78
+ cmd = exec .Command (pkg , versionFlagParameter )
78
79
output , _ := cmd .CombinedOutput ()
79
80
outputLines := strings .Split (string (output ), "\n " )
80
81
81
- if versionFlagParameter == "none" {
82
+ // If the package does not have a version parameter, we need extract the version from the full output
83
+ if versionFlagParameter == "" {
82
84
// Regular expression to match various version formats including num.num.num, num.num, and alphanumeric versions
83
85
re := regexp .MustCompile (`\b\d+(\.\d+){1,3}(-\w+)?\b` )
84
86
for _ , line := range outputLines {
0 commit comments