Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 3.1.2 #150

Merged
merged 9 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,7 @@ func getVersionFromFile() (string, error) {
return "", fmtc.Errorf("Can't read version file: %v", err)
}

versionName := strings.Trim(string(versionData[:]), " \n\r")
versionName := strings.Trim(string(versionData), " \n\r")

if versionName == "" {
return "", fmtc.Errorf("Can't use version file - file malformed")
Expand Down Expand Up @@ -1731,7 +1731,7 @@ func isVersionSupportedByBundler(rubyVersion string) bool {

// getNameWithoutPatchLevel return name without -p0
func getNameWithoutPatchLevel(name string) string {
return strings.Replace(name, "-p0", "", -1)
return strings.ReplaceAll(name, "-p0", "")
}

// parseGemInfo extract name and version of gem
Expand Down Expand Up @@ -1800,11 +1800,11 @@ func printCompletion() int {

switch options.GetS(OPT_COMPLETION) {
case "bash":
fmt.Printf(bash.Generate(info, "rbinstall"))
fmt.Print(bash.Generate(info, "rbinstall"))
case "fish":
fmt.Printf(fish.Generate(info, "rbinstall"))
fmt.Print(fish.Generate(info, "rbinstall"))
case "zsh":
fmt.Printf(zsh.Generate(info, optMap, "rbinstall"))
fmt.Print(zsh.Generate(info, optMap, "rbinstall"))
default:
return 1
}
Expand Down
6 changes: 3 additions & 3 deletions clone/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,11 @@ func printCompletion() int {

switch options.GetS(OPT_COMPLETION) {
case "bash":
fmt.Printf(bash.Generate(info, "rbinstall-clone"))
fmt.Print(bash.Generate(info, "rbinstall-clone"))
case "fish":
fmt.Printf(fish.Generate(info, "rbinstall-clone"))
fmt.Print(fish.Generate(info, "rbinstall-clone"))
case "zsh":
fmt.Printf(zsh.Generate(info, optMap, "rbinstall-clone"))
fmt.Print(zsh.Generate(info, optMap, "rbinstall-clone"))
default:
return 1
}
Expand Down
12 changes: 9 additions & 3 deletions common/rbinstall.spec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

Summary: Utility for installing prebuilt Ruby to rbenv
Name: rbinstall
Version: 3.1.1
Version: 3.1.2
Release: 0%{?dist}
Group: Applications/System
License: Apache License, Version 2.0
Expand Down Expand Up @@ -38,7 +38,7 @@ Utility for installing different prebuilt versions of Ruby to rbenv.
%package gen

Summary: Utility for generating RBInstall index
Version: 3.0.4
Version: 3.1.0
Release: 0%{?dist}
Group: Development/Tools

Expand All @@ -50,7 +50,7 @@ Utility for generating RBInstall index.
%package clone

Summary: Utility for cloning RBInstall repository
Version: 3.0.4
Version: 3.0.5
Release: 0%{?dist}
Group: Development/Tools

Expand Down Expand Up @@ -118,6 +118,12 @@ rm -rf %{buildroot}
################################################################################

%changelog
* Tue Oct 17 2023 Anton Novojilov <[email protected]> - 3.1.2-0
- [gen] Improved alias and eol info handling
- [cli|gen|clone] Improve verbose version info
- [cli|gen|clone] Code refactoring
- Dependencies update

* Tue Oct 03 2023 Anton Novojilov <[email protected]> - 3.1.1-0
- [gen] Fixed bug with searching base version
- Dependencies update
Expand Down
69 changes: 47 additions & 22 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
// App info
const (
APP = "RBInstall Gen"
VER = "3.0.4"
VER = "3.1.0"
DESC = "Utility for generating RBInstall index"
)

Expand Down Expand Up @@ -80,10 +80,7 @@ type fileInfoSlice []FileInfo
func (s fileInfoSlice) Len() int { return len(s) }
func (s fileInfoSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s fileInfoSlice) Less(i, j int) bool {
return sortutil.VersionCompare(
fmtVersionName(s[i].File),
fmtVersionName(s[j].File),
)
return sortutil.VersionCompare(fmtVersionName(s[i].File), fmtVersionName(s[j].File))
}

// ////////////////////////////////////////////////////////////////////////////////// //
Expand All @@ -93,8 +90,8 @@ var aliasInfo map[string]string

var optMap = options.Map{
OPT_OUTPUT: {Value: INDEX_NAME},
OPT_EOL: {},
OPT_ALIAS: {},
OPT_EOL: {Value: "eol.json"},
OPT_ALIAS: {Value: "alias.json"},
OPT_NO_COLOR: {Type: options.BOOL},
OPT_HELP: {Type: options.BOOL, Alias: "u:usage"},
OPT_VER: {Type: options.BOOL, Alias: "ver"},
Expand Down Expand Up @@ -190,33 +187,37 @@ func configureUI() {
}
}

// loadEOLInfo load EOL info from file
// loadEOLInfo loads EOL info from file
func loadEOLInfo() {
eolInfo = make(map[string]bool)

if !options.Has(OPT_EOL) {
return
if !fsutil.CheckPerms("FRS", options.GetS(OPT_EOL)) {
if !options.Has(OPT_EOL) {
return
}
}

err := jsonutil.Read(options.GetS(OPT_EOL), &eolInfo)

if err != nil {
printErrorAndExit(err.Error())
printErrorAndExit("Can't read EOL data: %v", err)
}
}

// loadAliasInfo loads aliases info
func loadAliasInfo() {
aliasInfo = make(map[string]string)

if !options.Has(OPT_ALIAS) {
return
if !fsutil.CheckPerms("FRS", options.GetS(OPT_ALIAS)) {
if !options.Has(OPT_ALIAS) {
return
}
}

err := jsonutil.Read(options.GetS(OPT_ALIAS), &aliasInfo)

if err != nil {
printErrorAndExit(err.Error())
printErrorAndExit("Can't read alias data: %v", err)
}
}

Expand Down Expand Up @@ -268,7 +269,7 @@ func buildIndex(dataDir string) {
alreadyExist := false

filePath := path.Join(dataDir, fileInfo.OS, fileInfo.Arch, fileInfo.File)
fileName := strings.Replace(fileInfo.File, ".tzst", "", -1)
fileName := strutil.Exclude(fileInfo.File, ".tzst")
fileSize := fsutil.GetSize(filePath)
fileAdded, _ := fsutil.GetCTime(filePath)

Expand Down Expand Up @@ -330,6 +331,10 @@ func buildIndex(dataDir string) {
}

printIndexStats(newIndex)
printExtraInfo()

fmtutil.Separator(false)

saveIndex(outputFile, newIndex)

fmtc.Printf(
Expand Down Expand Up @@ -415,8 +420,28 @@ func printIndexStats(i *index.Index) {
fmtutil.PrettyNum(i.Meta.Items),
fmtutil.PrettySize(i.Meta.Size, " "),
)
}

fmtutil.Separator(false)
// printExtraInfo prints info about used alias/eol data
func printExtraInfo() {
fmtutil.Separator(false, "EXTRA")

eolModTime, _ := fsutil.GetMTime(options.GetS(OPT_EOL))
aliasModTime, _ := fsutil.GetMTime(options.GetS(OPT_ALIAS))

fmtc.If(len(eolInfo) == 0).Println(" {*}EOL: {!} {s}—{!}")
fmtc.If(len(eolInfo) != 0).Printf(
" {*}EOL: {!} %s {s-}(%s){!}\n",
options.GetS(OPT_EOL),
timeutil.Format(eolModTime, "%Y/%m/%d %H:%M"),
)

fmtc.If(len(aliasInfo) == 0).Println(" {*}Alias:{!} {s}—{!}")
fmtc.If(len(aliasInfo) != 0).Printf(
" {*}Alias:{!} %s {s-}(%s){!}\n",
options.GetS(OPT_ALIAS),
timeutil.Format(aliasModTime, "%Y/%m/%d %H:%M"),
)
}

// saveIndex saves index data as JSON to file
Expand All @@ -435,7 +460,7 @@ func saveIndex(outputFile string, i *index.Index) {
err = os.WriteFile(outputFile, indexData, 0644)

if err != nil {
printErrorAndExit(err.Error())
printErrorAndExit("Can't save index: %v", err)
}

os.Chmod(outputFile, 0644)
Expand Down Expand Up @@ -529,11 +554,11 @@ func printCompletion() int {

switch options.GetS(OPT_COMPLETION) {
case "bash":
fmt.Printf(bash.Generate(info, "rbinstall-clone"))
fmt.Print(bash.Generate(info, "rbinstall-clone"))
case "fish":
fmt.Printf(fish.Generate(info, "rbinstall-clone"))
fmt.Print(fish.Generate(info, "rbinstall-clone"))
case "zsh":
fmt.Printf(zsh.Generate(info, optMap, "rbinstall-clone"))
fmt.Print(zsh.Generate(info, optMap, "rbinstall-clone"))
default:
return 1
}
Expand All @@ -558,8 +583,8 @@ func genUsage() *usage.Info {
info.AppNameColorTag = "{*}" + colorTagApp

info.AddOption(OPT_OUTPUT, "Custom index output {s-}(default: index.json){!}", "file")
info.AddOption(OPT_EOL, "File with EOL information", "file")
info.AddOption(OPT_ALIAS, "File with aliases information", "file")
info.AddOption(OPT_EOL, "File with EOL information {s-}(default: eol.json){!}", "file")
info.AddOption(OPT_ALIAS, "File with aliases information {s-}(default: alias.json){!}", "file")
info.AddOption(OPT_NO_COLOR, "Disable colors in output")
info.AddOption(OPT_HELP, "Show this help message")
info.AddOption(OPT_VER, "Show version")
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ go 1.18

require (
github.com/essentialkaos/depsy v1.1.0
github.com/essentialkaos/ek/v12 v12.79.0
github.com/essentialkaos/ek/v12 v12.82.0
github.com/essentialkaos/npck v1.6.1
)

require (
github.com/essentialkaos/go-linenoise/v3 v3.4.0 // indirect
github.com/klauspost/compress v1.17.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/sys v0.12.0 // indirect
github.com/klauspost/compress v1.17.1 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/sys v0.13.0 // indirect
)
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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.79.0 h1:Dq/bCqk8/N5h/r5jJA2UHc1YoUEVYcc7xnR0DI5L9wA=
github.com/essentialkaos/ek/v12 v12.79.0/go.mod h1:S9/XSKhEAdylL3PF8GAnUeKKyd92VrDGR4YGacHfz0c=
github.com/essentialkaos/ek/v12 v12.82.0 h1:8JqG7E1RWhMJq2CuSV0oaR96pmEjngLPG3cnJ++EJeQ=
github.com/essentialkaos/ek/v12 v12.82.0/go.mod h1:X0gkyjBCP4QiD+sV4D52aquLDLGUmHteMEL7Rsgbev0=
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.1 h1:cFhLRRFNbl7tBXQD2+EkzTHy6y7+oxfvwsVgbhaFvUg=
github.com/essentialkaos/npck v1.6.1/go.mod h1:Leny9a2R4otIGqZdnrs8swhI9KvwO+Rmmn2zThpPoN4=
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/compress v1.17.1 h1:NE3C767s2ak2bweCZo3+rdP4U/HoyVXLv/X9f2gPS5g=
github.com/klauspost/compress v1.17.1/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
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.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
6 changes: 3 additions & 3 deletions index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ type versionInfoSlice []*VersionInfo
func (s versionInfoSlice) Len() int { return len(s) }
func (s versionInfoSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s versionInfoSlice) Less(i, j int) bool {
iv := strings.Replace(s[i].Name, "-", ".", -1)
jv := strings.Replace(s[j].Name, "-", ".", -1)
iv := strings.ReplaceAll(s[i].Name, "-", ".")
jv := strings.ReplaceAll(s[j].Name, "-", ".")

return sortutil.VersionCompare(iv, jv)
}
Expand All @@ -86,7 +86,7 @@ func (s versionInfoSlice) Less(i, j int) bool {
// NewIndex return pointer to new index struct
func NewIndex() *Index {
return &Index{
UUID: uuid.GenUUID(),
UUID: uuid.UUID4().String(),
Meta: &Metadata{},
Data: make(map[string]DistData),
}
Expand Down
2 changes: 1 addition & 1 deletion support/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func getHashColorBullet(v string) string {

// printInfo formats and prints info record
func printInfo(size int, name, value string) {
name = name + ":"
name += ":"
size++

if value == "" {
Expand Down
24 changes: 13 additions & 11 deletions support/support_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"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"
)

// ////////////////////////////////////////////////////////////////////////////////// //
Expand All @@ -26,37 +27,38 @@ func showOSInfo() {
if err == nil {
fmtutil.Separator(false, "OS INFO")

printInfo(12, "Name", osInfo.Name)
printInfo(12, "Pretty Name", osInfo.PrettyName)
printInfo(12, "Version", osInfo.VersionID)
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)
}
} 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 {
case fsutil.IsExist("/.dockerenv"):
switch container.GetEngine() {
case container.DOCKER:
containerEngine = "Yes (Docker)"
case fsutil.IsExist("/run/.containerenv"):
case container.PODMAN:
containerEngine = "Yes (Podman)"
case container.LXC:
containerEngine = "Yes (LXC)"
}

fmtc.NewLine()
Expand Down