[PATCH]: gnu: Add bash-bcu.

OpenSubmitted by david larsson.
Details
3 participants
  • david larsson
  • Tobias Geerinckx-Rice
  • (
Owner
unassigned
Severity
normal
D
D
david larsson wrote on 30 Oct 2021 16:59
(address . guix-patches@gnu.org)
3add15b77522d6e9ebd715a19d966666@selfhosted.xyz
Hi,
This patch adds "bash-coding-utils" as the bash-bcu package.

Best regards,
David
Attachment: 0001-gnu-Add-bash-bcu.patch (.01 MiB)
T
T
Tobias Geerinckx-Rice wrote on 7 Nov 2021 13:40
(name . david larsson)(address . david.larsson@selfhosted.xyz)
87r1bsqdy8.fsf@nckx
David,

Thank you!

(One fire's out, you'll be glad to hear, so in return here's most
of a review. I still reserve the right to tinker with the hunk
below — you'll see which — later today.)

david larsson 写道:
Toggle quote (2 lines)
> This patch adds "bash-coding-utils" as the bash-bcu package.

[…]

Toggle quote (2 lines)
> +(define-public bash-bcu

Let's keep ‘bash-coding-utils’ as the name then, both of the
variable and the package name string.

Toggle quote (4 lines)
> + (let ((pyver (version-major+minor (package-version python)))
> + (guilever (version-major+minor (package-version
> guile-3.0))))

These aren't used until #:builder, which already has a let* where
they'll do fine. Binding them this early implies otherwise &
indents the whole package. Let's not.

Toggle quote (4 lines)
> + (package
> + (name "bash-bcu")
> + (version "v0.2.0")

Don't repeat ‘v’ (or ‘version-’, ‘RELEASE_’ &c.) here.

Toggle quote (3 lines)
> + (home-page
> "https://gitlab.com/methuselah-0/bash-coding-utils.sh")

Not wrong, but I'd move this to the informal ‘metadata area’ at
the end of the package (synopsis &c.). It doesn't affect the
build or even the hash.

Toggle quote (9 lines)
> + (source
> + (origin
> + (method git-fetch)
> + (uri (git-reference
> + (commit
> "40d6527a9effb4e18778c37bebaa9f3a58de12d6")
> + (url
> "https://gitlab.com/methuselah-0/bash-coding-utils.sh.git")

+ ;; TODO: unbundle submodules/ some day.

Toggle quote (2 lines)
> + (recursive? #t)))

This will create
/gnu/store/ivnsnv2yhq9mawxvacmjwxw1z535x9aq-git-checkout.

Guix doesn't care, but please use

+ (file-name (git-file-name name version))

to make it more meaningful for humans.

Toggle quote (3 lines)
> + (base32
> + "007g6wfybjr0ms32qikb545r11lgm3p98cd7dbzpfyh0grgn9vj1"))))

This can be one line.

Toggle quote (35 lines)
> + (inputs `(("bash-full" ,bash)
> + ("bindutils" ,isc-bind "utils")
> + ("coreutils" ,coreutils)
> + ("ctypes.sh" ,bash-ctypes)
> + ("curl" ,curl)
> + ("diffutils" ,diffutils)
> + ("ed" ,ed)
> + ("expect" ,expect)
> + ("find" ,findutils)
> + ("gawk" ,gawk)
> + ("grep" ,grep)
> + ("guile" ,guile-3.0)
> + ("guile-bash" ,guile-bash)
> + ("guile-daemon" ,guile-daemon)
> + ("inetutils" ,inetutils)
> + ("jq" ,jq)
> + ("libxml2-xpath0" ,libxml2-xpath0)
> + ("netcat" ,netcat)
> + ("nmap" ,nmap)
> + ("pcre/bin" ,pcre "bin")
> + ("perl" ,perl)
> + ("php" ,php)
> + ("prips" ,prips)
> + ("python" ,python)
> + ("python-elementpath" ,python-elementpath)
> + ("python-lxml" ,python-lxml)
> + ("python-netaddr" ,python-netaddr)
> + ("python-yq" ,python-yq)
> + ("sed" ,sed)
> + ("socat" ,socat)
> + ("util-linux" ,util-linux)
> + ("which" ,which)
> + ("xdg-utils" ,xdg-utils)
> + ("yad" ,yad)))

So the de-facto ordering of common fields is something like:

name
version
source
build-system
outputs ; a bit inconsistent, yes, and sometimes put after *inputs
arguments ; to the build-system
native-inputs, inputs, propagated-inputs
metadata: synopsis, description, home-page, properties, license…

There's some minor variation in where to put inputs, but
(build-system trivial-build-system) definitely belongs here, above
arguments, no matter what.

Toggle quote (8 lines)
> + (arguments
> + `(#:modules ((guix build utils))
> + #:builder
> + (begin
> + (use-modules (guix build utils))
> + (let* ((bashfull (assoc-ref %build-inputs
> "bash-full"))

There's nothing with which to confuse it so just "bash" for both
the variable and label.

Toggle quote (9 lines)
> + ;; Some guile libraries such as gnu bash will
> need
> + ;; to be added to GUILE_LOAD_PATH
> + (guile-bash (assoc-ref %build-inputs
> "guile-bash"))
> + (g-bash-lib (string-append guile-bash
> + "/share/guile/site/"
> ,guilever))

So drop the top-level ‘let’ and just use ,(version-major+minor
(package-version guile-3.0) directly…

Toggle quote (3 lines)
> + ;; Some python libraries needs added to
> PYTHONPATH

…and add

+ (python-version ,(version-major+minor (package-version python)))

here for use ad of ‘pyver’ (Guile isn't C and hard drives not 5
MB).

Toggle quote (125 lines)
> + (p-elementpath-lib (string-append
> + (assoc-ref %build-inputs
> "python-elementpath")
> + "/lib/python" ,pyver
> "/site-packages"))
> + (p-lxml-lib (string-append
> + (assoc-ref %build-inputs
> "python-lxml")
> + "/lib/python" ,pyver
> "/site-packages"))
> + (p-netaddr-lib (string-append
> + (assoc-ref %build-inputs
> "python-netaddr")
> + "/lib/python" ,pyver
> "/site-packages"))
> + (p-lib (string-append
> + (assoc-ref %build-inputs "python")
> + "/lib/python" ,pyver
> "/site-packages"))
> + (pylibsline (string-append
> + p-elementpath-lib ":" p-lxml-lib
> + ":" p-netaddr-lib ":" p-lib))
> + (out (assoc-ref %outputs "out"))
> + (bin (string-append out "/bin"))
> + ;; Everything but bcu.sh itself is only
> accessed
> + ;; internally by bcu so we put it in libexec.
> + (libexec (string-append out "/libexec/bcu")))
> + (mkdir-p libexec)
> + (copy-recursively (assoc-ref %build-inputs
> "source") libexec)
> + ;; Create a bcu.sh wrapping script manually that
> ensures
> + ;; we prepend necessary PATHs.
> + (mkdir-p bin)
> + (let* ((binfile (string-append bin "/bcu.sh"))
> + (bcu-port (open-file binfile "a"))
> + (pathline (string-append
> + bashfull "/bin"
> + ":" (assoc-ref %build-inputs
> "bindutils") "/bin"
> + ":" (assoc-ref %build-inputs
> "coreutils") "/bin"
> + ":" (assoc-ref %build-inputs
> "ctypes.sh") "/bin"
> + ":" (assoc-ref %build-inputs
> "curl") "/bin"
> + ":" (assoc-ref %build-inputs
> "diffutils") "/bin"
> + ":" (assoc-ref %build-inputs
> "ed") "/bin"
> + ":" (assoc-ref %build-inputs
> "expect") "/bin"
> + ":" (assoc-ref %build-inputs
> "find") "/bin"
> + ":" (assoc-ref %build-inputs
> "gawk") "/bin"
> + ":" (assoc-ref %build-inputs
> "grep") "/bin"
> + ":" (assoc-ref %build-inputs
> "guile") "/bin"
> + ":" (assoc-ref %build-inputs
> "inetutils") "/bin"
> + ":" (assoc-ref %build-inputs
> "jq") "/bin"
> + ":" (assoc-ref %build-inputs
> "libxml2-xpath0") "/bin"
> + ":" (assoc-ref %build-inputs
> "netcat") "/bin"
> + ":" (assoc-ref %build-inputs
> "nmap") "/bin"
> + ":" (assoc-ref %build-inputs
> "pcre/bin") "/bin"
> + ":" (assoc-ref %build-inputs
> "perl") "/bin"
> + ":" (assoc-ref %build-inputs
> "php") "/bin"
> + ":" (assoc-ref %build-inputs
> "prips") "/bin"
> + ":" (assoc-ref %build-inputs
> "python") "/bin"
> + ":" (assoc-ref %build-inputs
> "python-yq") "/bin"
> + ":" (assoc-ref %build-inputs
> "sed") "/bin"
> + ":" (assoc-ref %build-inputs
> "socat") "/bin"
> + ":" (assoc-ref %build-inputs
> "util-linux") "/bin"
> + ":" (assoc-ref %build-inputs
> "which") "/bin"
> + ":" (assoc-ref %build-inputs
> "xdg-utils") "/bin"
> + ":" (assoc-ref %build-inputs
> "yad") "/bin")))
> + (display (string-append "#!" bashfull
> "/bin/bash\n") bcu-port)
> + (display
> + (string-append
> + "[[ \"$_BCU_SH_LOADED\" == YES ]] || {
> \nexport PATH=\""
> + pathline "${PATH:+:}${PATH}\"\nexport
> PYTHONPATH=\""
> + pylibsline
> "${PYTHONPATH:+:}${PYTHONPATH}\"\nexport GUILE_LOAD_PATH=\""
> + g-bash-lib
> "${GUILE_LOAD_PATH:+:}${GUILE_LOAD_PATH}\"\n"
> + ;; XDG_DATA_DIRS needs set for yad to load
> icons properly
> + "[[ -e /run/current-system/profile/share ]] &&
> export XDG_DATA_DIRS="
> + "/run/current-system/profile/share${XDG_DATA_DIRS:+:}${XDG_DATA_DIRS}\n"
> + ;; Ensure that the setuid version of ping is
> used
> + "[[ -e /run/setuid-programs/ping ]] && "
> + "ping(){ /run/setuid-programs/ping \"$@\" ; }
> && export -f ping\n"
> + "[[ -e /run/setuid-programs/ping6 ]] && "
> + "ping6(){ /run/setuid-programs/ping6 \"$@\" ;
> } && export -f ping6\n}\n")
> + bcu-port)
> + (display (string-append "source " libexec
> "/bcu.sh\n") bcu-port)
> + (close-port bcu-port)

[So this is the part I was waiting to finish :-) I still don't
have time now.]

I really want to rewrite this whole block, but for now I just have
1 question: why not simply append /run/setuid-programs to the
start of $PATH here? What's the difference, if any, and do we
care?

Toggle quote (2 lines)
> + (chmod binfile #o555)

s/binfile/wrapper/ or somesuch.

Toggle quote (3 lines)
> + (setenv "PATH" (string-append pathline ":"
> (getenv "PATH"))))

s/pathline/path/

Toggle quote (3 lines)
> + (for-each (lambda (file)
> + (substitute* file

substitute* supports a list of (found-)files as the first argument
directly. No need to call it multiple times.

Toggle quote (2 lines)
> + (find-files out ".*\\.sh"))

.* is noise: "\\.sh$"

Toggle quote (3 lines)
> + (find-files out
> ".*\\.(sh|scm|awk|php|py)$"))

…same here.

Wonderful that you took the trouble to run tests!

Let's visually separate the ‘test phase’:

+
+ ;;; Now that everything's installed, prepare & run
the tests.
+ ;; Set up PATH for tests.

Toggle quote (15 lines)
> + (setenv "PATH" (string-append bin ":" (getenv
> "PATH")))
> + ;; Some tests need a HOME-directory
> + (setenv "HOME" "/tmp")
> + ;; Disable network tests, and all tests for
> setopts which
> + ;; don't work inside the Guix build environment
> + (call-with-output-file (string-append libexec
> "/disabled_tests.txt")
> + (lambda (port)
> + (display (string-append
> + "ip_of_test_1\nsetopts_test_1\nsetopts_test_2\nsetopts_test_3"
> + "\nsetopts_test_4\nsetopts_test_5\nsetopts_test_6\n")
> + port)))

+ (with-output-to-file (string-append libexec
"/disabled_tests.txt")
+ (lambda _
+ (format #t "~{~a~%~}"
+ (list "ip_of_test_1"
+ "setopts_test_1"
+ "setopts_test_2"
+ "setopts_test_3"
+ "setopts_test_4"
+ "setopts_test_5"
+ "setopts_test_6"))))

Toggle quote (3 lines)
> + (synopsis "Bash functions and tools for software
> prototyping in Bash")

I dropped the leading ‘Bash ’ here.

Toggle quote (3 lines)
> + (description
> + (string-append

Just use

(description
"This package contains Bash functions and wrappers that can
be useful when writing quick implementations of new programs. It
helps you work with JSON, XML, and parallelization, and installs
some commonly used helper programs used in Bash scripting.

Run @command{bcu__docs} for the full HTML documentation.")

But wrapped at 80 characters—I used less to avoid turning it into
an unreadable mess in some MUAs.

Toggle quote (7 lines)
> + "Bash-bcu contains bash functions and wrappers that can
> be useful when"
> + " writing quick implementations of new programs. It
> helps you work with"
> + " JSON, XML, parallelization and installs some commonly
> used \"helper\""

Texinfo double quotes are ``thus'' but can just be dropped here.

Toggle quote (3 lines)
> + @command{TAB}
> + @command{ --help}

Even the (comfortable) subset of Texinfo that Guix supports has
more keywords than ‘command’! ;-) @key, @code, …

Toggle quote (2 lines)
> + Just run @command{. bcu.sh}, type

I left this out because we don't usually include ‘getting started’
instructions in package descriptions. There are exceptions, and
this package not including info (or man) pages is unfortunate, so
I kept the bcu__docs hint.

Acceptable?

Toggle quote (2 lines)
> + (license license:gpl3))))

Why not lgpl3+? I can't find the gpl3-only file(s).

Kind regards,

T G-R
-----BEGIN PGP SIGNATURE-----

iIMEARYKACsWIQT12iAyS4c9C3o4dnINsP+IT1VteQUCYYfX4A0cbWVAdG9iaWFz
LmdyAAoJEA2w/4hPVW15BH4BAI66CGDpcXE1T+t0wJDld2La2F1abNGwIkDJdDhH
bbCDAQDZ9wgsFR9sak430GhQwr87Ca6aZMH6bOgcFNlABCpEAg==
=H+/K
-----END PGP SIGNATURE-----

D
D
david larsson wrote on 9 Nov 2021 13:32
Re: [bug#51512] [PATCH v 2]: gnu: Add bash-bcu.
93d8232c104dc63f46f6b975073b56ca@selfhosted.xyz
On 2021-11-07 13:40, Tobias Geerinckx-Rice wrote:
Toggle quote (9 lines)
> David,
>
> Thank you!
>
> (One fire's out, you'll be glad to hear, so in return here's most of a
> review. I still reserve the right to tinker with the hunk below —
> you'll see which — later today.)
>

Thanks for the review, it feels like I learn a lot from this :-)

Not sure if u intended to attach ur modified version of the patch when
you replied or not. I have however made the changes you suggested in a
version2 and attached.

[...]

Toggle quote (34 lines)
>> + (display
>> + (string-append
>> + "[[ \"$_BCU_SH_LOADED\" == YES ]] || { \nexport
>> PATH=\""
>> + pathline "${PATH:+:}${PATH}\"\nexport PYTHONPATH=\""
>> + pylibsline "${PYTHONPATH:+:}${PYTHONPATH}\"\nexport
>> GUILE_LOAD_PATH=\""
>> + g-bash-lib
>> "${GUILE_LOAD_PATH:+:}${GUILE_LOAD_PATH}\"\n"
>> + ;; XDG_DATA_DIRS needs set for yad to load icons
>> properly
>> + "[[ -e /run/current-system/profile/share ]] &&
>> export XDG_DATA_DIRS="
>> +
>> "/run/current-system/profile/share${XDG_DATA_DIRS:+:}${XDG_DATA_DIRS}\n"
>> + ;; Ensure that the setuid version of ping is used
>> + "[[ -e /run/setuid-programs/ping ]] && "
>> + "ping(){ /run/setuid-programs/ping \"$@\" ; } &&
>> export -f ping\n"
>> + "[[ -e /run/setuid-programs/ping6 ]] && "
>> + "ping6(){ /run/setuid-programs/ping6 \"$@\" ; } &&
>> export -f ping6\n}\n")
>> + bcu-port)
>> + (display (string-append "source " libexec "/bcu.sh\n")
>> bcu-port)
>> + (close-port bcu-port)
>
> [So this is the part I was waiting to finish :-) I still don't have
> time now.]
>
> I really want to rewrite this whole block, but for now I just have 1
> question: why not simply append /run/setuid-programs to the start of
> $PATH here? What's the difference, if any, and do we care?

Basically just to make minimal disruption of the the current environment
when you source bcu.sh. Almost certainly a non-issue 99.9% of cases,
i.e. I think that just prepending /run/setuid-programs to PATH would be
fine as well.

Toggle quote (4 lines)
>> + (license license:gpl3))))
>
> Why not lgpl3+? I can't find the gpl3-only file(s).

I really don't know enough about licensing to answer this very well
unfortunately.. bash-coding-utils is to a large extent a remix of
stackoverflow contributions (CC-BY-SA-4.0) and other small libraries,
some of which have GPLv3+ stated at the top (e.g. src/csv/csv/csv.scm).
I want to apply whatever license must be applied based on the included
software and SO snippets. If it needs to be lgpl3+ or GPLv3 in the end
does not matter much to me (Im the author of bash-coding-utils).

Best regards,
David
Attachment: 0001-gnu-Add-bash-bcu.patch (.01 MiB)
T
T
Tobias Geerinckx-Rice wrote on 20 Nov 2021 15:11
(name . david larsson)(address . david.larsson@selfhosted.xyz)
87y25inbsu.fsf@nckx
David,

david larsson 写道:
Toggle quote (4 lines)
> Not sure if u intended to attach ur modified version of the
> patch when
> you replied or not.

Absolutely. Oops! Here it is, belatedly, and possibly
pointlessly.

Toggle quote (7 lines)
> Basically just to make minimal disruption of the the current
> environment when you source bcu.sh. Almost certainly a non-issue
> 99.9%
> of cases, i.e. I think that just prepending /run/setuid-programs
> to
> PATH would be fine as well.

The current package does much ‘worse’ comparatively:

Toggle quote (6 lines)
> + ":" (assoc-ref %build-inputs "bindutils") "/bin"
> + ":" (assoc-ref %build-inputs "coreutils") "/bin"
> + ":" (assoc-ref %build-inputs "ctypes.sh") "/bin"
> + ":" (assoc-ref %build-inputs "curl") "/bin"
> […many more…]

However, you make an excellent point, and this packages's intended
usage means that it will clobber the caller's environment, not
just its own.

If I were to use this package (and I might—it's neat) I would
almost certainly end up using it in a setting where changing PATH
at all would cause unexpected and frustrating ‘bugs’.

Hmm…

Kind regards,

T G-R
From 2ee51b0224c6f3bf9720d217346f53e3cb94e68a Mon Sep 17 00:00:00 2001
From: Tobias Geerinckx-Rice <me@tobias.gr>
Date: Mon, 8 Nov 2021 21:09:17 +0100
Subject: [PATCH 06/10] wip bcu

---
gnu/packages/bash.scm | 196 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 196 insertions(+)

Toggle diff (224 lines)
diff --git a/gnu/packages/bash.scm b/gnu/packages/bash.scm
index ed2931fd97..114ea1dcac 100644
--- a/gnu/packages/bash.scm
+++ b/gnu/packages/bash.scm
@@ -25,17 +25,34 @@
 (define-module (gnu packages bash)
   #:use-module ((guix licenses) #:prefix license:)
   #:use-module (gnu packages)
+  #:use-module (gnu packages admin)
   #:use-module (gnu packages base)
   #:use-module (gnu packages bootstrap)
   #:use-module (gnu packages compression)
+  #:use-module (gnu packages curl)
+  #:use-module (gnu packages dns)
+  #:use-module (gnu packages ed)
   #:use-module (gnu packages elf)
+  #:use-module (gnu packages freedesktop)
+  #:use-module (gnu packages gawk)
+  #:use-module (gnu packages gtk)
   #:use-module (gnu packages ncurses)
+  #:use-module (gnu packages networking)
   #:use-module (gnu packages readline)
   #:use-module (gnu packages bison)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages libffi)
+  #:use-module (gnu packages pcre)
+  #:use-module (gnu packages perl)
+  #:use-module (gnu packages php)
   #:use-module (gnu packages pkg-config)
+  #:use-module (gnu packages python)
+  #:use-module (gnu packages python-xyz)
   #:use-module (gnu packages guile)
+  #:use-module (gnu packages guile-xyz)
+  #:use-module (gnu packages tcl)
+  #:use-module (gnu packages web)
+  #:use-module (gnu packages xml)
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix git-download)
@@ -448,3 +465,182 @@ (define-public bash-ctypes
 function interface (FFI) directly in your shell.  In other words, it allows
 you to call routines in shared libraries from within Bash.")
     (license license:expat)))
+
+(define-public bash-coding-utils
+  (let ()
+    (package
+      (name "bash-coding-utils")
+      (version "0.2.0")
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (commit "40d6527a9effb4e18778c37bebaa9f3a58de12d6")
+               (url "https://gitlab.com/methuselah-0/bash-coding-utils.sh.git")
+               ;; Include submodules/.  TODO: These seem to be worth packaging?
+               (recursive? #t)))
+         (sha256
+          (base32 "007g6wfybjr0ms32qikb545r11lgm3p98cd7dbzpfyh0grgn9vj1"))))
+      (inputs `(("bash" ,bash)
+                ("bindutils" ,isc-bind "utils")
+                ("coreutils" ,coreutils)
+                ("ctypes.sh" ,bash-ctypes)
+                ("curl" ,curl)
+                ("diffutils" ,diffutils)
+                ("ed" ,ed)
+                ("expect" ,expect)
+                ("find" ,findutils)
+                ("gawk" ,gawk)
+                ("grep" ,grep)
+                ("guile" ,guile-3.0)
+                ("guile-bash" ,guile-bash)
+                ("guile-daemon" ,guile-daemon)
+                ("inetutils" ,inetutils)
+                ("jq" ,jq)
+                ("libxml2-xpath0" ,libxml2-xpath0)
+                ("netcat" ,netcat)
+                ("nmap" ,nmap)
+                ("pcre/bin" ,pcre "bin")
+                ("perl" ,perl)
+                ("php" ,php)
+                ("prips" ,prips)
+                ("python" ,python)
+                ("python-elementpath" ,python-elementpath)
+                ("python-lxml" ,python-lxml)
+                ("python-netaddr" ,python-netaddr)
+                ("python-yq" ,python-yq)
+                ("sed" ,sed)
+                ("socat" ,socat)
+                ("util-linux" ,util-linux)
+                ("which" ,which)
+                ("xdg-utils" ,xdg-utils)
+                ("yad" ,yad)))
+      (build-system trivial-build-system)
+      (arguments
+       `(#:modules ((guix build utils))
+         #:builder
+         (begin
+           (use-modules (guix build utils))
+           (let* ((bash (assoc-ref %build-inputs "bash"))
+                  ;; Some Guile libraries such as GNU Bash will need
+                  ;; to be added to GUILE_LOAD_PATH.
+                  (guile-bash (assoc-ref %build-inputs "guile-bash"))
+                  (g-bash-lib (string-append guile-bash
+                                        "/share/guile/site/"
+                                        ,(version-major+minor (package-version guile-3.0))))
+                  ;; Some Python libraries needs added to PYTHONPATH.
+                  (python-version ,(version-major+minor (package-version python)))
+                  (p-elementpath-lib (string-append
+                                      (assoc-ref %build-inputs "python-elementpath")
+                                      "/lib/python" python-version "/site-packages"))
+                  (p-lxml-lib (string-append
+                               (assoc-ref %build-inputs "python-lxml")
+                               "/lib/python" python-version "/site-packages"))
+                  (p-netaddr-lib (string-append
+                                  (assoc-ref %build-inputs "python-netaddr")
+                                  "/lib/python" python-version "/site-packages"))
+                  (p-lib (string-append
+                          (assoc-ref %build-inputs "python")
+                          "/lib/python" python-version "/site-packages"))
+                  (pylibsline (string-append
+                               p-elementpath-lib ":" p-lxml-lib
+                               ":" p-netaddr-lib ":" p-lib))
+                  (out (assoc-ref %outputs "out"))
+                  (bin (string-append out "/bin"))
+                  ;; Everything but bcu.sh itself is only accessed
+                  ;; internally by bcu so we put it in libexec.
+                  (libexec (string-append out "/libexec/bcu")))
+             (mkdir-p libexec)
+             (copy-recursively (assoc-ref %build-inputs "source") libexec)
+             ;; Create a bcu.sh wrapping script manually that ensures
+             ;; we prepend necessary PATHs.
+             (mkdir-p bin)
+             (let* ((bcu.sh (string-append bin "/bcu.sh"))
+                    (path (string-append
+                               "/run/setuid-programs"
+                               ":" bash "/bin"
+                               ":" (assoc-ref %build-inputs "bindutils") "/bin"
+                               ":" (assoc-ref %build-inputs "coreutils") "/bin"
+                               ":" (assoc-ref %build-inputs "ctypes.sh") "/bin"
+                               ":" (assoc-ref %build-inputs "curl") "/bin"
+                               ":" (assoc-ref %build-inputs "diffutils") "/bin"
+                               ":" (assoc-ref %build-inputs "ed") "/bin"
+                               ":" (assoc-ref %build-inputs "expect") "/bin"
+                               ":" (assoc-ref %build-inputs "find") "/bin"
+                               ":" (assoc-ref %build-inputs "gawk") "/bin"
+                               ":" (assoc-ref %build-inputs "grep") "/bin"
+                               ":" (assoc-ref %build-inputs "guile") "/bin"
+                               ":" (assoc-ref %build-inputs "inetutils") "/bin"
+                               ":" (assoc-ref %build-inputs "jq") "/bin"
+                               ":" (assoc-ref %build-inputs "libxml2-xpath0") "/bin"
+                               ":" (assoc-ref %build-inputs "netcat") "/bin"
+                               ":" (assoc-ref %build-inputs "nmap") "/bin"
+                               ":" (assoc-ref %build-inputs "pcre/bin") "/bin"
+                               ":" (assoc-ref %build-inputs "perl") "/bin"
+                               ":" (assoc-ref %build-inputs "php") "/bin"
+                               ":" (assoc-ref %build-inputs "prips") "/bin"
+                               ":" (assoc-ref %build-inputs "python") "/bin"
+                               ":" (assoc-ref %build-inputs "python-yq") "/bin"
+                               ":" (assoc-ref %build-inputs "sed") "/bin"
+                               ":" (assoc-ref %build-inputs "socat") "/bin"
+                               ":" (assoc-ref %build-inputs "util-linux") "/bin"
+                               ":" (assoc-ref %build-inputs "which") "/bin"
+                               ":" (assoc-ref %build-inputs "xdg-utils") "/bin"
+                               ":" (assoc-ref %build-inputs "yad") "/bin")))
+               (with-output-to-file bcu.sh
+                 (lambda _
+                   (display (string-append "#!" bash "/bin/bash\n"))
+                   (display "[[ \"$_BCU_SH_LOADED\" == YES ]] || { \n")
+                   (display (string-append "export PATH=\"" path
+                                           "${PATH:+:}${PATH}\"\n"))
+                   (display (string-append "export PYTHONPATH=\"" pylibsline
+                                           "${PYTHONPATH:+:}${PYTHONPATH}\"\n"))
+                   (display
+                    (string-append "export GUILE_LOAD_PATH=\"" g-bash-lib
+                                   "${GUILE_LOAD_PATH:+:}${GUILE_LOAD_PATH}\"\n"))
+                   ;; XDG_DATA_DIRS needs set for yad to load icons properly.
+                   (display (string-append
+                             "[[ -e /run/current-system/profile/share ]] && "
+                             "export XDG_DATA_DIRS="
+                             "/run/current-system/profile/share"
+                             "${XDG_DATA_DIRS:+:}${XDG_DATA_DIRS}\n"))
+                   (display (string-append "source " libexec "/bcu.sh\n"))
+                   (display "}\n")))
+               (chmod bcu.sh #o555)
+               (setenv "PATH" (string-append path ":" (getenv "PATH"))))
+             (substitute* (find-files out ".*\\.sh")
+               (("~/\\.guix-profile/lib/bash/libguile-bash\\.so")
+                (string-append guile-bash "/lib/bash/libguile-bash.so"))
+               (("\"\\$GUIX_PROFILE\"/lib/bash/libguile-bash\\.so")
+                (string-append guile-bash "/lib/bash/libguile-bash.so")))
+             (for-each (lambda (file)
+                         (patch-shebang file))
+                       (find-files out ".*\\.(sh|scm|awk|php|py)$")   )
+             ;; Set up PATH for tests.
+             (setenv "PATH" (string-append bin ":" (getenv "PATH")))
+             ;; Some tests need a HOME directory.
+             (setenv "HOME" "/tmp")
+             ;; Disable network tests, and all tests for setopts which
+             ;; don't work inside the Guix build environment.
+             (with-output-to-file (string-append libexec "/disabled_tests.txt")
+               (lambda _
+                 (format #t "~{~a~%~}"
+                         (list "ip_of_test_1"
+                               "setopts_test_1"
+                               "setopts_test_2"
+                               "setopts_test_3"
+                               "setopts_test_4"
+                               "setopts_test_5"
+                               "setopts_test_6"))))
+             (invoke (string-append libexec "/bcu-test.sh"))))))
+      (home-page "https://gitlab.com/methuselah-0/bash-coding-utils.sh")
+      (synopsis "Functions and tools for software prototyping in Bash")
+      (description
+       "This package contains Bash functions and wrappers that can be useful
+when writing quick implementations of new programs.  It helps you work with
+JSON, XML, and parallelization, and installs some commonly used helper programs
+used in Bash scripting.  Just run @command{. bcu.sh}, type @command{bcu__}, hit
+@key{TAB} to see available functions and give any of them the @code{--help}
+flag to see how to use it, or run @command{bcu__docs} for the full HTML
+documentation.")
+      (license license:gpl3))))
-- 
2.34.0
-----BEGIN PGP SIGNATURE-----

iIMEARYKACsWIQT12iAyS4c9C3o4dnINsP+IT1VteQUCYZkFgQ0cbWVAdG9iaWFz
LmdyAAoJEA2w/4hPVW15t5kA/1hUt6eWgsPInj1c+tgtc8Y1NLVCh1KL3T9iX5ME
s87jAQDSxy1Bv8+ki2J21Oea1bgjVUfKnmLw0/dxsoXPgRoNBw==
=7rK0
-----END PGP SIGNATURE-----

D
D
david larsson wrote on 23 Nov 2021 13:44
(name . Tobias Geerinckx-Rice)(address . me@tobias.gr)
d4c8d512dd211d920130cdf25c682954@selfhosted.xyz
Toggle quote (4 lines)
> However, you make an excellent point, and this packages's intended
> usage means that it will clobber the caller's environment, not just
> its own.

Yep, it will. Previously I had the dependencies as propagated inputs but
I think the current approach with putting them as inputs and creating a
wrapper script is better.

Toggle quote (6 lines)
> If I were to use this package (and I might—it's neat) I would almost
> certainly end up using it in a setting where changing PATH at all
> would cause unexpected and frustrating ‘bugs’.
>
> Hmm…

Im not sure I follow here.. can you give an example? Maybe some info or
warning can be added to the description?

Personally, I would be happy to see the current patch you provided
committed to master, except I would just update to the very most recent
commit again.

Thanks for reviewing this!

Best regards,
David
D
D
david larsson wrote on 1 Jul 20:13 +0200
Re: [bug#51512] [PATCH v 3]: gnu: Add bash-bcu.
(address . 51512@debbugs.gnu.org)(name . Guix-patches)(address . guix-patches-bounces+david.larsson=selfhosted.xyz@gnu.org)
482320c017a2ab923b040cb83746e563@selfhosted.xyz
New version based on prior reviews and off-list (IRC) communication.

Best regards,
David L
(
[PATCH]: gnu: Add bash-bcu.
(address . 51512@debbugs.gnu.org)
CL76IJDONOSA.2D1R7QC88T550@guix-aspire
Hello! Following a request on IRC, I'll try to review this patch to the
best of my abilities. (I'm just sending this so that the thread appears
in my inbox, since it's from before I subscribed to guix-patches. I'm
sure there's a better way, but oh well :))

-- (
(
CL76QJLEG1FE.A9WDOEV5TDNO@guix-aspire
On Mon Jul 4, 2022 at 10:11 PM BST, ( via Guix-patches via wrote:
Toggle quote (2 lines)
> (I'm just sending this so that the thread appears in my inbox)

It didn't work. I should have looked harder, all I needed to do was
download and import the mbox.

-- (
D
D
david larsson wrote on 2 Aug 22:21 +0200
Re: [bug#51512] [PATCH v 3]: gnu: Add bash-bcu.
(address . 51512@debbugs.gnu.org)(name . Guix-patches)(address . guix-patches-bounces+david.larsson=selfhosted.xyz@gnu.org)
0502a262288c12f706231f7bf55c9a21@selfhosted.xyz
Ping!

On 2022-07-01 20:13, david larsson wrote:
Toggle quote (4 lines)
> New version based on prior reviews and off-list (IRC) communication.
>
> Best regards,
> David L
D
D
david larsson wrote on 27 Aug 20:29 +0200
(address . 51512@debbugs.gnu.org)(name . Guix-patches)(address . guix-patches-bounces+david.larsson=selfhosted.xyz@gnu.org)
c300f858bd110d54769ec626667aa7a2@selfhosted.xyz
Ping!

On 2022-08-02 22:21, david larsson wrote:
Toggle quote (7 lines)
> Ping!
>
> On 2022-07-01 20:13, david larsson wrote:
>> New version based on prior reviews and off-list (IRC) communication.
>>
>> Best regards,
>> David L
?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send email to 51512@debbugs.gnu.org