Skip to content

Commit a956a53

Browse files
committed
code revisions
1 parent 5592e8d commit a956a53

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

toolkit/tools/pkg/imagecustomizerlib/imagecustomizer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func CustomizeImageWithConfigFile(buildDir string, configFile string, imageFile
172172
) error {
173173
var err error
174174

175-
getVersionsOfToolDeps()
175+
logVersionsOfToolDeps()
176176

177177
var config imagecustomizerapi.Config
178178
err = imagecustomizerapi.UnmarshalYamlFile(configFile, &config)

toolkit/tools/pkg/imagecustomizerlib/versionsOfToolDependencies.go

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/microsoft/azurelinux/toolkit/tools/internal/logger"
99
)
1010

11-
func getVersionsOfToolDeps() {
11+
func logVersionsOfToolDeps() {
1212
// Map of version flags with corresponding packages
1313
versionFlags := map[string][]string{
1414
"--version": {
@@ -25,41 +25,48 @@ func getVersionsOfToolDeps() {
2525
"-V": {
2626
"mkfs.ext4", "mkfs.xfs", "e2fsck", "xfs_repair", "xfs_admin",
2727
},
28-
"none": {
28+
"": {
2929
"mkfs.vfat", "resize2fs", "tune2fs",
3030
},
3131
}
3232

3333
// Get distro and version
3434
distro, version := getDistroAndVersion()
35-
logger.Log.Debugf("Distro: %s, Version: %s\n", distro, version)
35+
logger.Log.Debugf("Distro: %s, Version: %s", distro, version)
3636

3737
// Get versions of packages
3838
logger.Log.Debugf("Tool Dependencies:")
3939
for versionFlag, pkgList := range versionFlags {
4040
for _, pkg := range pkgList {
4141
version, err := getPackageVersion(pkg, versionFlag)
4242
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)
4444
} else {
4545
logger.Log.Debugf("%s: %s", pkg, version)
4646
}
4747
}
4848
}
4949
}
5050

51-
// Function to get the distribution and version of host machine
51+
// Function to get the distribution and version of the host machine
5252
func getDistroAndVersion() (string, string) {
53-
output, err := exec.Command("lsb_release", "-si").Output()
53+
output, err := exec.Command("cat", "/etc/os-release").Output()
5454
if err != nil {
55-
output = []byte("Unknown Distro")
55+
return "Unknown Distro", "Unknown Version"
5656
}
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+
}
6168
}
62-
version := strings.TrimSpace(string(output))
69+
6370
return distro, version
6471
}
6572

@@ -68,17 +75,12 @@ func getPackageVersion(pkg string, versionFlagParameter string) (string, error)
6875
var cmd *exec.Cmd
6976
var pkgVersion string
7077

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)
7879
output, _ := cmd.CombinedOutput()
7980
outputLines := strings.Split(string(output), "\n")
8081

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 == "" {
8284
// Regular expression to match various version formats including num.num.num, num.num, and alphanumeric versions
8385
re := regexp.MustCompile(`\b\d+(\.\d+){1,3}(-\w+)?\b`)
8486
for _, line := range outputLines {

0 commit comments

Comments
 (0)