From 8b0a22df39a87410c60892e3d2b1ee86f5e5c608 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Thu, 12 Oct 2023 22:18:02 +0300 Subject: [PATCH 01/30] Code refactoring --- cli/barcode.go | 2 +- cli/cli.go | 19 +++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/cli/barcode.go b/cli/barcode.go index 3f08d816..ce2f092f 100644 --- a/cli/barcode.go +++ b/cli/barcode.go @@ -55,7 +55,7 @@ func getPackagesInfo(pkgs []string) ([]byte, error) { // getRPMPackagesInfo returns info about installed packages from rpm func getRPMPackagesInfo(pkgs []string) ([]byte, error) { - cmd := exec.Command("rpm", "-q", "--queryformat", "%{FILEMD5S}\n") + cmd := exec.Command("rpm", "-q", "--qf", "%{pkgid}\n") cmd.Env = []string{"LC_ALL=C"} cmd.Args = append(cmd.Args, pkgs...) diff --git a/cli/cli.go b/cli/cli.go index 8c773f18..453c1d91 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -41,7 +41,7 @@ import ( // Application info const ( APP = "bibop" - VER = "7.5.0" + VER = "7.5.1" DESC = "Utility for testing command-line tools" ) @@ -261,7 +261,7 @@ func process(file string) { switch { case options.GetB(OPT_LIST_PACKAGES), options.GetB(OPT_LIST_PACKAGES_FLAT): - listPackages(r.Packages) + listPackages(r) os.Exit(0) case options.GetB(OPT_VARIABLES): listVariables(r) @@ -320,16 +320,16 @@ func validate(e *executor.Executor, r *recipe.Recipe, tags []string) { } // listPackages shows list packages required by recipe -func listPackages(pkgs []string) { - if len(pkgs) == 0 { +func listPackages(r *recipe.Recipe) { + if len(r.Packages) == 0 { return } if options.GetB(OPT_LIST_PACKAGES_FLAT) { - fmt.Println(strings.Join(pkgs, " ")) + fmt.Println(strings.Join(r.Packages, " ")) } else { fmtc.If(!rawOutput).NewLine() - for _, pkg := range pkgs { + for _, pkg := range r.Packages { fmtc.If(!rawOutput).Printf("{s-}•{!} %s\n", pkg) fmtc.If(rawOutput).Printf("%s\n", pkg) } @@ -444,12 +444,7 @@ func printCompletion() int { // printMan prints man page func printMan() { - fmt.Println( - man.Generate( - genUsage(), - genAbout(""), - ), - ) + fmt.Println(man.Generate(genUsage(), genAbout(""))) } // genUsage generates usage info From 9fc220c8b083bfbc5718632fff96b35530a42a22 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Thu, 12 Oct 2023 22:26:10 +0300 Subject: [PATCH 02/30] Improve support info collecting --- cli/support/support.go | 22 ++++++++++++++++++++++ cli/support/support_linux.go | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cli/support/support.go b/cli/support/support.go index 9374af07..0e38d77c 100644 --- a/cli/support/support.go +++ b/cli/support/support.go @@ -11,6 +11,7 @@ import ( "fmt" "os" "runtime" + "runtime/debug" "strings" "github.com/essentialkaos/ek/v12/fmtc" @@ -67,6 +68,10 @@ func showApplicationInfo(app, ver, gitRev string) { runtime.GOOS, runtime.GOARCH, )) + if gitRev == "" { + gitRev = extractGitRevFromBuildInfo() + } + if gitRev != "" { if !fmtc.DisableColors && fmtc.IsTrueColorSupported() { printInfo(7, "Git SHA", gitRev+getHashColorBullet(gitRev)) @@ -107,6 +112,23 @@ func showDepsInfo(gomod []byte) { } } +// 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 { diff --git a/cli/support/support_linux.go b/cli/support/support_linux.go index 99f08a05..390b205d 100644 --- a/cli/support/support_linux.go +++ b/cli/support/support_linux.go @@ -28,7 +28,7 @@ func showOSInfo() { printInfo(12, "Name", osInfo.Name) printInfo(12, "Pretty Name", osInfo.PrettyName) - printInfo(12, "Version", osInfo.VersionID) + printInfo(12, "Version", osInfo.Version) printInfo(12, "ID", osInfo.ID) printInfo(12, "ID Like", osInfo.IDLike) printInfo(12, "Version ID", osInfo.VersionID) From cc041f293254e9dfa8aa214573fd46a0da7c26bb Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Thu, 12 Oct 2023 23:20:23 +0300 Subject: [PATCH 03/30] Add support of symlinks to bibop-massive script --- scripts/bibop-massive | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/bibop-massive b/scripts/bibop-massive index b1d0b73c..18b01aef 100755 --- a/scripts/bibop-massive +++ b/scripts/bibop-massive @@ -267,7 +267,7 @@ processRecipes() { if [[ -n "$recipe_list" ]] ; then recipes="$recipes $recipe_list" fi - elif [[ -f $recipe && $recipe = *.recipe ]]; then + elif [[ -e $recipe && $recipe = *.recipe ]]; then recipes="$recipes $recipe" else error "Can't use $recipe as a recipe source" From 431b498b6690721bf00ef63d81cd377cbabc9c08 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Thu, 12 Oct 2023 23:22:24 +0300 Subject: [PATCH 04/30] Dependencies update --- cli/support/support_linux.go | 4 ++-- go.mod | 4 ++-- go.sum | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cli/support/support_linux.go b/cli/support/support_linux.go index 390b205d..62abc3fe 100644 --- a/cli/support/support_linux.go +++ b/cli/support/support_linux.go @@ -26,8 +26,8 @@ func showOSInfo() { if err == nil { fmtutil.Separator(false, "OS INFO") - printInfo(12, "Name", osInfo.Name) - printInfo(12, "Pretty Name", osInfo.PrettyName) + 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) diff --git a/go.mod b/go.mod index 86436757..2b5089bd 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/buger/jsonparser v1.1.1 github.com/essentialkaos/check v1.4.0 github.com/essentialkaos/depsy v1.1.0 - github.com/essentialkaos/ek/v12 v12.79.0 + github.com/essentialkaos/ek/v12 v12.80.0 github.com/google/goterm v0.0.0-20200907032337-555d40f16ae2 ) @@ -14,5 +14,5 @@ require ( github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect - golang.org/x/sys v0.12.0 // indirect + golang.org/x/sys v0.13.0 // indirect ) diff --git a/go.sum b/go.sum index e9ebc632..957543da 100644 --- a/go.sum +++ b/go.sum @@ -5,8 +5,8 @@ github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1n github.com/essentialkaos/check v1.4.0/go.mod h1:LMKPZ2H+9PXe7Y2gEoKyVAwUqXVgx7KtgibfsHJPus0= 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.80.0 h1:Yy3VF9J18qdhMZt1Tl7fKtjLvg6PdZX5rcDdk92KNys= +github.com/essentialkaos/ek/v12 v12.80.0/go.mod h1:X0gkyjBCP4QiD+sV4D52aquLDLGUmHteMEL7Rsgbev0= github.com/google/goterm v0.0.0-20200907032337-555d40f16ae2 h1:CVuJwN34x4xM2aT4sIKhmeib40NeBPhRihNjQmpJsA4= github.com/google/goterm v0.0.0-20200907032337-555d40f16ae2/go.mod h1:nOFQdrUlIlx6M6ODdSpBj1NVA+VgLC6kmw60mkw34H4= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= @@ -17,5 +17,5 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= From 7fd95316d754105ad23fa502a363eb24d3b33eb0 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Fri, 13 Oct 2023 22:51:30 +0300 Subject: [PATCH 05/30] Add better recipes filtering to bibop-massive script --- scripts/bibop-massive | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/bibop-massive b/scripts/bibop-massive index 18b01aef..7b0dd652 100755 --- a/scripts/bibop-massive +++ b/scripts/bibop-massive @@ -3,7 +3,7 @@ ################################################################################ APP="bibop-massive" -VER="1.11.0" +VER="1.12.0" DESC="Utility for mass package testing" ################################################################################ @@ -262,7 +262,7 @@ processRecipes() { for recipe in "$@" ; do if [[ -d $recipe ]] ; then - recipe_list=$(find "$recipe" -type f -name "*.recipe" | grep -vE '\-el[7-9]') + recipe_list=$(find "$recipe" -name "*.recipe") if [[ -n "$recipe_list" ]] ; then recipes="$recipes $recipe_list" @@ -296,9 +296,14 @@ filterRecipes() { for recipe in $recipe_list ; do if [[ -n "$dist" && -z "$validate" ]] ; then - # Check for dist specific recipe - if [[ -f "${recipe%.recipe}-el${dist}.recipe" ]] ; then - recipe="${recipe%.recipe}-el${dist}.recipe" + if [[ $recipe =~ .*-el[7-9]\.recipe$ ]] ; then + if [[ "$recipe" != "${recipe%-el?.recipe}-el${dist}.recipe" ]] ; then + continue + fi + else + if [[ -e "${recipe%.recipe}-el${dist}.recipe" ]] ; then + continue + fi fi fi From 2e6026297c9bc33aa38ebbcdaec21ce16fc93cc2 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sat, 14 Oct 2023 22:51:39 +0300 Subject: [PATCH 06/30] Improve install/uninstall actions in bibop-massive script --- scripts/bibop-massive | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/scripts/bibop-massive b/scripts/bibop-massive index 7b0dd652..6a69886d 100755 --- a/scripts/bibop-massive +++ b/scripts/bibop-massive @@ -100,6 +100,9 @@ max_recipe_len=0 # Path to package manager log file pm_log="" +# Pre install transaction ID +preinstall_transaction_id="" + # Canceled flag is_canceled="" @@ -733,6 +736,8 @@ checkPackagesAvailability() { installPackages() { local opts pkg_count tmp_output status problems + preinstall_transaction_id=$(getLastTransactionID) + log "Installing packages → $*" truncate -s 0 "$pm_log" @@ -775,12 +780,16 @@ installPackages() { installPackagesVerbose() { local pkg_list="$*" + preinstall_transaction_id=$(getLastTransactionID) + show "Installing ${pkg_list// /, }…\n" $BOLD # shellcheck disable=SC2046 LC_ALL=C yum -y $(getPMOpts) install "$@" - return $? + status=$? + + return $status } # Uninstall required packages @@ -794,6 +803,11 @@ uninstallPackages() { truncate -s 0 "$pm_log" + if [[ "$preinstall_transaction_id" == "$(getLastTransactionID)" ]] ; then + log "No packages were installed, nothing to uninstall" + return $STATUS_OK + fi + tmp_output=$(mktemp) yum -y history undo last &> "$tmp_output" @@ -829,6 +843,11 @@ uninstallPackages() { uninstallPackagesVerbose() { show "Uninstalling packages…\n" $BOLD + if [[ "$preinstall_transaction_id" == "$(getLastTransactionID)" ]] ; then + show "No packages were installed, nothing to uninstall. Continue…\n" $GREY + return $STATUS_OK + fi + yum -y history undo last return $? @@ -961,6 +980,14 @@ cleanPMCache() { fi } +# Get ID of the latest transaction in history +# +# Code: No +# Echo: ID (Number) +getLastTransactionID() { + yum history list | grep -A2 'ID ' | tail -1 | tr -s ' ' | sed 's/^ \+//' | cut -f1 -d' ' +} + # Generate list of YUM/DNF options # # Code: No From 9a6efbcd9640ebf16449766e3d2eeea6fc2e0205 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sat, 14 Oct 2023 23:24:01 +0300 Subject: [PATCH 07/30] Improve install/uninstall actions in bibop-massive script --- scripts/bibop-massive | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/bibop-massive b/scripts/bibop-massive index 6a69886d..0c89025c 100755 --- a/scripts/bibop-massive +++ b/scripts/bibop-massive @@ -844,7 +844,7 @@ uninstallPackagesVerbose() { show "Uninstalling packages…\n" $BOLD if [[ "$preinstall_transaction_id" == "$(getLastTransactionID)" ]] ; then - show "No packages were installed, nothing to uninstall. Continue…\n" $GREY + show "No packages were installed, nothing to uninstall. Continue…" $GREY return $STATUS_OK fi From 0a127cac91548da303abd67e5ba5f97796170f90 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sun, 15 Oct 2023 11:39:10 +0300 Subject: [PATCH 08/30] Migrate from goterm/term to creack/pty --- cli/cli.go | 2 +- cli/executor/executor.go | 53 ++++++++++++++++++++++++++-------------- go.mod | 2 +- go.sum | 4 +-- 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index 453c1d91..e0040272 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -41,7 +41,7 @@ import ( // Application info const ( APP = "bibop" - VER = "7.5.1" + VER = "8.0.0" DESC = "Utility for testing command-line tools" ) diff --git a/cli/executor/executor.go b/cli/executor/executor.go index ffa34ff2..0cee2cd1 100644 --- a/cli/executor/executor.go +++ b/cli/executor/executor.go @@ -28,7 +28,7 @@ import ( "github.com/essentialkaos/ek/v12/timeutil" "github.com/essentialkaos/ek/v12/tmp" - "github.com/google/goterm/term" + "github.com/creack/pty" "github.com/essentialkaos/bibop/action" "github.com/essentialkaos/bibop/recipe" @@ -71,7 +71,13 @@ type ValidationConfig struct { type CommandEnv struct { cmd *exec.Cmd output *action.OutputContainer - pty *term.PTY + term *PTY +} + +// PTY contains pseudo-terminal structs +type PTY struct { + pty *os.File + tty *os.File } // ////////////////////////////////////////////////////////////////////////////////// // @@ -201,6 +207,23 @@ func (e *Executor) Run(rr render.Renderer, r *recipe.Recipe, tags []string) bool // ////////////////////////////////////////////////////////////////////////////////// // +// Close closes tty and pty +func (t *PTY) Close() { + if t == nil { + return + } + + if t.pty != nil { + t.pty.Close() + } + + if t.tty != nil { + t.pty.Close() + } +} + +// ////////////////////////////////////////////////////////////////////////////////// // + // applyRecipeOptions applies recipe options to executor func applyRecipeOptions(e *Executor, rr render.Renderer, r *recipe.Recipe) { if r.HTTPSSkipVerify { @@ -319,7 +342,7 @@ func execCommand(c *recipe.Command) (*CommandEnv, error) { return nil, err } - cmdEnv.pty, err = createPseudoTerminal(cmdEnv.cmd) + cmdEnv.term, err = createPTY(cmdEnv.cmd) if err != nil { return nil, err @@ -332,6 +355,7 @@ func execCommand(c *recipe.Command) (*CommandEnv, error) { err = cmdEnv.cmd.Start() if err != nil { + cmdEnv.term.Close() return nil, err } @@ -408,7 +432,7 @@ func runAction(a *recipe.Action, cmdEnv *CommandEnv) error { case recipe.ACTION_EXPECT: return action.Expect(a, cmdEnv.output) case recipe.ACTION_PRINT: - return action.Input(a, cmdEnv.pty.Master, cmdEnv.output) + return action.Input(a, cmdEnv.term.pty, cmdEnv.output) case recipe.ACTION_WAIT_OUTPUT: return action.WaitOutput(a, cmdEnv.output) case recipe.ACTION_OUTPUT_CONTAINS: @@ -436,25 +460,18 @@ func runAction(a *recipe.Action, cmdEnv *CommandEnv) error { return handler(a) } -// createPseudoTerminal creates pseudo-terminal -func createPseudoTerminal(cmd *exec.Cmd) (*term.PTY, error) { - pty, err := term.OpenPTY() +// createPTY creates pseudo-terminal +func createPTY(cmd *exec.Cmd) (*PTY, error) { + pty, tty, err := pty.Open() if err != nil { return nil, err } - termios := &term.Termios{} - termios.Raw() - termios.Set(pty.Slave) - + cmd.Stdin, cmd.Stdout, cmd.Stderr = tty, tty, tty cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true, Setctty: true} - cmd.Stdin = pty.Slave - cmd.Stdout = pty.Slave - cmd.Stderr = pty.Slave - - return pty, nil + return &PTY{pty: pty, tty: tty}, nil } // outputIOLoop reads data from reader and writes it to output store @@ -462,14 +479,14 @@ func outputIOLoop(cmdEnv *CommandEnv) { buf := make([]byte, 8192) for { - n, _ := cmdEnv.pty.Master.Read(buf[:cap(buf)]) + n, _ := cmdEnv.term.pty.Read(buf[:cap(buf)]) if n > 0 { cmdEnv.output.Write(buf[:n]) } if cmdEnv.cmd.ProcessState != nil && cmdEnv.cmd.ProcessState.Exited() { - cmdEnv.pty.Close() + cmdEnv.term.Close() return } } diff --git a/go.mod b/go.mod index 2b5089bd..7c332253 100644 --- a/go.mod +++ b/go.mod @@ -4,10 +4,10 @@ go 1.18 require ( github.com/buger/jsonparser v1.1.1 + github.com/creack/pty v1.1.18 github.com/essentialkaos/check v1.4.0 github.com/essentialkaos/depsy v1.1.0 github.com/essentialkaos/ek/v12 v12.80.0 - github.com/google/goterm v0.0.0-20200907032337-555d40f16ae2 ) require ( diff --git a/go.sum b/go.sum index 957543da..0562d89d 100644 --- a/go.sum +++ b/go.sum @@ -1,14 +1,14 @@ github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= +github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk= github.com/essentialkaos/check v1.4.0/go.mod h1:LMKPZ2H+9PXe7Y2gEoKyVAwUqXVgx7KtgibfsHJPus0= 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.80.0 h1:Yy3VF9J18qdhMZt1Tl7fKtjLvg6PdZX5rcDdk92KNys= github.com/essentialkaos/ek/v12 v12.80.0/go.mod h1:X0gkyjBCP4QiD+sV4D52aquLDLGUmHteMEL7Rsgbev0= -github.com/google/goterm v0.0.0-20200907032337-555d40f16ae2 h1:CVuJwN34x4xM2aT4sIKhmeib40NeBPhRihNjQmpJsA4= -github.com/google/goterm v0.0.0-20200907032337-555d40f16ae2/go.mod h1:nOFQdrUlIlx6M6ODdSpBj1NVA+VgLC6kmw60mkw34H4= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= From d4ddae0152fad04e06a28fc538b4cc930b015174 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 17 Oct 2023 02:50:24 +0000 Subject: [PATCH 09/30] Bump github.com/essentialkaos/ek/v12 from 12.80.0 to 12.82.0 Bumps [github.com/essentialkaos/ek/v12](https://github.com/essentialkaos/ek) from 12.80.0 to 12.82.0. - [Release notes](https://github.com/essentialkaos/ek/releases) - [Changelog](https://github.com/essentialkaos/ek/blob/master/CHANGELOG.md) - [Commits](https://github.com/essentialkaos/ek/compare/v12.80.0...v12.82.0) --- updated-dependencies: - dependency-name: github.com/essentialkaos/ek/v12 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7c332253..c4ac1cca 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/creack/pty v1.1.18 github.com/essentialkaos/check v1.4.0 github.com/essentialkaos/depsy v1.1.0 - github.com/essentialkaos/ek/v12 v12.80.0 + github.com/essentialkaos/ek/v12 v12.82.0 ) require ( diff --git a/go.sum b/go.sum index 0562d89d..ced9f1af 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,8 @@ github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1n github.com/essentialkaos/check v1.4.0/go.mod h1:LMKPZ2H+9PXe7Y2gEoKyVAwUqXVgx7KtgibfsHJPus0= 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.80.0 h1:Yy3VF9J18qdhMZt1Tl7fKtjLvg6PdZX5rcDdk92KNys= -github.com/essentialkaos/ek/v12 v12.80.0/go.mod h1:X0gkyjBCP4QiD+sV4D52aquLDLGUmHteMEL7Rsgbev0= +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/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= From 48cef639b03586ea7c8c2d10fedf0b0c6bf1add1 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 18 Oct 2023 00:04:08 +0300 Subject: [PATCH 10/30] Improve verbose version info --- cli/support/support_linux.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cli/support/support_linux.go b/cli/support/support_linux.go index 62abc3fe..de731ad7 100644 --- a/cli/support/support_linux.go +++ b/cli/support/support_linux.go @@ -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" ) // ////////////////////////////////////////////////////////////////////////////////// // @@ -33,6 +34,7 @@ func showOSInfo() { 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) } @@ -52,11 +54,13 @@ func showOSInfo() { 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() From 4c5ea831ef077f8d2c49652033e5e9827bb55157 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 18 Oct 2023 00:09:30 +0300 Subject: [PATCH 11/30] Code refactoring --- cli/support/support_linux.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cli/support/support_linux.go b/cli/support/support_linux.go index de731ad7..ef1c5671 100644 --- a/cli/support/support_linux.go +++ b/cli/support/support_linux.go @@ -42,11 +42,9 @@ func showOSInfo() { 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) From d4b4dbd7cfbfa117b0188efcf30e178d8140507a Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 18 Oct 2023 00:25:17 +0300 Subject: [PATCH 12/30] Code refactoring --- action/basic.go | 2 +- action/fs.go | 2 +- action/http.go | 13 ++----------- action/io.go | 4 ++-- action/service.go | 2 +- action/system.go | 8 ++++---- cli/cli.go | 6 +++--- cli/support/support.go | 2 +- parser/parser.go | 2 +- render/renderer_terminal.go | 2 +- render/renderer_xml.go | 6 +++--- 11 files changed, 20 insertions(+), 29 deletions(-) diff --git a/action/basic.go b/action/basic.go index 289ae5dd..b599a95f 100644 --- a/action/basic.go +++ b/action/basic.go @@ -29,7 +29,7 @@ func Wait(action *recipe.Action) error { return err } - durSec = mathutil.BetweenF64(durSec, 0.01, 3600.0) + durSec = mathutil.Between(durSec, 0.01, 3600.0) time.Sleep(timeutil.SecondsToDuration(durSec)) diff --git a/action/fs.go b/action/fs.go index 382de2d0..ce116e44 100644 --- a/action/fs.go +++ b/action/fs.go @@ -604,7 +604,7 @@ func Cleanup(action *recipe.Action) error { err = os.RemoveAll(obj) if err != nil { - return fmt.Errorf("Can't remove object %q: %v", err) + return fmt.Errorf("Can't remove object %q: %v", obj, err) } } diff --git a/action/http.go b/action/http.go index 4f976c17..dc48b84c 100644 --- a/action/http.go +++ b/action/http.go @@ -297,16 +297,7 @@ func HTTPSetHeader(action *recipe.Action) error { // ////////////////////////////////////////////////////////////////////////////////// // -// isHTTPMethodSupported returns true if HTTP method is supported -func isHTTPMethodSupported(method string) bool { - switch method { - case req.GET, req.POST, req.DELETE, req.PUT, req.PATCH, req.HEAD: - return true - } - - return false -} - +// checkRequestData checks request data func checkRequestData(method, payload string) error { switch method { case req.GET, req.POST, req.DELETE, req.PUT, req.PATCH, req.HEAD: @@ -353,6 +344,6 @@ func makeHTTPRequest(action *recipe.Action, method, url, payload string) *req.Re // parseJSONQuery converts json query to slice func parseJSONQuery(q string) []string { - q = strings.Replace(q, "[", ".[", -1) + q = strings.ReplaceAll(q, "[", ".[") return strings.Split(q, ".") } diff --git a/action/io.go b/action/io.go index 3e809804..e22e350a 100644 --- a/action/io.go +++ b/action/io.go @@ -48,7 +48,7 @@ func Expect(action *recipe.Action, output *OutputContainer) error { } start := time.Now() - timeout = mathutil.BetweenF64(timeout, 0.01, 3600.0) + timeout = mathutil.Between(timeout, 0.01, 3600.0) timeoutDur := timeutil.SecondsToDuration(timeout) for range time.NewTicker(_DATA_READ_PERIOD).C { @@ -98,7 +98,7 @@ func Input(action *recipe.Action, input *os.File, output *OutputContainer) error } if !strings.HasSuffix(text, "\n") { - text = text + "\n" + text += "\n" } output.Purge() diff --git a/action/service.go b/action/service.go index 4124ed65..377fd9b8 100644 --- a/action/service.go +++ b/action/service.go @@ -109,7 +109,7 @@ func WaitService(action *recipe.Action) error { } start := time.Now() - timeout = mathutil.BetweenF64(timeout, 0.01, 3600.0) + timeout = mathutil.Between(timeout, 0.01, 3600.0) timeoutDur := timeutil.SecondsToDuration(timeout) for range time.NewTicker(time.Second / 2).C { diff --git a/action/system.go b/action/system.go index e83adc7c..f5370e7e 100644 --- a/action/system.go +++ b/action/system.go @@ -87,7 +87,7 @@ func WaitPID(action *recipe.Action) error { } start := time.Now() - timeout = mathutil.BetweenF64(timeout, 0.01, 3600.0) + timeout = mathutil.Between(timeout, 0.01, 3600.0) timeoutDur := timeutil.SecondsToDuration(timeout) for range time.NewTicker(25 * time.Millisecond).C { @@ -147,7 +147,7 @@ func WaitFS(action *recipe.Action) error { } start := time.Now() - timeout = mathutil.BetweenF64(timeout, 0.01, 3600.0) + timeout = mathutil.Between(timeout, 0.01, 3600.0) timeoutDur := timeutil.SecondsToDuration(timeout) for range time.NewTicker(25 * time.Millisecond).C { @@ -203,7 +203,7 @@ func WaitConnect(action *recipe.Action) error { } start := time.Now() - timeout = mathutil.BetweenF64(timeout, 0.01, 3600.0) + timeout = mathutil.Between(timeout, 0.01, 3600.0) timeoutDur := timeutil.SecondsToDuration(timeout) for range time.NewTicker(25 * time.Millisecond).C { @@ -264,7 +264,7 @@ func Connect(action *recipe.Action) error { timeout = 1.0 } - timeout = mathutil.BetweenF64(timeout, 0.01, 3600.0) + timeout = mathutil.Between(timeout, 0.01, 3600.0) timeoutDur := timeutil.SecondsToDuration(timeout) conn, err := net.DialTimeout(network, address, timeoutDur) diff --git a/cli/cli.go b/cli/cli.go index e0040272..92eac1fd 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -430,11 +430,11 @@ func printCompletion() int { switch options.GetS(OPT_COMPLETION) { case "bash": - fmt.Printf(bash.Generate(info, "bibop", "recipe")) + fmt.Print(bash.Generate(info, "bibop", "recipe")) case "fish": - fmt.Printf(fish.Generate(info, "bibop")) + fmt.Print(fish.Generate(info, "bibop")) case "zsh": - fmt.Printf(zsh.Generate(info, optMap, "bibop", "*.recipe")) + fmt.Print(zsh.Generate(info, optMap, "bibop", "*.recipe")) default: return 1 } diff --git a/cli/support/support.go b/cli/support/support.go index 0e38d77c..cfdd9493 100644 --- a/cli/support/support.go +++ b/cli/support/support.go @@ -140,7 +140,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 == "" { diff --git a/parser/parser.go b/parser/parser.go index 6fd04967..79b7c9a3 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -273,7 +273,7 @@ func getTokenInfo(keyword string) recipe.TokenInfo { // isUselessRecipeLine return if line doesn't contains recipe data func isUselessRecipeLine(line string) bool { // Skip empty lines - if line == "" || strings.Replace(line, " ", "", -1) == "" { + if line == "" || strings.ReplaceAll(line, " ", "") == "" { return true } diff --git a/render/renderer_terminal.go b/render/renderer_terminal.go index cc8a1820..8cb508f7 100644 --- a/render/renderer_terminal.go +++ b/render/renderer_terminal.go @@ -187,7 +187,7 @@ func (rr *TerminalRenderer) Result(passes, fails, skips int) { } d := rr.formatDuration(time.Since(rr.start), true) - d = strings.Replace(d, ".", "{s-}.", -1) + "{!}" + d = strings.ReplaceAll(d, ".", "{s-}.") + "{!}" fmtc.NewLine() fmtc.Println(" {*}Duration:{!} " + d) diff --git a/render/renderer_xml.go b/render/renderer_xml.go index f363e15d..e2b22599 100644 --- a/render/renderer_xml.go +++ b/render/renderer_xml.go @@ -150,9 +150,9 @@ func (rr *XMLRenderer) Result(passes, fails, skips int) { // ////////////////////////////////////////////////////////////////////////////////// // func (rr *XMLRenderer) escapeData(data string) string { - data = strings.Replace(data, "<", "<", -1) - data = strings.Replace(data, ">", ">", -1) - data = strings.Replace(data, "&", "&", -1) + data = strings.ReplaceAll(data, "<", "<") + data = strings.ReplaceAll(data, ">", ">") + data = strings.ReplaceAll(data, "&", "&") return data } From b5929a783fb5b303dca9584475313857d73136d6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 24 Oct 2023 03:01:23 +0000 Subject: [PATCH 13/30] Bump github.com/essentialkaos/ek/v12 from 12.82.0 to 12.83.1 Bumps [github.com/essentialkaos/ek/v12](https://github.com/essentialkaos/ek) from 12.82.0 to 12.83.1. - [Release notes](https://github.com/essentialkaos/ek/releases) - [Changelog](https://github.com/essentialkaos/ek/blob/master/CHANGELOG.md) - [Commits](https://github.com/essentialkaos/ek/compare/v12.82.0...v12.83.1) --- updated-dependencies: - dependency-name: github.com/essentialkaos/ek/v12 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c4ac1cca..b124c555 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/creack/pty v1.1.18 github.com/essentialkaos/check v1.4.0 github.com/essentialkaos/depsy v1.1.0 - github.com/essentialkaos/ek/v12 v12.82.0 + github.com/essentialkaos/ek/v12 v12.83.1 ) require ( diff --git a/go.sum b/go.sum index ced9f1af..8078763c 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,8 @@ github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1n github.com/essentialkaos/check v1.4.0/go.mod h1:LMKPZ2H+9PXe7Y2gEoKyVAwUqXVgx7KtgibfsHJPus0= 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.82.0 h1:8JqG7E1RWhMJq2CuSV0oaR96pmEjngLPG3cnJ++EJeQ= -github.com/essentialkaos/ek/v12 v12.82.0/go.mod h1:X0gkyjBCP4QiD+sV4D52aquLDLGUmHteMEL7Rsgbev0= +github.com/essentialkaos/ek/v12 v12.83.1 h1:jNImDlEVKd7CoiUxctFqPp5K4ZwLFlHeMtE0UAoA9PA= +github.com/essentialkaos/ek/v12 v12.83.1/go.mod h1:X0gkyjBCP4QiD+sV4D52aquLDLGUmHteMEL7Rsgbev0= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= From 20496ce2db81e296f6a227f062f339c0cc3db821 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Thu, 26 Oct 2023 13:55:56 +0300 Subject: [PATCH 14/30] Get binding suffix from python --- recipe/recipe_test.go | 2 +- recipe/runtime_variables.go | 20 +++----------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/recipe/recipe_test.go b/recipe/recipe_test.go index 1d60b7c5..ff471bfa 100644 --- a/recipe/recipe_test.go +++ b/recipe/recipe_test.go @@ -284,7 +284,7 @@ func (s *RecipeSuite) TestPythonVariables(c *C) { python3Bin = "_unknown_" c.Assert(evalPythonCode(3, "test"), Equals, "") - c.Assert(getPythonBindingSuffix(), Equals, "") + c.Assert(getPythonBindingSuffix(3), Equals, "") python3Bin = "python3" } diff --git a/recipe/runtime_variables.go b/recipe/runtime_variables.go index ec33575b..e8b9e538 100644 --- a/recipe/runtime_variables.go +++ b/recipe/runtime_variables.go @@ -8,7 +8,6 @@ package recipe // ////////////////////////////////////////////////////////////////////////////////// // import ( - "fmt" "os" "os/exec" "strconv" @@ -153,7 +152,7 @@ func getRuntimeVariable(name string, r *Recipe) string { dynVarCache[name] = getPythonSiteArch(3) case "PYTHON3_BINDING_SUFFIX": - dynVarCache[name] = getPythonBindingSuffix() + dynVarCache[name] = getPythonBindingSuffix(3) case "LIBDIR": dynVarCache[name] = getLibDir(false) @@ -195,21 +194,8 @@ func getPythonSiteArch(majorVersion int) string { } // getPythonBindingSuffix returns suffix for Python bindings -func getPythonBindingSuffix() string { - version := getPythonVersion(3) - - if version == "" { - return "" - } - - version = strutil.Exclude(version, ".") - systemInfo := getSystemInfo() - - if systemInfo == nil { - return "" - } - - return fmt.Sprintf(".cpython-%sm-%s-linux-gnu.so", version, systemInfo.Arch) +func getPythonBindingSuffix(majorVersion int) string { + return evalPythonCode(majorVersion, `import sysconfig; print(sysconfig.get_config_var("EXT_SUFFIX"))`) } // evalPythonCode evaluates Python code From 761ae80157542003542e01881ecf311a22b36385 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sat, 28 Oct 2023 11:38:38 +0300 Subject: [PATCH 15/30] Improve reading command output --- cli/executor/executor.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/executor/executor.go b/cli/executor/executor.go index 0cee2cd1..4561204f 100644 --- a/cli/executor/executor.go +++ b/cli/executor/executor.go @@ -483,6 +483,7 @@ func outputIOLoop(cmdEnv *CommandEnv) { if n > 0 { cmdEnv.output.Write(buf[:n]) + continue } if cmdEnv.cmd.ProcessState != nil && cmdEnv.cmd.ProcessState.Exited() { From b0bedd8f78411635281e9edf9f65dc0da4b5d765 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sat, 28 Oct 2023 23:01:32 +0300 Subject: [PATCH 16/30] Add readme for scripts --- scripts/README.md | 157 ++++++++++++++++++++++++++++++++++++++ scripts/bibop-linked | 6 +- scripts/bibop-so-exported | 6 +- 3 files changed, 163 insertions(+), 6 deletions(-) create mode 100644 scripts/README.md diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 00000000..315225da --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,157 @@ +### `bibop` scripts + +- `bibop-dep` — utility for installing/uninstalling recipe dependecnies +- `bibop-docker` — `bibop` docker/podman wrapper +- `bibop-libtest-gen` — utility for generating compilation tests for libraries +- `bibop-libtest-gen` — utility listing linked shared libraries +- `bibop-massive` — utility for mass package testing +- `bibop-multi-check` — utility for checking different versions of package +- `bibop-so-exported` — utility for generating exported symbols tests + +#### `bibop-dep` + +``` +Usage: bibop-dep {options} {action} + +Actions + + install, i Install packages + reinstall, r Reinstall packages + uninstall, u Uninstall packages + +Options + + --enablerepo, -ER repo Enable repository + --disablerepo, -DR repo Disable repository + --yes, -y Automatically answer yes for all questions + --no-color, -nc Disable colors in output + --help, -h Show this help message + --version, -v Show information about version + +Examples + + bibop-dep install -ER kaos-testing myapp.recipe + Install packages for myapp recipe with enabled kaos-testing repository + + bibop-dep install -ER kaos-testing,epel,cbr -y myapp.recipe + Install packages for myapp recipe with enabled repositories + + bibop-dep uninstall + Uninstall all packages installed by previous transaction +``` + +#### `bibop-libtest-gen` + +``` +Usage: bibop-libtest-gen {options} devel-package + +Options + + --list-libs, -L List all libs in package + --output, -o name Output source file (default: test.c) + --lib, -l name Lib name + --no-color, -nc Disable colors in output + --help, -h Show this help message + --version, -v Show information about version + +Examples + + bibop-libtest-gen dirac-devel-1.0.2-15.el7.x86_64.rpm + Generate test.c with all required headers for RPM package + + bibop-libtest-gen dirac-devel + Generate test.c with all required headers for installed package +``` + +#### `bibop-linked` + +``` +Usage: bibop-linked {options} binary-file + +Options + + --no-color, -nc Disable colors in output + --help, -h Show this help message + --version, -v Show information about version + +Examples + + bibop-linked /usr/bin/curl + List required shared libraries for binary file + + bibop-linked /usr/lib64/libcurl.so.4 + List required shared libraries for other library +``` + +#### `bibop-massive` + +``` +Usage: bibop-massive {options} recipe… + +Options + + --validate, -V Just validate recipes + --recheck, -R Run only failed checks + --fresh, -F Clean all caches before run + --interrupt, -X Interrupt checks after first error + --barcode, -B Print unique barcode for every test + --enablerepo, -ER repo Enable repository + --disablerepo, -DR repo Disable repository + --error-dir, -e dir Path to directory with tests errors + --log, -l file Path to log file + --no-color, -nc Disable colors in output + --help, -h Show this help message + --version, -v Show information about version + +Examples + + bibop-massive ~/tests/ + Run all tests in given directory + + bibop-massive -ER kaos-testing ~/tests/package1.recipe ~/tests/package2.recipe + Run 2 tests with enabled repository 'kaos-testing' for installing packages + + bibop-massive -ER kaos-testing,epel,cbr ~/tests/package1.recipe + Run verbose test with enabled repositories for installing packages +``` + +#### `bibop-multi-check` + +``` +Usage: bibop-multi-check {options} recipe package-list + +Options + + --enablerepo, -ER repo Enable repository + --disablerepo, -DR repo Disable repository + --error-dir, -e dir Path to directory with tests errors + --log, -l file Path to log file + --no-color, -nc Disable colors in output + --help, -h Show this help message + --version, -v Show information about version + +Examples + + bibop-multi-check app.recipe package.list + Run tests for every package in list + + bibop-multi-check -ER kaos-testing,epel,cbr ~/tests/package1.recipe app.recipe package.list + Run tests with enabled repositories for installing packages +``` + +#### `bibop-so-exported` + +``` +Usage: bibop-so-exported {options} package-name + +Options + + --no-color, -nc Disable colors in output + --help, -h Show this help message + --version, -v Show information about version + +Examples + + bibop-so-exported zlib + Create tests for exported symbols for shared libraries in package zlib +``` diff --git a/scripts/bibop-linked b/scripts/bibop-linked index 129141af..33268f9f 100755 --- a/scripts/bibop-linked +++ b/scripts/bibop-linked @@ -178,9 +178,9 @@ usage() { show "" show "Options" $BOLD show "" - show " ${CL_GREEN}--no-color, -nc${CL_NORM} ${CL_DARK}..........${CL_NORM} Disable colors in output" - show " ${CL_GREEN}--help, -h${CL_NORM} ${CL_DARK}...............${CL_NORM} Show this help message" - show " ${CL_GREEN}--version, -v${CL_NORM} ${CL_DARK}............${CL_NORM} Show information about version" + show " ${CL_GREEN}--no-color, -nc${CL_NORM} ${CL_DARK}..${CL_NORM} Disable colors in output" + show " ${CL_GREEN}--help, -h${CL_NORM} ${CL_DARK}.......${CL_NORM} Show this help message" + show " ${CL_GREEN}--version, -v${CL_NORM} ${CL_DARK}....${CL_NORM} Show information about version" show "" show "Examples" $BOLD show "" diff --git a/scripts/bibop-so-exported b/scripts/bibop-so-exported index 8a6b602b..5d60ecc0 100755 --- a/scripts/bibop-so-exported +++ b/scripts/bibop-so-exported @@ -204,9 +204,9 @@ usage() { show "" show "Options" $BOLD show "" - show " ${CL_GREEN}--no-color, -nc${CL_NORM} ${CL_DARK}..........${CL_NORM} Disable colors in output" - show " ${CL_GREEN}--help, -h${CL_NORM} ${CL_DARK}...............${CL_NORM} Show this help message" - show " ${CL_GREEN}--version, -v${CL_NORM} ${CL_DARK}............${CL_NORM} Show information about version" + show " ${CL_GREEN}--no-color, -nc${CL_NORM} ${CL_DARK}..${CL_NORM} Disable colors in output" + show " ${CL_GREEN}--help, -h${CL_NORM} ${CL_DARK}.......${CL_NORM} Show this help message" + show " ${CL_GREEN}--version, -v${CL_NORM} ${CL_DARK}....${CL_NORM} Show information about version" show "" show "Examples" $BOLD show "" From 8454c2e6ac6d3dcce2369ff7a957f85ed612d7ce Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sat, 28 Oct 2023 23:10:07 +0300 Subject: [PATCH 17/30] Improve CI workflow --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 08d3c63f..ea5eaaee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -103,7 +103,7 @@ jobs: - name: Check scripts with Shellcheck uses: essentialkaos/shellcheck-action@v1 with: - files: scripts/* + files: scripts/bibop-dep scripts/bibop-docker scripts/bibop-entrypoint scripts/bibop-libtest-gen scripts/bibop-linked scripts/bibop-massive scripts/bibop-multi-check scripts/bibop-so-exported Hadolint: name: Hadolint From 9be2f8e0687cd5ad7251db05793dabef48925dc4 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sun, 29 Oct 2023 22:45:11 +0300 Subject: [PATCH 18/30] Use terminal window 256x80 for all commands --- cli/executor/executor.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cli/executor/executor.go b/cli/executor/executor.go index 4561204f..08ec2915 100644 --- a/cli/executor/executor.go +++ b/cli/executor/executor.go @@ -462,16 +462,18 @@ func runAction(a *recipe.Action, cmdEnv *CommandEnv) error { // createPTY creates pseudo-terminal func createPTY(cmd *exec.Cmd) (*PTY, error) { - pty, tty, err := pty.Open() + p, t, err := pty.Open() if err != nil { return nil, err } - cmd.Stdin, cmd.Stdout, cmd.Stderr = tty, tty, tty + cmd.Stdin, cmd.Stdout, cmd.Stderr = t, t, t cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true, Setctty: true} - return &PTY{pty: pty, tty: tty}, nil + pty.Setsize(p, &pty.Winsize{Rows: 80, Cols: 256}) + + return &PTY{pty: p, tty: t}, nil } // outputIOLoop reads data from reader and writes it to output store From 9325d0dbaa9e2f51adc6c8be49e7f4f4c89f6812 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sun, 29 Oct 2023 22:45:56 +0300 Subject: [PATCH 19/30] Improve data sanitization --- action/auxi.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/action/auxi.go b/action/auxi.go index 6000d3e0..5acb0061 100644 --- a/action/auxi.go +++ b/action/auxi.go @@ -30,7 +30,7 @@ type OutputContainer struct { // ////////////////////////////////////////////////////////////////////////////////// // // escapeCharRegex is regexp for searching escape characters -var escapeCharRegex = regexp.MustCompile(`\x1b\[[0-9\;]+m`) +var escapeCharRegex = regexp.MustCompile("[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))") // ////////////////////////////////////////////////////////////////////////////////// // @@ -156,5 +156,6 @@ func fmtValue(v string) string { // sanitizeData removes escape characters func sanitizeData(data []byte) []byte { + data = bytes.ReplaceAll(data, []byte("\r"), nil) return escapeCharRegex.ReplaceAll(data, nil) } From 060b27c29d431b804d84ef7051d0028c82b5e4ca Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Oct 2023 03:43:06 +0000 Subject: [PATCH 20/30] Bump github.com/creack/pty from 1.1.18 to 1.1.20 Bumps [github.com/creack/pty](https://github.com/creack/pty) from 1.1.18 to 1.1.20. - [Release notes](https://github.com/creack/pty/releases) - [Commits](https://github.com/creack/pty/compare/v1.1.18...v1.1.20) --- updated-dependencies: - dependency-name: github.com/creack/pty dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b124c555..44beba25 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/buger/jsonparser v1.1.1 - github.com/creack/pty v1.1.18 + github.com/creack/pty v1.1.20 github.com/essentialkaos/check v1.4.0 github.com/essentialkaos/depsy v1.1.0 github.com/essentialkaos/ek/v12 v12.83.1 diff --git a/go.sum b/go.sum index 8078763c..6d172b7c 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= -github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= +github.com/creack/pty v1.1.20 h1:VIPb/a2s17qNeQgDnkfZC35RScx+blkKF8GV68n80J4= +github.com/creack/pty v1.1.20/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk= github.com/essentialkaos/check v1.4.0/go.mod h1:LMKPZ2H+9PXe7Y2gEoKyVAwUqXVgx7KtgibfsHJPus0= github.com/essentialkaos/depsy v1.1.0 h1:U6dp687UkQwXlZU17Hg2KMxbp3nfZAoZ8duaeUFYvJI= From 844fdd8facead217ca0c917c44c2665ef3bc44eb Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 30 Oct 2023 22:57:08 +0300 Subject: [PATCH 21/30] Add 'template' action --- COOKBOOK.md | 68 +++++++++++++++++++++++ action/template.go | 114 +++++++++++++++++++++++++++++++++++++++ cli/executor/executor.go | 1 + recipe/tokens.go | 4 ++ 4 files changed, 187 insertions(+) create mode 100644 action/template.go diff --git a/COOKBOOK.md b/COOKBOOK.md index 6b3e3f8a..d585ce82 100644 --- a/COOKBOOK.md +++ b/COOKBOOK.md @@ -18,6 +18,7 @@ * [Common](#common) * [`exit`](#exit) * [`wait`](#wait) + * [`template`](#template) * [Input/Output](#inputoutput) * [`expect`](#expect) * [`print`](#print) @@ -490,6 +491,71 @@ command "echo 'ABCD'" "Simple echo command" +##### `template` + +Creates a file from a template. If file already exists, it will be rewritten with the same UID, GID and mode. + +▲ _Note that 'template' action will not automatically backup the destination file if it already exists (use `backup` and `backup-restore` actions to preserve the original file). Also, the created file will remain after tests execution if it was created outside the working directory._ + +You can use the following methods in your templates: + +- `Var "name"` - get variable value; +- `Is "name" "value"` - compare variable value. + +Simple example: + +``` +# Sysconfig for postgresql service + +PG_ENGINE="" +PG_POSTMASTER="" +{{ if not .Is "data_dir" "" }} +PG_DATA="{{ .Var "data_dir" }}/db" +{{ else }} +PG_DATA="" +{{end}} +PG_LOG="" +PG_UPLOG="" +PG_SOCKET_DIR="" +TIMEOUT="" +DISABLE_AUTO_NUMA="" +``` + +**Syntax:** `template [file-mode]` + +**Arguments:** + +* `source` - Path to template file (_String_) +* `dest` - Destination path (_String_) +* `file-mode` - Destination file mode (_Integer_) [Optional | 644] + +**Negative form:** No + +**Example:** + +```yang +command "-" "Create configuration file" + template app.template /etc/myapp.conf +``` + +```yang +command "-" "Create configuration file" + template app.template /etc/myapp.conf 640 +``` + +```yang +command "-" "Replace configuration file" + backup /etc/myapp.conf + template app.template /etc/myapp.conf 640 + +... + +command "-" "Restore original configuration file" + backup-restore /etc/myapp.conf +``` + + + #### Input/Output Be aware that the output store limited to 2 Mb of data for each stream (`stdout` _and_ `stderr`). So if command generates lots of output data, it better to use `expect` action to working with the output. @@ -563,6 +629,8 @@ command "echo 'ABCD'" "Simple echo command" wait-output 10.0 ``` + + ##### `output-match` Checks output with given [regular expression](https://en.wikipedia.org/wiki/Regular_expression). diff --git a/action/template.go b/action/template.go new file mode 100644 index 00000000..ce4b4468 --- /dev/null +++ b/action/template.go @@ -0,0 +1,114 @@ +package action + +// ////////////////////////////////////////////////////////////////////////////////// // +// // +// Copyright (c) 2023 ESSENTIAL KAOS // +// Apache License, Version 2.0 // +// // +// ////////////////////////////////////////////////////////////////////////////////// // + +import ( + "fmt" + "os" + "strconv" + "text/template" + + "github.com/essentialkaos/bibop/recipe" +) + +// ////////////////////////////////////////////////////////////////////////////////// // + +// varWrapper is a recipe wrapper for accessing variables +type varWrapper struct { + r *recipe.Recipe +} + +// ////////////////////////////////////////////////////////////////////////////////// // + +// Template is action processor for "template" +func Template(action *recipe.Action) error { + mode := uint64(0644) + source, err := action.GetS(0) + + if err != nil { + return err + } + + dest, err := action.GetS(1) + + if err != nil { + return err + } + + isSafePath, err := checkPathSafety(action.Command.Recipe, source) + + if err != nil { + return err + } + + if !isSafePath { + return fmt.Errorf("Action uses unsafe path (%s)", source) + } + + isSafePath, err = checkPathSafety(action.Command.Recipe, dest) + + if err != nil { + return err + } + + if !isSafePath { + return fmt.Errorf("Action uses unsafe path (%s)", dest) + } + + if action.Has(2) { + modeStr, _ := action.GetS(1) + mode, err = strconv.ParseUint(modeStr, 8, 32) + + if err != nil { + return err + } + } + + tmplData, err := os.ReadFile(source) + + if err != nil { + fmt.Errorf("Can't read template %q: %v", source, err) + } + + tmpl, err := template.New("").Parse(string(tmplData)) + + if err != nil { + return fmt.Errorf("Can't parse template %q: %v", source, err) + } + + fd, err := os.OpenFile(dest, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, os.FileMode(mode)) + + if err != nil { + return fmt.Errorf("Can't save template data into %q: %v", dest, err) + } + + defer fd.Close() + + vw := &varWrapper{action.Command.Recipe} + err = tmpl.Execute(fd, vw) + + if err != nil { + return fmt.Errorf("Can't render template %q: %v", source, err) + } + + return nil +} + +// ////////////////////////////////////////////////////////////////////////////////// // + +// Var returns variable value +func (vw *varWrapper) Var(name string) string { + return vw.r.GetVariable(name, true) +} + +// Is compares variable value +func (vw *varWrapper) Is(name, value string) bool { + return vw.r.GetVariable(name, true) == value +} + +// ////////////////////////////////////////////////////////////////////////////////// // diff --git a/cli/executor/executor.go b/cli/executor/executor.go index 08ec2915..f6df57fa 100644 --- a/cli/executor/executor.go +++ b/cli/executor/executor.go @@ -143,6 +143,7 @@ var handlers = map[string]action.Handler{ recipe.ACTION_LIB_EXPORTED: action.LibExported, recipe.ACTION_PYTHON2_PACKAGE: action.Python2Package, recipe.ACTION_PYTHON3_PACKAGE: action.Python3Package, + recipe.ACTION_TEMPLATE: action.Template, } var temp *tmp.Temp diff --git a/recipe/tokens.go b/recipe/tokens.go index 64f3340e..58e55db0 100644 --- a/recipe/tokens.go +++ b/recipe/tokens.go @@ -106,6 +106,8 @@ const ( ACTION_PYTHON2_PACKAGE = "python2-package" ACTION_PYTHON3_PACKAGE = "python3-package" + + ACTION_TEMPLATE = "template" ) // ////////////////////////////////////////////////////////////////////////////////// // @@ -217,4 +219,6 @@ var Tokens = []TokenInfo{ {ACTION_PYTHON2_PACKAGE, 1, 1, false, false}, {ACTION_PYTHON3_PACKAGE, 1, 1, false, false}, + + {ACTION_TEMPLATE, 2, 3, false, false}, } From d6b82934756a4e5b48c36bcd5debdfd488b25119 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 31 Oct 2023 23:50:01 +0300 Subject: [PATCH 22/30] Code refactoring --- action/auxi.go | 4 ++-- cli/cli.go | 10 +++------- cli/executor/executor.go | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/action/auxi.go b/action/auxi.go index 5acb0061..cbf3ce12 100644 --- a/action/auxi.go +++ b/action/auxi.go @@ -101,11 +101,11 @@ func (c *OutputContainer) Tail(lines int) string { } if line == lines { - return strings.TrimRight(string(data[i+1:]), " \n\r") + return strings.Trim(string(data[i+1:]), " \n\r") } } - return strings.TrimRight(string(data), " \n\r") + return strings.Trim(string(data), " \n\r") } // IsEmpty returns true if container is empty diff --git a/cli/cli.go b/cli/cli.go index 92eac1fd..eef4e5b7 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -18,7 +18,6 @@ import ( "github.com/essentialkaos/ek/v12/fmtutil/panel" "github.com/essentialkaos/ek/v12/fmtutil/table" "github.com/essentialkaos/ek/v12/fsutil" - "github.com/essentialkaos/ek/v12/mathutil" "github.com/essentialkaos/ek/v12/options" "github.com/essentialkaos/ek/v12/req" "github.com/essentialkaos/ek/v12/strutil" @@ -81,7 +80,7 @@ var optMap = options.Map{ OPT_LIST_PACKAGES_FLAT: {Type: options.BOOL}, OPT_VARIABLES: {Type: options.BOOL}, OPT_BARCODE: {Type: options.BOOL}, - OPT_EXTRA: {Type: options.MIXED}, + OPT_EXTRA: {Type: options.INT, Value: 10, Min: 1, Max: 256}, OPT_TIME: {Type: options.BOOL}, OPT_FORMAT: {}, OPT_DIR: {}, @@ -278,13 +277,10 @@ func process(file string) { cfg := &executor.Config{ Quiet: options.GetB(OPT_QUIET), DisableCleanup: options.GetB(OPT_NO_CLEANUP), + DebugLines: options.GetI(OPT_EXTRA), ErrsDir: errDir, } - if options.GetB(OPT_EXTRA) { - cfg.DebugLines = mathutil.Max(10, options.GetI(OPT_EXTRA)) - } - e := executor.NewExecutor(cfg) tags := strutil.Fields(options.GetS(OPT_TAG)) @@ -454,7 +450,7 @@ func genUsage() *usage.Info { info.AppNameColorTag = "{*}" + colorTagApp info.AddOption(OPT_DRY_RUN, "Parse and validate recipe") - info.AddOption(OPT_EXTRA, "Print the last lines from command output if action was failed", "?lines") + info.AddOption(OPT_EXTRA, "Number of output lines for failed action {s-}(default: 10){!}", "lines") info.AddOption(OPT_LIST_PACKAGES, "List required packages") info.AddOption(OPT_LIST_PACKAGES_FLAT, "List required packages in one line {s-}(useful for scripts){!}") info.AddOption(OPT_VARIABLES, "List recipe variables") diff --git a/cli/executor/executor.go b/cli/executor/executor.go index f6df57fa..02b0c1b1 100644 --- a/cli/executor/executor.go +++ b/cli/executor/executor.go @@ -314,7 +314,7 @@ func runCommand(e *Executor, rr render.Renderer, c *recipe.Command) bool { } if err != nil { - if !e.config.Quiet && e.config.DebugLines > 0 && cmdEnv != nil && !cmdEnv.output.IsEmpty() { + if !e.config.Quiet && cmdEnv != nil && !cmdEnv.output.IsEmpty() { fmtc.NewLine() panel.Panel( "☴ OUTPUT", "{y}", From 3032b778b468d7b15583498fc936d9b2d3ebbe82 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 1 Nov 2023 01:06:45 +0300 Subject: [PATCH 23/30] Add --pause/-P option for pause between executing commands --- cli/cli.go | 4 ++++ cli/executor/executor.go | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cli/cli.go b/cli/cli.go index eef4e5b7..a4f39c70 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -55,6 +55,7 @@ const ( OPT_BARCODE = "B:barcode" OPT_EXTRA = "X:extra" OPT_TIME = "T:time" + OPT_PAUSE = "P:pause" OPT_FORMAT = "f:format" OPT_DIR = "d:dir" OPT_PATH = "p:path" @@ -82,6 +83,7 @@ var optMap = options.Map{ OPT_BARCODE: {Type: options.BOOL}, OPT_EXTRA: {Type: options.INT, Value: 10, Min: 1, Max: 256}, OPT_TIME: {Type: options.BOOL}, + OPT_PAUSE: {Type: options.FLOAT, Max: 60}, OPT_FORMAT: {}, OPT_DIR: {}, OPT_PATH: {}, @@ -278,6 +280,7 @@ func process(file string) { Quiet: options.GetB(OPT_QUIET), DisableCleanup: options.GetB(OPT_NO_CLEANUP), DebugLines: options.GetI(OPT_EXTRA), + Pause: options.GetF(OPT_PAUSE), ErrsDir: errDir, } @@ -451,6 +454,7 @@ func genUsage() *usage.Info { info.AddOption(OPT_DRY_RUN, "Parse and validate recipe") info.AddOption(OPT_EXTRA, "Number of output lines for failed action {s-}(default: 10){!}", "lines") + info.AddOption(OPT_PAUSE, "Pause between commands in seconds", "duration") info.AddOption(OPT_LIST_PACKAGES, "List required packages") info.AddOption(OPT_LIST_PACKAGES_FLAT, "List required packages in one line {s-}(useful for scripts){!}") info.AddOption(OPT_VARIABLES, "List recipe variables") diff --git a/cli/executor/executor.go b/cli/executor/executor.go index 02b0c1b1..dd184009 100644 --- a/cli/executor/executor.go +++ b/cli/executor/executor.go @@ -55,6 +55,7 @@ type Executor struct { // ExecutorConfig contains executor configuration type Config struct { ErrsDir string + Pause float64 DebugLines int Quiet bool DisableCleanup bool @@ -278,7 +279,9 @@ func processRecipe(e *Executor, rr render.Renderer, r *recipe.Recipe, tags []str rr.CommandDone(command, isLastCommand) } - if r.Delay > 0 { + if e.config.Pause > 0 { + time.Sleep(timeutil.SecondsToDuration(e.config.Pause)) + } else if r.Delay > 0 { time.Sleep(timeutil.SecondsToDuration(r.Delay)) } } From 9dacafa8ed7286b903d670ac33de42ff1cf7eb8b Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 1 Nov 2023 01:52:06 +0300 Subject: [PATCH 24/30] Update usage demo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 658e5825..380c90b4 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Information about bibop recipe syntax you can find in our [cookbook](COOKBOOK.md ### Usage demo -[![demo](https://gh.kaos.st/bibop-600.gif)](#usage-demo) +https://github.com/essentialkaos/bibop/assets/182020/86883ea8-4b73-49a3-ac55-6b646b49e8fd ### Installation From fa7e25d02eb877ee1913548f240d819a8d6595ee Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 1 Nov 2023 02:03:27 +0300 Subject: [PATCH 25/30] Improve cookbook --- COOKBOOK.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/COOKBOOK.md b/COOKBOOK.md index d585ce82..9b2d1e5d 100644 --- a/COOKBOOK.md +++ b/COOKBOOK.md @@ -513,7 +513,7 @@ PG_POSTMASTER="" PG_DATA="{{ .Var "data_dir" }}/db" {{ else }} PG_DATA="" -{{end}} +{{ end }} PG_LOG="" PG_UPLOG="" PG_SOCKET_DIR="" From 32c06cbf251592172b01e825c084a673c326a6e6 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 1 Nov 2023 10:01:08 +0300 Subject: [PATCH 26/30] Improve README --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 380c90b4..d0351b23 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@
-`bibop` is a utility for testing command-line tools and daemons. Initially, this utility was created for testing packages from [ESSENTIAL KAOS Public Repository](https://pkgs.kaos.st). +`bibop` is a utility for testing command-line tools, packages and daemons. Initially, this utility was created for testing packages from [ESSENTIAL KAOS Public Repository](https://kaos.sh/kaos-repo). Information about bibop recipe syntax you can find in our [cookbook](COOKBOOK.md). @@ -99,7 +99,8 @@ Usage: bibop {options} recipe Options --dry-run, -D Parse and validate recipe - --extra, -X Print the last lines from command output if action was failed + --extra, -X lines Number of output lines for failed action (default: 10) + --pause, -P duration Pause between commands in seconds --list-packages, -L List required packages --list-packages-flat, -L1 List required packages in one line (useful for scripts) --variables, -V List recipe variables @@ -128,6 +129,12 @@ Examples bibop app.recipe --tag init,service Run tests from app.recipe and execute commands with tags init and service + bibop app.recipe --extra + Run tests from app.recipe and print the last 10 lines from command output if action was failed + + bibop app.recipe --extra=50 + Run tests from app.recipe and print the last 50 lines from command output if action was failed + bibop app.recipe --format json 1> ~/results/app.json Run tests from app.recipe and save result in JSON format From 6add8a1bd4c28e4783824371b65a15aaec90c2fc Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 1 Nov 2023 16:39:12 +0300 Subject: [PATCH 27/30] Dependencies update --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 44beba25..da5d1708 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/creack/pty v1.1.20 github.com/essentialkaos/check v1.4.0 github.com/essentialkaos/depsy v1.1.0 - github.com/essentialkaos/ek/v12 v12.83.1 + github.com/essentialkaos/ek/v12 v12.83.2 ) require ( diff --git a/go.sum b/go.sum index 6d172b7c..6920c7dc 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,8 @@ github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1n github.com/essentialkaos/check v1.4.0/go.mod h1:LMKPZ2H+9PXe7Y2gEoKyVAwUqXVgx7KtgibfsHJPus0= 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.83.1 h1:jNImDlEVKd7CoiUxctFqPp5K4ZwLFlHeMtE0UAoA9PA= -github.com/essentialkaos/ek/v12 v12.83.1/go.mod h1:X0gkyjBCP4QiD+sV4D52aquLDLGUmHteMEL7Rsgbev0= +github.com/essentialkaos/ek/v12 v12.83.2 h1:gXFwLIBAZsdi5uT/vJj9ka/rd94jLR1NF6OGxAYbgkQ= +github.com/essentialkaos/ek/v12 v12.83.2/go.mod h1:X0gkyjBCP4QiD+sV4D52aquLDLGUmHteMEL7Rsgbev0= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= From c0c33502bda57161461fac9926ff7b8d387730f1 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 1 Nov 2023 18:21:52 +0300 Subject: [PATCH 28/30] Improve recipe validation --- cli/cli.go | 3 +- cli/executor/executor.go | 7 ++++- cli/executor/validators.go | 61 +++++++++++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index a4f39c70..96f16c55 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -361,11 +361,12 @@ func getValidationConfig(tags []string) *executor.ValidationConfig { if options.GetB(OPT_DRY_RUN) { vc.IgnoreDependencies = true + vc.IgnorePackages = true vc.IgnorePrivileges = true } if options.GetB(OPT_IGNORE_PACKAGES) { - vc.IgnoreDependencies = true + vc.IgnorePackages = true } return vc diff --git a/cli/executor/executor.go b/cli/executor/executor.go index dd184009..99d4c3c1 100644 --- a/cli/executor/executor.go +++ b/cli/executor/executor.go @@ -64,6 +64,7 @@ type Config struct { // ValidationConfig is config for validation type ValidationConfig struct { Tags []string + IgnorePackages bool IgnoreDependencies bool IgnorePrivileges bool } @@ -171,10 +172,14 @@ func (e *Executor) Validate(r *recipe.Recipe, cfg *ValidationConfig) []error { errs.Add(checkRecipePrivileges(r)) } - if !cfg.IgnoreDependencies { + if !cfg.IgnorePackages { errs.Add(checkPackages(r)) } + if !cfg.IgnoreDependencies { + errs.Add(checkDependencies(r)) + } + if !errs.HasErrors() { return nil } diff --git a/cli/executor/validators.go b/cli/executor/validators.go index a4393ad9..dad8c610 100644 --- a/cli/executor/validators.go +++ b/cli/executor/validators.go @@ -121,7 +121,7 @@ func checkRecipeVariables(r *recipe.Recipe) []error { return errs } -// checkPackages checks packages +// checkPackages checks if required packages are installed on the system func checkPackages(r *recipe.Recipe) []error { if len(r.Packages) == 0 { return nil @@ -137,6 +137,65 @@ func checkPackages(r *recipe.Recipe) []error { return []error{errors.New("Can't check required packages availability: Unsupported OS")} } +// checkDependencies checks if all required binaries are present on the system +func checkDependencies(r *recipe.Recipe) []error { + var errs []error + + binCache := make(map[string]bool) + + for _, c := range r.Commands { + for _, a := range c.Actions { + var binary string + + switch a.Name { + case recipe.ACTION_SERVICE_PRESENT: + binary = "systemctl" + case recipe.ACTION_SERVICE_ENABLED: + binary = "systemctl" + case recipe.ACTION_SERVICE_WORKS: + binary = "systemctl" + case recipe.ACTION_WAIT_SERVICE: + binary = "systemctl" + case recipe.ACTION_LIB_LOADED: + binary = "ldconfig" + case recipe.ACTION_LIB_CONFIG: + binary = "pkg-config" + case recipe.ACTION_LIB_LINKED: + binary = "readelf" + case recipe.ACTION_LIB_RPATH: + binary = "readelf" + case recipe.ACTION_LIB_SONAME: + binary = "readelf" + case recipe.ACTION_LIB_EXPORTED: + binary = "nm" + case recipe.ACTION_PYTHON2_PACKAGE: + binary = "python" + case recipe.ACTION_PYTHON3_PACKAGE: + binary = "python3" + } + + if !hasBinary(binCache, binary) { + errs = append(errs, fmt.Errorf("Action %q requires %q binary")) + } + } + } + + return errs +} + +// hasBinary checks if binary is present on the system +func hasBinary(binCache map[string]bool, binary string) bool { + isExist, ok := binCache[binary] + + if ok { + return isExist + } + + binCache[binary] = env.Which(binary) != "" + + return binCache[binary] +} + // getDynamicVars returns slice with dynamic vars func getDynamicVars(a *recipe.Action) []string { switch a.Name { From 364995ddbf211ec1a2991b1a483a37e86aabbb98 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 1 Nov 2023 18:28:26 +0300 Subject: [PATCH 29/30] Improve recipe validation --- cli/executor/validators.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cli/executor/validators.go b/cli/executor/validators.go index dad8c610..25f5b0ca 100644 --- a/cli/executor/validators.go +++ b/cli/executor/validators.go @@ -175,7 +175,9 @@ func checkDependencies(r *recipe.Recipe) []error { } if !hasBinary(binCache, binary) { - errs = append(errs, fmt.Errorf("Action %q requires %q binary")) + errs = append(errs, fmt.Errorf( + "Line %d: Action %q requires %q binary", a.Line, a.Name, binary, + )) } } } From 11cd8fe6f87e478cece49e4c00a4661f8c2cba4d Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 1 Nov 2023 22:00:49 +0300 Subject: [PATCH 30/30] Update usage demo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d0351b23..b9a728f6 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Information about bibop recipe syntax you can find in our [cookbook](COOKBOOK.md ### Usage demo -https://github.com/essentialkaos/bibop/assets/182020/86883ea8-4b73-49a3-ac55-6b646b49e8fd +https://github.com/essentialkaos/bibop/assets/182020/c63dc147-fa44-40df-92e2-12f530c411af ### Installation