diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 906b6b5..3b1028d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: strategy: matrix: - go: [ '1.20.x', '1.21.x' ] + go: [ '1.21.x', '1.22.x' ] steps: - name: Checkout diff --git a/cli/cli.go b/cli/cli.go index 73c4c7a..ce368e2 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -2,7 +2,7 @@ package cli // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2023 ESSENTIAL KAOS // +// Copyright (c) 2024 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // @@ -38,6 +38,9 @@ import ( "github.com/essentialkaos/ek/v12/sortutil" "github.com/essentialkaos/ek/v12/spinner" "github.com/essentialkaos/ek/v12/strutil" + "github.com/essentialkaos/ek/v12/support" + "github.com/essentialkaos/ek/v12/support/deps" + "github.com/essentialkaos/ek/v12/support/pkgs" "github.com/essentialkaos/ek/v12/system" "github.com/essentialkaos/ek/v12/terminal" "github.com/essentialkaos/ek/v12/terminal/tty" @@ -58,7 +61,6 @@ import ( "github.com/essentialkaos/npck/tzst" "github.com/essentialkaos/rbinstall/index" - "github.com/essentialkaos/rbinstall/support" ) // ////////////////////////////////////////////////////////////////////////////////// // @@ -66,7 +68,7 @@ import ( // App info const ( APP = "RBInstall" - VER = "3.4.1" + VER = "3.4.2" DESC = "Utility for installing prebuilt Ruby versions to rbenv" ) @@ -209,7 +211,16 @@ func Run(gitRev string, gomod []byte) { genAbout(gitRev).Print(options.GetS(OPT_VER)) os.Exit(0) case options.GetB(OPT_VERB_VER): - support.Print(APP, VER, gitRev, gomod) + support.Collect(APP, VER). + WithRevision(gitRev). + WithDeps(deps.Extract(gomod)). + WithPackages(pkgs.Collect( + "rbinstall", "rbinstall-gen", "rbinstall-clone", "rbenv", + "jemalloc", "openssl", "zlib", "gcc", + "jre8,jre11,jre17,jdk8,jdk11,jdk17,java-1.8.0-openjdk,java-11-openjdk,java-17-openjdk,java-latest-openjdk", + )). + WithChecks(checkRepositoryAvailability()). + Print() os.Exit(0) case options.GetB(OPT_HELP): genUsage().Print() @@ -1509,7 +1520,7 @@ func getVersionFromFile() (string, error) { // getAdvisableRubyGemsVersion returns recommended RubyGems version for // given version of Ruby func getAdvisableRubyGemsVersion(rubyVersion string) string { - ver, err := version.Parse(strutil.ReadField(rubyVersion, 0, false, "-")) + ver, err := version.Parse(strutil.ReadField(rubyVersion, 0, false, '-')) if err != nil { return "2.3" @@ -1756,7 +1767,7 @@ func isLibLoaded(glob string) bool { } line = strings.TrimSpace(line) - line = strutil.ReadField(line, 0, false, " ") + line = strutil.ReadField(line, 0, false, ' ') match, _ := filepath.Match(glob, line) @@ -1781,7 +1792,7 @@ func isVersionSupportedByBundler(rubyVersion string) bool { return false } - minor := strutil.ReadField(rubyVersion, 1, false, ".") + minor := strutil.ReadField(rubyVersion, 1, false, '.') if strings.ContainsAny(minor, "012") { return false @@ -1801,8 +1812,8 @@ func parseGemInfo(data string) (string, string) { return data, "" } - return strutil.ReadField(data, 0, false, "="), - strutil.ReadField(data, 1, false, "=") + return strutil.ReadField(data, 0, false, '='), + strutil.ReadField(data, 1, false, '=') } // logFailedAction save data to temporary log file and return path @@ -1855,6 +1866,34 @@ func exit(code int) { // ////////////////////////////////////////////////////////////////////////////////// // +// checkRepositoryAccess checks availability +func checkRepositoryAvailability() support.Check { + chk := support.Check{Status: support.CHECK_OK, Title: "EK Repository availability"} + + resp, err := req.Request{ + URL: "https://rbinstall.kaos.st/" + INDEX_NAME, + AutoDiscard: true, + }.Head() + + if err != nil { + chk.Status, chk.Message = support.CHECK_ERROR, err.Error() + return chk + } + + if resp.StatusCode != 200 { + chk.Status = support.CHECK_ERROR + chk.Message = fmt.Sprintf("Repository returned non-ok status code (%d)", resp.StatusCode) + return chk + } + + chk.Message = fmt.Sprintf( + "Status: %d; Updated: %s", + resp.StatusCode, resp.Response.Header.Get("last-modified"), + ) + + return chk +} + // printCompletion prints completion for given shell func printCompletion() int { info := genUsage() diff --git a/clone/clone.go b/clone/clone.go index 2119a5b..79ec226 100644 --- a/clone/clone.go +++ b/clone/clone.go @@ -2,7 +2,7 @@ package clone // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2023 ESSENTIAL KAOS // +// Copyright (c) 2024 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // @@ -25,6 +25,8 @@ import ( "github.com/essentialkaos/ek/v12/pluralize" "github.com/essentialkaos/ek/v12/progress" "github.com/essentialkaos/ek/v12/req" + "github.com/essentialkaos/ek/v12/support" + "github.com/essentialkaos/ek/v12/support/deps" "github.com/essentialkaos/ek/v12/terminal" "github.com/essentialkaos/ek/v12/terminal/tty" "github.com/essentialkaos/ek/v12/timeutil" @@ -35,7 +37,6 @@ import ( "github.com/essentialkaos/ek/v12/usage/man" "github.com/essentialkaos/rbinstall/index" - "github.com/essentialkaos/rbinstall/support" ) // ////////////////////////////////////////////////////////////////////////////////// // @@ -43,7 +44,7 @@ import ( // App info const ( APP = "RBInstall Clone" - VER = "3.1.3" + VER = "3.1.4" DESC = "Utility for cloning RBInstall repository" ) @@ -80,8 +81,8 @@ type FileInfo struct { var optMap = options.Map{ OPT_YES: {Type: options.BOOL}, OPT_NO_COLOR: {Type: options.BOOL}, - OPT_HELP: {Type: options.BOOL, Alias: "u:usage"}, - OPT_VER: {Type: options.BOOL, Alias: "ver"}, + OPT_HELP: {Type: options.BOOL}, + OPT_VER: {Type: options.MIXED}, OPT_VERB_VER: {Type: options.BOOL}, OPT_COMPLETION: {}, @@ -113,10 +114,11 @@ func Run(gitRev string, gomod []byte) { printMan() os.Exit(0) case options.GetB(OPT_VER): - genAbout(gitRev).Print() + genAbout(gitRev).Print(options.GetS(OPT_VER)) os.Exit(0) case options.GetB(OPT_VERB_VER): - support.Print(APP, VER, gitRev, gomod) + support.Collect(APP, VER).WithRevision(gitRev). + WithDeps(deps.Extract(gomod)).Print() os.Exit(0) case options.GetB(OPT_HELP) || len(args) != 2: genUsage().Print() diff --git a/common/rbinstall.spec b/common/rbinstall.spec index 9c74c58..938e4ca 100644 --- a/common/rbinstall.spec +++ b/common/rbinstall.spec @@ -10,7 +10,7 @@ Summary: Utility for installing prebuilt Ruby to rbenv Name: rbinstall -Version: 3.4.1 +Version: 3.4.2 Release: 0%{?dist} Group: Applications/System License: Apache License, Version 2.0 @@ -38,7 +38,7 @@ Utility for installing different prebuilt versions of Ruby to rbenv. %package gen Summary: Utility for generating RBInstall index -Version: 3.2.3 +Version: 3.2.4 Release: 0%{?dist} Group: Development/Tools @@ -50,7 +50,7 @@ Utility for generating RBInstall index. %package clone Summary: Utility for cloning RBInstall repository -Version: 3.1.3 +Version: 3.1.4 Release: 0%{?dist} Group: Development/Tools @@ -118,6 +118,10 @@ rm -rf %{buildroot} ################################################################################ %changelog +* Wed Mar 20 2024 Anton Novojilov - 3.4.2-0 +- [cli|gen|clone] Improved support information gathering +- Dependencies update + * Wed Jan 24 2024 Anton Novojilov - 3.4.1-0 - Dependencies update diff --git a/gen/gen.go b/gen/gen.go index 58860f0..c71760c 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -2,7 +2,7 @@ package gen // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2023 ESSENTIAL KAOS // +// Copyright (c) 2024 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // @@ -24,6 +24,8 @@ import ( "github.com/essentialkaos/ek/v12/path" "github.com/essentialkaos/ek/v12/sortutil" "github.com/essentialkaos/ek/v12/strutil" + "github.com/essentialkaos/ek/v12/support" + "github.com/essentialkaos/ek/v12/support/deps" "github.com/essentialkaos/ek/v12/terminal/tty" "github.com/essentialkaos/ek/v12/timeutil" "github.com/essentialkaos/ek/v12/usage" @@ -33,7 +35,6 @@ import ( "github.com/essentialkaos/ek/v12/usage/man" "github.com/essentialkaos/rbinstall/index" - "github.com/essentialkaos/rbinstall/support" ) // ////////////////////////////////////////////////////////////////////////////////// // @@ -41,7 +42,7 @@ import ( // App info const ( APP = "RBInstall Gen" - VER = "3.2.3" + VER = "3.2.4" DESC = "Utility for generating RBInstall index" ) @@ -95,7 +96,7 @@ var optMap = options.Map{ OPT_ALIAS: {Value: "alias.json"}, OPT_NO_COLOR: {Type: options.BOOL}, OPT_HELP: {Type: options.BOOL}, - OPT_VER: {Type: options.BOOL}, + OPT_VER: {Type: options.MIXED}, OPT_VERB_VER: {Type: options.BOOL}, OPT_COMPLETION: {}, @@ -129,10 +130,11 @@ func Run(gitRev string, gomod []byte) { printMan() os.Exit(0) case options.GetB(OPT_VER): - genAbout(gitRev).Print() + genAbout(gitRev).Print(options.GetS(OPT_VER)) os.Exit(0) case options.GetB(OPT_VERB_VER): - support.Print(APP, VER, gitRev, gomod) + support.Collect(APP, VER).WithRevision(gitRev). + WithDeps(deps.Extract(gomod)).Print() os.Exit(0) case options.GetB(OPT_HELP) || len(args) == 0: genUsage().Print() diff --git a/go.mod b/go.mod index 47ebbb5..d673be5 100644 --- a/go.mod +++ b/go.mod @@ -3,14 +3,14 @@ module github.com/essentialkaos/rbinstall go 1.18 require ( - github.com/essentialkaos/depsy v1.1.0 - github.com/essentialkaos/ek/v12 v12.98.0 + github.com/essentialkaos/ek/v12 v12.113.1 github.com/essentialkaos/npck v1.6.2 ) require ( + github.com/essentialkaos/depsy v1.1.0 // indirect github.com/essentialkaos/go-linenoise/v3 v3.4.0 // indirect - github.com/klauspost/compress v1.17.4 // indirect - golang.org/x/crypto v0.18.0 // indirect - golang.org/x/sys v0.16.0 // indirect + github.com/klauspost/compress v1.17.7 // indirect + golang.org/x/crypto v0.21.0 // indirect + golang.org/x/sys v0.18.0 // indirect ) diff --git a/go.sum b/go.sum index f03ea59..2ced2eb 100644 --- a/go.sum +++ b/go.sum @@ -1,18 +1,18 @@ github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk= github.com/essentialkaos/depsy v1.1.0 h1:U6dp687UkQwXlZU17Hg2KMxbp3nfZAoZ8duaeUFYvJI= github.com/essentialkaos/depsy v1.1.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8= -github.com/essentialkaos/ek/v12 v12.98.0 h1:DSoP84rmUpNFjfuk8HSL04lkNLC8EzBo38IYoZ0O1qc= -github.com/essentialkaos/ek/v12 v12.98.0/go.mod h1:peB5w8zUkRuDs7m/QG5Z2gMmqzSIs2viAmxzzNFIIoo= +github.com/essentialkaos/ek/v12 v12.113.1 h1:3opV9dwRpIQq1fqg5mkaSEt6ogECL4VLzrH/829qeYg= +github.com/essentialkaos/ek/v12 v12.113.1/go.mod h1:SslW97Se34YQKc08Ume2V/8h/HPTgLS1+Iok64cNF/U= github.com/essentialkaos/go-linenoise/v3 v3.4.0 h1:g72w8x+/HIwOMBVvNaPYp+wMWVHrYZwzFAF7OfZR5Ts= github.com/essentialkaos/go-linenoise/v3 v3.4.0/go.mod h1:t1kNLY2bSMQCy1JXOefD2BDLs/TTPMtTv3DFNV5uDSI= github.com/essentialkaos/npck v1.6.2 h1:OqV74UfA9qoRYbFVsZ+KYH9kY//1nU6uX/HBfAltUQ4= github.com/essentialkaos/npck v1.6.2/go.mod h1:7ziKy4mdUrSMTihDTZKAaxf6uDH2uAlOzsD3Mj2WTyI= -github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4= -github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= +github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg= +github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/index/index.go b/index/index.go index a87e3ae..7b3c71f 100644 --- a/index/index.go +++ b/index/index.go @@ -2,7 +2,7 @@ package index // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2023 ESSENTIAL KAOS // +// Copyright (c) 2024 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/rbinstall-clone.go b/rbinstall-clone.go index e5b7c02..3005876 100644 --- a/rbinstall-clone.go +++ b/rbinstall-clone.go @@ -5,7 +5,7 @@ package main // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2023 ESSENTIAL KAOS // +// Copyright (c) 2024 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/rbinstall-gen.go b/rbinstall-gen.go index 19d492c..36d8435 100644 --- a/rbinstall-gen.go +++ b/rbinstall-gen.go @@ -5,7 +5,7 @@ package main // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2023 ESSENTIAL KAOS // +// Copyright (c) 2024 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/rbinstall.go b/rbinstall.go index 3d9358a..6771783 100644 --- a/rbinstall.go +++ b/rbinstall.go @@ -5,7 +5,7 @@ package main // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2023 ESSENTIAL KAOS // +// Copyright (c) 2024 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/support/support.go b/support/support.go deleted file mode 100644 index 2b05545..0000000 --- a/support/support.go +++ /dev/null @@ -1,164 +0,0 @@ -package support - -// ////////////////////////////////////////////////////////////////////////////////// // -// // -// Copyright (c) 2023 ESSENTIAL KAOS // -// Apache License, Version 2.0 // -// // -// ////////////////////////////////////////////////////////////////////////////////// // - -import ( - "fmt" - "os" - "runtime" - "runtime/debug" - "strings" - - "github.com/essentialkaos/ek/v12/fmtc" - "github.com/essentialkaos/ek/v12/fmtutil" - "github.com/essentialkaos/ek/v12/hash" - "github.com/essentialkaos/ek/v12/strutil" - - "github.com/essentialkaos/depsy" -) - -// ////////////////////////////////////////////////////////////////////////////////// // - -// Pkg contains basic package info -type Pkg struct { - Name string - Version string -} - -// Pkgs is slice with packages -type Pkgs []Pkg - -// ////////////////////////////////////////////////////////////////////////////////// // - -// Print prints verbose info about application, system, dependencies and -// important environment -func Print(app, ver, gitRev string, gomod []byte) { - pkgs := collectEnvInfo() - - fmtutil.SeparatorTitleColorTag = "{s-}" - fmtutil.SeparatorFullscreen = false - fmtutil.SeparatorColorTag = "{s-}" - fmtutil.SeparatorSize = 80 - - showApplicationInfo(app, ver, gitRev) - showOSInfo() - showEnvInfo(pkgs) - showDepsInfo(gomod) - - fmtutil.Separator(false) -} - -// ////////////////////////////////////////////////////////////////////////////////// // - -// showApplicationInfo shows verbose information about application -func showApplicationInfo(app, ver, gitRev string) { - fmtutil.Separator(false, "APPLICATION INFO") - - printInfo(7, "Name", app) - printInfo(7, "Version", ver) - - printInfo(7, "Go", fmtc.Sprintf( - "%s {s}(%s/%s){!}", - strings.TrimLeft(runtime.Version(), "go"), - runtime.GOOS, runtime.GOARCH, - )) - - if gitRev != "" { - if !fmtc.DisableColors && fmtc.IsTrueColorSupported() { - printInfo(7, "Git SHA", gitRev+getHashColorBullet(gitRev)) - } else { - printInfo(7, "Git SHA", gitRev) - } - } - - bin, _ := os.Executable() - binSHA := hash.FileHash(bin) - - if binSHA != "" { - binSHA = strutil.Head(binSHA, 7) - if !fmtc.DisableColors && fmtc.IsTrueColorSupported() { - printInfo(7, "Bin SHA", binSHA+getHashColorBullet(binSHA)) - } else { - printInfo(7, "Bin SHA", binSHA) - } - } -} - -// showDepsInfo shows information about all dependencies -func showDepsInfo(gomod []byte) { - deps := depsy.Extract(gomod, false) - - if len(deps) == 0 { - return - } - - fmtutil.Separator(false, "DEPENDENCIES") - - for _, dep := range deps { - if dep.Extra == "" { - fmtc.Printf(" {s}%8s{!} %s\n", dep.Version, dep.Path) - } else { - fmtc.Printf(" {s}%8s{!} %s {s-}(%s){!}\n", dep.Version, dep.Path, dep.Extra) - } - } -} - -// extractGitRevFromBuildInfo extracts git SHA from embedded build info -func extractGitRevFromBuildInfo() string { - info, ok := debug.ReadBuildInfo() - - if !ok { - return "" - } - - for _, s := range info.Settings { - if s.Key == "vcs.revision" && len(s.Value) > 7 { - return s.Value[:7] - } - } - - return "" -} - -// getHashColorBullet return bullet with color from hash -func getHashColorBullet(v string) string { - if len(v) > 6 { - v = strutil.Head(v, 6) - } - - return fmtc.Sprintf(" {#" + strutil.Head(v, 6) + "}● {!}") -} - -// printInfo formats and prints info record -func printInfo(size int, name, value string) { - name += ":" - size++ - - if value == "" { - fm := fmt.Sprintf(" {*}%%-%ds{!} {s-}—{!}\n", size) - fmtc.Printf(fm, name) - } else { - fm := fmt.Sprintf(" {*}%%-%ds{!} %%s\n", size) - fmtc.Printf(fm, name, value) - } -} - -// ////////////////////////////////////////////////////////////////////////////////// // - -// getMaxSize returns max package name size -func (p Pkgs) getMaxSize() int { - size := 0 - - for _, pkg := range p { - if len(pkg.Name) > size { - size = len(pkg.Name) - } - } - - return size -} diff --git a/support/support_linux.go b/support/support_linux.go deleted file mode 100644 index a15c78d..0000000 --- a/support/support_linux.go +++ /dev/null @@ -1,154 +0,0 @@ -package support - -// ////////////////////////////////////////////////////////////////////////////////// // -// // -// Copyright (c) 2023 ESSENTIAL KAOS // -// Apache License, Version 2.0 // -// // -// ////////////////////////////////////////////////////////////////////////////////// // - -import ( - "os/exec" - "strings" - - "github.com/essentialkaos/ek/v12/fmtc" - "github.com/essentialkaos/ek/v12/fmtutil" - "github.com/essentialkaos/ek/v12/fsutil" - "github.com/essentialkaos/ek/v12/system" - "github.com/essentialkaos/ek/v12/system/container" -) - -// ////////////////////////////////////////////////////////////////////////////////// // - -// showOSInfo shows verbose information about system -func showOSInfo() { - osInfo, err := system.GetOSInfo() - - if err == nil { - fmtutil.Separator(false, "OS INFO") - - printInfo(12, "Name", osInfo.ColoredName()) - printInfo(12, "Pretty Name", osInfo.ColoredPrettyName()) - printInfo(12, "Version", osInfo.Version) - printInfo(12, "ID", osInfo.ID) - printInfo(12, "ID Like", osInfo.IDLike) - printInfo(12, "Version ID", osInfo.VersionID) - printInfo(12, "Version Code", osInfo.VersionCodename) - printInfo(12, "Platform ID", osInfo.PlatformID) - printInfo(12, "CPE", osInfo.CPEName) - } - - systemInfo, err := system.GetSystemInfo() - - if err != nil { - return - } else if osInfo == nil { - fmtutil.Separator(false, "SYSTEM INFO") - printInfo(12, "Name", systemInfo.OS) - } - - printInfo(12, "Arch", systemInfo.Arch) - printInfo(12, "Kernel", systemInfo.Kernel) - - containerEngine := "No" - - switch container.GetEngine() { - case container.DOCKER: - containerEngine = "Yes (Docker)" - case container.PODMAN: - containerEngine = "Yes (Podman)" - case container.LXC: - containerEngine = "Yes (LXC)" - } - - fmtc.NewLine() - - printInfo(12, "Container", containerEngine) -} - -// showEnvInfo shows info about environment -func showEnvInfo(pkgs Pkgs) { - fmtutil.Separator(false, "ENVIRONMENT") - - size := pkgs.getMaxSize() - - for _, pkg := range pkgs { - printInfo(size, pkg.Name, pkg.Version) - } -} - -// collectEnvInfo collects info about packages -func collectEnvInfo() Pkgs { - return Pkgs{ - getPackageInfo("rbinstall"), - getPackageInfo("rbinstall-gen"), - getPackageInfo("rbinstall-clone"), - getPackageInfo("rbenv"), - getPackageInfo("jemalloc"), - getPackageInfo("zlib"), - getPackageInfo("gcc"), - getPackageInfo( - "jre8", "jre11", "jre17", "jdk8", "jdk11", "jdk17", - "java-1.8.0-openjdk", "java-11-openjdk", "java-17-openjdk", - "java-latest-openjdk", - ), - } -} - -// getPackageVersion returns package name and version from package manager database -func getPackageInfo(names ...string) Pkg { - var info Pkg - - if len(names) == 0 { - return Pkg{} - } - - for _, name := range names { - switch { - case isDEBBased(): - info = getDEBPackageInfo(name) - case isRPMBased(): - info = getRPMPackageInfo(name) - } - - if info.Version != "" { - return info - } - } - - return Pkg{names[0], ""} -} - -// isDEBBased returns true if is DEB-based distro -func isRPMBased() bool { - return fsutil.IsExist("/usr/bin/rpm") -} - -// isDEBBased returns true if is DEB-based distro -func isDEBBased() bool { - return fsutil.IsExist("/usr/bin/dpkg-query") -} - -// getRPMPackageInfo returns info about RPM package -func getRPMPackageInfo(name string) Pkg { - cmd := exec.Command("rpm", "-q", name) - out, err := cmd.Output() - - if err != nil || len(out) == 0 { - return Pkg{name, ""} - } - - return Pkg{name, strings.TrimRight(string(out), "\n\r")} -} - -// getDEBPackageInfo returns info about DEB package -func getDEBPackageInfo(name string) Pkg { - cmd := exec.Command("dpkg-query", "--showformat=${Version}", "--show", name) - out, err := cmd.Output() - - if err != nil || len(out) == 0 { - return Pkg{name, ""} - } - - return Pkg{name, string(out)} -}