all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#51512] [PATCH]: gnu: Add bash-bcu.
@ 2021-10-30 14:59 david larsson
  2021-11-07 12:40 ` Tobias Geerinckx-Rice via Guix-patches via
                   ` (6 more replies)
  0 siblings, 7 replies; 24+ messages in thread
From: david larsson @ 2021-10-30 14:59 UTC (permalink / raw)
  To: 51512

[-- Attachment #1: Type: text/plain, Size: 85 bytes --]

Hi,
This patch adds "bash-coding-utils" as the bash-bcu package.

Best regards,
David

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnu-Add-bash-bcu.patch --]
[-- Type: text/x-diff; name=0001-gnu-Add-bash-bcu.patch, Size: 12050 bytes --]

From b79e6173263acb8d77946a08e03d5b01a9f5f86c Mon Sep 17 00:00:00 2001
From: David Larsson <david.larsson@selfhosted.xyz>
Date: Fri, 29 Oct 2021 13:58:41 +0200
Subject: [PATCH] gnu: Add bash-bcu.

* gnu/packages/bash.scm (bash-bcu): New variable.
---
 gnu/packages/bash.scm | 193 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 193 insertions(+)

diff --git a/gnu/packages/bash.scm b/gnu/packages/bash.scm
index ed2931fd97..f89dcf5341 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,179 @@ in Bash, but you can use it to test any UNIX program.")
 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-bcu
+  (let ((pyver (version-major+minor (package-version python)))
+        (guilever (version-major+minor (package-version guile-3.0))))
+    (package
+      (name "bash-bcu")
+      (version "v0.2.0")
+      (home-page "https://gitlab.com/methuselah-0/bash-coding-utils.sh")
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (commit "40d6527a9effb4e18778c37bebaa9f3a58de12d6")
+               (url "https://gitlab.com/methuselah-0/bash-coding-utils.sh.git")
+               (recursive? #t)))
+         (sha256
+          (base32
+           "007g6wfybjr0ms32qikb545r11lgm3p98cd7dbzpfyh0grgn9vj1"))))
+      (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)))
+      (arguments
+       `(#:modules ((guix build utils))
+         #:builder
+         (begin
+           (use-modules (guix build utils))
+           (let* ((bashfull (assoc-ref %build-inputs "bash-full"))
+                  ;; 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))
+                  ;; Some python libraries needs added to PYTHONPATH
+                  (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)
+               (chmod binfile #o555)
+               (setenv "PATH" (string-append pathline ":" (getenv "PATH"))))
+             (for-each (lambda (file)
+                         (substitute* file
+                           (("~/\\.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"))))
+                       (find-files out ".*\\.sh"))
+             (for-each (lambda (file)
+                         (patch-shebang file))
+                       (find-files out ".*\\.(sh|scm|awk|php|py)$"))
+             ;; Setup 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
+             (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)))
+             (invoke (string-append libexec "/bcu-test.sh"))))))
+      (build-system trivial-build-system)
+      (synopsis "Bash functions and tools for software prototyping in Bash")
+      (description
+       (string-append
+        "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\""
+        " programs used in Bash scripting.  Just run @command{. bcu.sh}, type "
+        "@command{bcu__}, hit @command{TAB} to see available functions and give"
+        " any of them the @command{ --help} flag to see how to use it, or run "
+        "@command{bcu__docs} for the full html documentation."))
+      (license license:gpl3))))
-- 
2.31.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [bug#51512] [PATCH]: gnu: Add bash-bcu.
  2021-10-30 14:59 [bug#51512] [PATCH]: gnu: Add bash-bcu david larsson
@ 2021-11-07 12:40 ` Tobias Geerinckx-Rice via Guix-patches via
  2021-11-09 12:32   ` [bug#51512] [PATCH v 2]: " david larsson
  2021-11-15 16:45   ` Recommend order for package fields? zimoun
  2022-07-04 21:11 ` [bug#51512] [PATCH]: gnu: Add bash-bcu ( via Guix-patches via
                   ` (5 subsequent siblings)
  6 siblings, 2 replies; 24+ messages in thread
From: Tobias Geerinckx-Rice via Guix-patches via @ 2021-11-07 12:40 UTC (permalink / raw)
  To: david larsson; +Cc: 51512

[-- Attachment #1: Type: text/plain, Size: 14200 bytes --]

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 写道:
> This patch adds "bash-coding-utils" as the bash-bcu package.

[…]

> +(define-public bash-bcu

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

> +  (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.

> +    (package
> +      (name "bash-bcu")
> +      (version "v0.2.0")

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

> +      (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.

> +      (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.

> +               (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.

> +          (base32
> +           "007g6wfybjr0ms32qikb545r11lgm3p98cd7dbzpfyh0grgn9vj1"))))

This can be one line.

> +      (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.

> +      (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.

> +                  ;; 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…

> +                  ;; 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).

> +                  (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?

> +               (chmod binfile #o555)

s/binfile/wrapper/ or somesuch.

> +               (setenv "PATH" (string-append pathline ":" 
> (getenv "PATH"))))

s/pathline/path/

> +             (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.

> +                       (find-files out ".*\\.sh"))

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

> +                       (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.

> +             (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"))))

> +      (synopsis "Bash functions and tools for software 
> prototyping in Bash")

I dropped the leading ‘Bash ’ here.

> +      (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.

> +        "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.

> + @command{TAB}
> + @command{ --help}

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

> + 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?

> +      (license license:gpl3))))

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

Kind regards,

T G-R

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 247 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [bug#51512] [PATCH v 2]: gnu: Add bash-bcu.
  2021-11-07 12:40 ` Tobias Geerinckx-Rice via Guix-patches via
@ 2021-11-09 12:32   ` david larsson
  2021-11-20 14:11     ` Tobias Geerinckx-Rice via Guix-patches via
  2022-07-01 18:13     ` [bug#51512] [PATCH v 3]: " david larsson
  2021-11-15 16:45   ` Recommend order for package fields? zimoun
  1 sibling, 2 replies; 24+ messages in thread
From: david larsson @ 2021-11-09 12:32 UTC (permalink / raw)
  To: 51512

[-- Attachment #1: Type: text/plain, Size: 2858 bytes --]

On 2021-11-07 13:40, Tobias Geerinckx-Rice wrote:
> 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.

[...]

>> +               (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.

>> +      (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 #2: 0001-gnu-Add-bash-bcu.patch --]
[-- Type: text/x-diff, Size: 11548 bytes --]

From d3ee10521b981fb4b97b2020bf9e3cd8373c3d5b Mon Sep 17 00:00:00 2001
From: David Larsson <david.larsson@selfhosted.xyz>
Date: Fri, 29 Oct 2021 13:58:41 +0200
Subject: [PATCH] gnu: Add bash-bcu.

* gnu/packages/bash.scm (bash-bcu): New variable.
---
 gnu/packages/bash.scm | 195 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 195 insertions(+)

diff --git a/gnu/packages/bash.scm b/gnu/packages/bash.scm
index ed2931fd97..95294ef5ed 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,181 @@ in Bash, but you can use it to test any UNIX program.")
 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
+  (package
+    (name "bash-coding-utils")
+    (version "0.2.0")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (commit "608a4c2a615e0d6e35bbb28d3a42864ee013975")
+             (url "https://gitlab.com/methuselah-0/bash-coding-utils.sh.git")
+             ;; TODO: unbundle submodules some day.
+             (recursive? #t)))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "1hfcxfv2i7rara96nk4w9babg8bm8khr2m9nlh09hxjhn22l0jga"))))
+    (build-system trivial-build-system)
+    (arguments
+     `(#:modules ((guix build utils))
+       #:builder
+       (begin
+         (use-modules (guix build utils))
+         (let* ((python-version ,(version-major+minor (package-version python)))
+                (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
+                (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* ((wrapper (string-append bin "/bcu.sh"))
+                  (bcu-port (open-file wrapper "a"))
+                  (path (string-append
+                         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")))
+             (display (string-append "#!" bash "/bin/bash\n") bcu-port)
+             (display
+              (string-append
+               "[[ \"$_BCU_SH_LOADED\" == YES ]] || { \nexport PATH=\""
+               path "${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)
+             (chmod wrapper #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)$"))
+
+;;; Now that everything's installed, prepare & run the tests.
+           ;; Setup 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"))))))
+    (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)))
+    (synopsis "Functions and tools for software prototyping in Bash")
+    (home-page "https://gitlab.com/methuselah-0/bash-coding-utils.sh")
+    (description
+     "Bash-coding-utils 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\" programs used in Bash scripting.  Just run @command{. bcu.sh},
+ and type @command{bcu__docs} for the full html documentation.")
+    (license license:gpl3)))
-- 
2.31.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Recommend order for package fields?
  2021-11-07 12:40 ` Tobias Geerinckx-Rice via Guix-patches via
  2021-11-09 12:32   ` [bug#51512] [PATCH v 2]: " david larsson
@ 2021-11-15 16:45   ` zimoun
  2021-11-16 18:54     ` Katherine Cox-Buday
  2021-11-17 11:18     ` Ludovic Courtès
  1 sibling, 2 replies; 24+ messages in thread
From: zimoun @ 2021-11-15 16:45 UTC (permalink / raw)
  To: Tobias Geerinckx-Rice; +Cc: Guix Devel

Hi,

On Sun, 07 Nov 2021 at 13:40, Tobias Geerinckx-Rice via Guix-patches via <guix-patches@gnu.org> wrote:

> 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.

Does it make sense to add this ordering advice in the manual?  Somewhere
under section “Contributing”.

Especially when there is probably some issues with the semantic, for
instance, compare [1] corner cases:

--8<---------------cut here---------------start------------->8---
$ guix repl
GNU Guile 3.0.7
Copyright (C) 1995-2021 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guix-user)> (let ((name "OUTER"))
  (package-version
   (package
     (version name)
     (name "name")
     (source #f)
     (build-system #f)
     (synopsis #f)
     (description #f)
     (license #f)
     (home-page #f))))

$1 = "OUTER"
scheme@(guix-user)> (let ((name "OUTER"))
  (package-version
   (package
     (name "INNER")
     (version name)
     (source #f)
     (build-system #f)
     (synopsis #f)
     (description #f)
     (license #f)
     (home-page #f))))
$2 = "INNER"
--8<---------------cut here---------------end--------------->8---

where a record field refers to another defined record field.


If yes, why not add a checker for “guix lint” for warning that?  And
obviously, it could be nice to have an automatic tool for formatting;
something similar as etc/indent-code.el for ordering packages. ;-)

Cheers,
simon


1: <https://yhetil.org/guix/20201204161257.64363a5a@scratchpost.org/>


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Recommend order for package fields?
  2021-11-15 16:45   ` Recommend order for package fields? zimoun
@ 2021-11-16 18:54     ` Katherine Cox-Buday
  2021-11-17 11:15       ` Ludovic Courtès
  2021-11-17 11:18     ` Ludovic Courtès
  1 sibling, 1 reply; 24+ messages in thread
From: Katherine Cox-Buday @ 2021-11-16 18:54 UTC (permalink / raw)
  To: zimoun; +Cc: Guix Devel

zimoun <zimon.toutoune@gmail.com> writes:

> And obviously, it could be nice to have an automatic tool for formatting; > something similar as etc/indent-code.el for ordering packages. ;-)

And cleaning up unused imports too! Does such a thing exist for Guile in general?

-- 
Katherine


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Recommend order for package fields?
  2021-11-16 18:54     ` Katherine Cox-Buday
@ 2021-11-17 11:15       ` Ludovic Courtès
  0 siblings, 0 replies; 24+ messages in thread
From: Ludovic Courtès @ 2021-11-17 11:15 UTC (permalink / raw)
  To: Katherine Cox-Buday; +Cc: Guix Devel

Hi,

Katherine Cox-Buday <cox.katherine.e@gmail.com> skribis:

> zimoun <zimon.toutoune@gmail.com> writes:
>
>> And obviously, it could be nice to have an automatic tool for formatting; > something similar as etc/indent-code.el for ordering packages. ;-)
>
> And cleaning up unused imports too! Does such a thing exist for Guile in general?

Unfortunately no.

Ludo’.


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Recommend order for package fields?
  2021-11-15 16:45   ` Recommend order for package fields? zimoun
  2021-11-16 18:54     ` Katherine Cox-Buday
@ 2021-11-17 11:18     ` Ludovic Courtès
  2021-11-17 11:40       ` zimoun
  1 sibling, 1 reply; 24+ messages in thread
From: Ludovic Courtès @ 2021-11-17 11:18 UTC (permalink / raw)
  To: zimoun; +Cc: Guix Devel

Hi,

zimoun <zimon.toutoune@gmail.com> skribis:

> On Sun, 07 Nov 2021 at 13:40, Tobias Geerinckx-Rice via Guix-patches via <guix-patches@gnu.org> wrote:
>
>> 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.
>
> Does it make sense to add this ordering advice in the manual?  Somewhere
> under section “Contributing”.

I don’t think so; examples in the manual, ‘guix import’, etc. are
already mostly consistent.

> Especially when there is probably some issues with the semantic, for
> instance, compare [1] corner cases:

It’s not a corner case, it’s lexical scoping.  :-)

> If yes, why not add a checker for “guix lint” for warning that?  And
> obviously, it could be nice to have an automatic tool for formatting;
> something similar as etc/indent-code.el for ordering packages. ;-)

I think ‘guix style’ should eventually be improved to replace
etc/indent-code.el.  We could augment it with specific stylers, such as
alphabetically sorting inputs.

Thanks,
Ludo’.


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Recommend order for package fields?
  2021-11-17 11:18     ` Ludovic Courtès
@ 2021-11-17 11:40       ` zimoun
  2021-11-19 14:51         ` Ludovic Courtès
  0 siblings, 1 reply; 24+ messages in thread
From: zimoun @ 2021-11-17 11:40 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: Guix Devel

Hi,

On Wed, 17 Nov 2021 at 12:18, Ludovic Courtès <ludo@gnu.org> wrote:

> I don’t think so; examples in the manual, ‘guix import’, etc. are
> already mostly consistent.

From my point of view, an explicit recommendation is always better
than an implicit one.  If it is already consistent and defacto
ordering, it costs nothing to write down such as a recommendation and
it helps, IMHO.

(On a side note, IMHO, similar issues with packages sorted or not
depending on the phase of the Moon, mostly, or with inputs sorted or
not depending on the phase of the Moon, mostly. ;-))


> > Especially when there is probably some issues with the semantic, for
> > instance, compare [1] corner cases:
>
> It’s not a corner case, it’s lexical scoping.  :-)

Thanks for explaining. :-)  Let rephrase: compare different behaviours
[1] depending on lexical scope which is odd in the framework of
"declarative".  Anyway, your point is: it is a feature, not an issue,
IIUC.


> > If yes, why not add a checker for “guix lint” for warning that?  And
> > obviously, it could be nice to have an automatic tool for formatting;
> > something similar as etc/indent-code.el for ordering packages. ;-)
>
> I think ‘guix style’ should eventually be improved to replace
> etc/indent-code.el.  We could augment it with specific stylers, such as
> alphabetically sorting inputs.

Ah yes I have forgotten about "guix style".  :-)


Cheers,
simon


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Recommend order for package fields?
  2021-11-17 11:40       ` zimoun
@ 2021-11-19 14:51         ` Ludovic Courtès
  0 siblings, 0 replies; 24+ messages in thread
From: Ludovic Courtès @ 2021-11-19 14:51 UTC (permalink / raw)
  To: zimoun; +Cc: Guix Devel

Hi!

zimoun <zimon.toutoune@gmail.com> skribis:

> Thanks for explaining. :-)  Let rephrase: compare different behaviours
> [1] depending on lexical scope which is odd in the framework of
> "declarative".  Anyway, your point is: it is a feature, not an issue,
> IIUC.

Exactly.  :-)

We’re verrrry far from having the kind of inconsistency I observed in
Nixpkgs back when I contributed.  And I think the difference mostly lies
in how people work together; it’s a social issue.

Ludo’.


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [bug#51512] [PATCH v 2]: gnu: Add bash-bcu.
  2021-11-09 12:32   ` [bug#51512] [PATCH v 2]: " david larsson
@ 2021-11-20 14:11     ` Tobias Geerinckx-Rice via Guix-patches via
  2021-11-23 12:44       ` david larsson
  2022-07-01 18:13     ` [bug#51512] [PATCH v 3]: " david larsson
  1 sibling, 1 reply; 24+ messages in thread
From: Tobias Geerinckx-Rice via Guix-patches via @ 2021-11-20 14:11 UTC (permalink / raw)
  To: david larsson; +Cc: 51512


[-- Attachment #1.1: Type: text/plain, Size: 1158 bytes --]

David,

david larsson 写道:
> 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.

> 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:

> +      ":" (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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: wip-bcu.patch --]
[-- Type: text/x-patch, Size: 12224 bytes --]

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(+)

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


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 247 bytes --]

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [bug#51512] [PATCH v 2]: gnu: Add bash-bcu.
  2021-11-20 14:11     ` Tobias Geerinckx-Rice via Guix-patches via
@ 2021-11-23 12:44       ` david larsson
  0 siblings, 0 replies; 24+ messages in thread
From: david larsson @ 2021-11-23 12:44 UTC (permalink / raw)
  To: Tobias Geerinckx-Rice; +Cc: 51512

> 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.

> 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




^ permalink raw reply	[flat|nested] 24+ messages in thread

* [bug#51512] [PATCH v 3]: gnu: Add bash-bcu.
  2021-11-09 12:32   ` [bug#51512] [PATCH v 2]: " david larsson
  2021-11-20 14:11     ` Tobias Geerinckx-Rice via Guix-patches via
@ 2022-07-01 18:13     ` david larsson
  2022-08-02 20:21       ` david larsson
  1 sibling, 1 reply; 24+ messages in thread
From: david larsson @ 2022-07-01 18:13 UTC (permalink / raw)
  To: 51512; +Cc: Guix-patches

[-- Attachment #1: Type: text/plain, Size: 91 bytes --]

New version based on prior reviews and off-list (IRC) communication.

Best regards,
David L

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnu-Add-bash-coding-utils.patch --]
[-- Type: text/x-diff; name=0001-gnu-Add-bash-coding-utils.patch, Size: 29278 bytes --]

From afcf99849048cf31384d9efcce99f2a4815346d6 Mon Sep 17 00:00:00 2001
From: David Larsson <david.larsson@selfhosted.xyz>
Date: Wed, 29 Jun 2022 23:35:50 +0200
Subject: [PATCH] gnu: Add bash-coding-utils

* gnu/packages/bash.scm (guile-bash-for-bash-coding-utils,
 org-html-themes/methuselah-0, pydaemon, bash-coding-utils):
New variables.
* gnu/packages/patches/guile-bash-args-from-stdin.patch: New file.
* gnu/local.mk: Register patch.
---
 gnu/local.mk                                  |   1 +
 gnu/packages/bash.scm                         | 466 +++++++++++++++++-
 .../patches/guile-bash-args-from-stdin.patch  |  42 ++
 3 files changed, 504 insertions(+), 5 deletions(-)
 create mode 100644 gnu/packages/patches/guile-bash-args-from-stdin.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 353b91cfd2..b9ff9a3784 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1229,6 +1229,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/guile-1.8-cpp-4.5.patch			\
   %D%/packages/patches/guile-2.2-skip-oom-test.patch            \
   %D%/packages/patches/guile-2.2-skip-so-test.patch             \
+  %D%/packages/patches/guile-bash-args-from-stdin.patch		\
   %D%/packages/patches/guile-default-utf8.patch			\
   %D%/packages/patches/guile-2.2-default-utf8.patch		\
   %D%/packages/patches/guile-relocatable.patch			\
diff --git a/gnu/packages/bash.scm b/gnu/packages/bash.scm
index 72758560cd..f058793160 100644
--- a/gnu/packages/bash.scm
+++ b/gnu/packages/bash.scm
@@ -26,17 +26,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 bison)
   #:use-module (gnu packages bootstrap)
   #:use-module (gnu packages compression)
+  #:use-module (gnu packages curl)
+  #:use-module (gnu packages dns)
   #:use-module (gnu packages elf)
-  #:use-module (gnu packages ncurses)
-  #:use-module (gnu packages readline)
-  #:use-module (gnu packages bison)
+  #:use-module (gnu packages file)
+  #:use-module (gnu packages freedesktop)
+  #:use-module (gnu packages gawk)
+  #:use-module (gnu packages gtk)
+  #:use-module (gnu packages guile)
+  #:use-module (gnu packages guile-xyz)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages libffi)
+  #:use-module (gnu packages lsof)
+  #:use-module (gnu packages ncurses)
+  #:use-module (gnu packages networking)
+  #: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 guile)
+  #:use-module (gnu packages python)
+  #:use-module (gnu packages python-xyz)
+  #:use-module (gnu packages readline)
+  #:use-module (gnu packages web)
+  #:use-module (gnu packages xml)
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix git-download)
@@ -45,7 +62,8 @@ (define-module (gnu packages bash)
   #:use-module (guix monads)
   #:use-module (guix store)
   #:use-module (guix build-system gnu)
-  #:use-module (guix build-system trivial)
+  #:use-module (guix build-system copy)
+  #:use-module (guix build-system trivial)  
   #:autoload   (guix gnupg) (gnupg-verify*)
   #:autoload   (guix base32) (bytevector->nix-base32-string)
 
@@ -456,3 +474,441 @@ (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 guile-bash-for-bash-coding-utils
+  (let ((commit "1eabc563ca5692b3e08d84f1f0e6fd2283284469")
+        (revision "0"))
+    (package
+      (inherit guile2.0-bash)
+      (version (string-append "0.1.6-" revision "." (string-take commit 7)))
+      (home-page (package-home-page guile2.0-bash))
+      (name "guile-bash-for-bash-coding-utils")
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (commit commit)
+                      (url home-page)))
+                (sha256
+                 (base32
+                  "097vny990wp2qpjij6a5a5gwc6fxzg5wk56inhy18iki5v6pif1p"))
+                (file-name (string-append name "-" version "-checkout"))
+                (patches (search-patches "guile-bash-args-from-stdin.patch"))))
+      (inputs
+       `(("guile" ,guile-3.0-latest)
+         ,@(assoc-remove! (package-inputs guile2.0-bash) "guile")))
+      (propagated-inputs (list bash))
+      (arguments
+       `(#:tests? #f
+         #:phases (modify-phases %standard-phases
+                    (add-after 'install 'install-guile
+                      (lambda* (#:key inputs outputs #:allow-other-keys)
+                        (copy-recursively
+                         (string-append (assoc-ref outputs "out")
+                                        (assoc-ref inputs "guile") "/share")
+                         (string-append (assoc-ref outputs "out") "/share"))
+                      #t)))
+         ,@(package-arguments guile2.0-bash))))))
+
+(define org-html-themes/methuselah-0
+  ;; XXX Bundles jquery and several other .js ‘libraries’ — problem?
+  ;; XXX A form of https://github.com/fniessen/org-html-themes but not
+  ;; drop-in compatible (using that would break the BCU docs).
+  ;; ‘Ideally’ we'd re-render them but uugh.
+  (let ((commit "8fff1d4c0879537b81f94d157a8c36485c790ee5")
+        (revision "0"))
+    (package
+      (name "org-html-themes")
+      (version (git-version "0.0.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (commit commit)
+               (url "https://gitlab.com/methuselah-0/org-html-themes.git")))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 "1hddgfdry8r65a5zqm1pc0rgicv78ls6giavfr5g0rzx428i1j45"))))
+      (build-system copy-build-system)
+      (home-page "https://github.com/fniessen/org-html-themes") ; XXX
+      (synopsis "Export Org mode files to HTML")
+      (description
+       "The Org-HMTL framework provides cross-browser themes for exporting Org
+documents to cross-browser HTML mark-up.")
+      (license license:cc-by-sa3.0))))
+
+(define-public pydaemon
+  (let ((commit "dae2798a2c1caa56025c6da69c0d464f70d9c79a")
+        (revision "0"))
+    (package
+      (name "pydaemon")
+      (version (git-version "0.0.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (commit commit)
+               (url "https://gitlab.com/methuselah-0/pydaemon.git")))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 "1cbg48ljyjqw1vxcb0sqhg9cxx0vgs6ggsdg8yvj441s6gakp2sh"))))
+      (build-system trivial-build-system)
+
+      (inputs (list coreutils netcat python socat util-linux))
+      (arguments
+       (list #:modules '((guix build utils))
+             #:builder
+             #~(begin
+                 (use-modules (guix build utils))
+                   (with-directory-excursion #$(package-source this-package)
+                     (mkdir-p (string-append (assoc-ref %outputs "out") "/bin"))
+                     (copy-file "pydaemon.py"
+                                (string-append (assoc-ref %outputs "out") "/bin/pydaemon.py"))
+                     (copy-file "py-net-daemon.py"
+                                (string-append (assoc-ref %outputs "out") "/bin/py-net-daemon.py"))
+                     (copy-file "pydaemon.sh"
+                                (string-append (assoc-ref %outputs "out") "/bin/pydaemon.sh"))
+
+                     (substitute* (find-files (string-append #$output "/bin") "\\.sh$")
+                       (("(flock) " library _)
+                        (string-append #$(this-package-input "util-linux") "/bin/" library))
+                       (("(socat) " library _)
+                        (string-append #$(this-package-input "socat") "/bin/" library))
+                       (("(nc) " library _)
+                        (string-append #$(this-package-input "netcat") "/bin/" library))
+                       (("( )(mkdir|cat|sleep|chown|id|kill|dirname) " all pre command _)
+                        (string-append pre #$(this-package-input "coreutils") "/bin/" command " "))
+                       (("(\\()(mkdir|cat|sleep|chown|id|kill|dirname) " all pre command _)
+                        (string-append pre #$(this-package-input "coreutils") "/bin/" command " "))
+                       (("(python3) " library _)
+                        (string-append #$(file-append (this-package-input "python")
+                                                      "/bin/python"
+                                                      (version-major+minor
+                                                       (package-version
+                                                        (this-package-input
+                                                         "python"))))
+                                       " ")))))))
+      (home-page "https://gitlab.com/methuselah-0/pydaemon")
+      (synopsis "Use python from bash")
+      (description "With pydaemon you can pipe strings of python code to one
+or multiple persistent python processes that keeps state, and get the results
+back as strings.  Can be used over either of a unix or tcp socket.")
+      (license license:cc-by-sa3.0))))
+
+(define-public bash-coding-utils
+  (let ((commit "ce9e7a8910d7debe29a07b48aa0770913b1ecdaf")
+        (revision "0"))
+    (package
+      (name "bash-coding-utils")
+      (version (git-version "0.3.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri
+          (git-reference
+           (commit commit)
+           (url "https://git.sr.ht/~methuselah-0/bash-coding-utils")
+           (recursive? #t))          )
+         (sha256
+          (base32 "0hgj0fy66bj5kbjs02fvjp5n9a5sz32fk45rc3id2bs0b2k9jrnx"))
+         (file-name (git-file-name name version))))
+      (build-system trivial-build-system)
+      (arguments
+       (list #:modules '((guix build utils))
+             #:builder
+             #~(begin
+                 (use-modules (guix build utils)
+                              (ice-9 ftw)
+                              (ice-9 match)
+                              (srfi srfi-26))
+                 (let* ((bash #$(this-package-input "bash"))
+                        (bin (string-append #$output "/bin"))
+                        (bcu.sh (string-append bin "/bcu.sh"))
+                        (share (string-append #$output "/share"))
+                        (doc (string-append share "/doc/" #$name))
+                        ;; Everything but bcu.sh itself is only ever accessed
+                        ;; internally by bcu, so put it all in share/.
+                        (bcu-root (string-append share "/bcu"))
+                        ;; XXX We should honour the without-tests transformation!
+                        (tests? (not #$(%current-target-system))))
+
+                   ;; Copy the ‘source’ and submodules directly to the output.
+                   (let ((source #$(package-source this-package)))
+                     (with-directory-excursion source
+                       (mkdir-p bcu-root)
+                       (for-each (lambda (file)
+                                   (copy-recursively file
+                                                     (string-append bcu-root
+                                                                    "/" file)))
+                                 (list "bcu.sh"
+                                       "dependency_paths.sh"
+                                       "bcu-test.sh"
+                                       "docs"
+                                       "src"
+                                       "submodules"))
+                       ;; Moving docs/ out of bcu-root would break symlinks.
+                       (mkdir-p (dirname doc))
+                       (symlink (string-append bcu-root "/docs") doc)))
+
+                   ;; Patch absolute file name references.
+                   (let* ((original-path (getenv "PATH"))
+                          (shebang-inputs '(#$@(map (lambda (name)
+                                                      (this-package-input name))
+                                                    '("guile"
+                                                      "python"))))
+                          (shebang-path (string-join
+                                         (map (cut string-append <> "/bin")
+                                              (cons bash shebang-inputs))
+                                         ":")))
+                     (setenv "PATH" shebang-path)
+                     (for-each patch-shebang
+                               (find-files #$output "\\.(sh|scm|py)$"))
+                     (setenv "PATH" original-path))
+
+                   ;; Add paths to dependencies - defined in
+                   ;; dependency_paths.sh, except the libguile-bash.so
+                   ;; file.
+                   (substitute* (find-files #$output "\\.sh$")
+                     (("[^ ]*(/lib/bash/libguile-bash\\.so)" _ library)
+                      (string-append
+                       #$(this-package-input "guile-bash-for-bash-coding-utils")
+                       library)))
+
+                   ;; TODO: use a PCRE regex to substitute invocations of coreutils
+                   ;; commands
+                   ;; TODO: condense below substitutions?
+                   (substitute* (find-files #$output "dependency_paths\\.sh$")
+                     (("export BCUCTYPES=(ctypes.sh)" _ library)
+                      (string-append "export BCUCTYPES="
+                                     #$(this-package-input "bash-ctypes")
+                                     "/bin/" library))
+                     (("export BCUDIFF=(diff)" _ library)
+                      (string-append "export BCUDIFF="
+                                     #$(this-package-input "diffutils")
+                                     "/bin/" library))
+                     (("export BCUPING=(ping)" _ library)
+                      (string-append "export BCUPING=/run/setuid-programs/ping"))
+                     (("export BCUPS=(ps)" _ library)
+                      (string-append "export BCUPS="
+                                     #$(this-package-input "procps")
+                                     "/bin/" library))
+                     (("export BCUFILE=(file)" _ library)
+                      (string-append "export BCUFILE="
+                                     #$(this-package-input "findutils")
+                                     "/bin/" library))
+                     (("export BCUFIND=(find)" _ library)
+                      (string-append "export BCUFIND="
+                                     #$(this-package-input "findutils")
+                                     "/bin/" library))
+                     (("export BCUFLOCK=(flock)" _ library)
+                      (string-append "export BCUFLOCK="
+                                     #$(this-package-input "util-linux")
+                                     "/bin/" library))
+                     (("export BCUGAWK=(gawk)" _ library)
+                      (string-append "export BCUGAWK="
+                                     #$(this-package-input "gawk")
+                                     "/bin/" library))
+                     (("export BCUGREP=(grep)" _ library)
+                      (string-append "export BCUGREP="
+                                     #$(this-package-input "grep")
+                                     "/bin/" library))
+                     (("export GUILE_LOAD_PATH=(.*)$")
+                      (string-append "export GUILE_LOAD_PATH=\""
+                                     (string-join
+                                      '(#$@(map (lambda (name)
+                                                  (file-append (this-package-input name)
+                                                               "/share/guile/site/"
+                                                               (version-major+minor
+                                                                (package-version
+                                                                 (this-package-input
+                                                                  "guile")))))
+                                                '("guile-bash-for-bash-coding-utils")))
+                                      ":")
+                                     "${GUILE_LOAD_PATH:+:}${GUILE_LOAD_PATH}\"\n"))
+                     (("export BCUJQ=(jq)" _ library)
+                      (string-append "export BCUJQ="
+                                     #$(this-package-input "jq")
+                                     "/bin/" library))
+                     (("export BCULSOF=(lsof)" _ library)
+                      (string-append "export BCULSOF="
+                                     #$(this-package-input "lsof")
+                                     "/bin/" library))
+                     (("export BCUNMAP=(nmap)" _ library)
+                      (string-append "export BCUNMAP="
+                                     #$(this-package-input "nmap")
+                                     "/bin/" library))
+                     (("export BCUPCREGREP=(pcregrep)" _ library)
+                      (string-append "export BCUPCREGREP="
+                                     (assoc-ref %build-inputs "pcre:bin")
+                                     "/bin/" library))
+                     (("export BCUPERL=(perl)" _ library)
+                      (string-append "export BCUPERL="
+                                     #$(this-package-input "perl")
+                                     "/bin/" library))
+                     (("export BCUPHP=(php)" _ library)
+                      (string-append "export BCUPHP="
+                                     #$(this-package-input "php")
+                                     "/bin/" library))
+                     (("export BCUPS=(ps)" _ library)
+                      (string-append "export BCUPS="
+                                     #$(this-package-input "procps")
+                                     "/bin/" library))
+                     (("export BCUPYDAEMON=(pydaemon.sh)" _ library)
+                      (string-append "export BCUPYDAEMON="
+                                     #$(this-package-input "pydaemon")
+                                     "/bin/" library))
+                     (("export BCUPYTHONVERSION=(.*)$" _)
+                      (string-append "export BCUPYTHONVERSION="
+                                     #$(version-major+minor
+                                        (package-version
+                                         (this-package-input
+                                          "python")))))
+                     (("export BCUPYTHON=python(.*)$" _)
+                      (string-append "export BCUPYTHON="
+                                     #$(file-append (this-package-input "python")
+                                                    "/bin/python"
+                                                    (version-major+minor
+                                                     (package-version
+                                                      (this-package-input
+                                                       "python"))))
+                                     "\n"))
+                     (("export PYTHONPATH=.*" all)
+                      (string-append "export PYTHONPATH=\""
+                                     (string-join
+                                      '(#$@(map (lambda (name)
+                                                  (file-append (this-package-input name)
+                                                               "/lib/python"
+                                                               (version-major+minor
+                                                                (package-version
+                                                                 (this-package-input
+                                                                  "python")))
+                                                               "/site-packages"))
+                                                '("python"
+                                                  "python-elementpath"
+                                                  "python-lxml"
+                                                  "python-netaddr")))
+                                      ":")
+                                     "${PYTHONPATH:+:}${PYTHONPATH}\"\n"))
+                     (("export BCUSED=(sed)" _ library)
+                      (string-append "export BCUSED="
+                                     #$(this-package-input "sed")
+                                     "/bin/" library))
+                     (("export BCUSOCAT=(socat)" _ library)
+                      (string-append "export BCUSOCAT="
+                                     #$(this-package-input "socat")
+                                     "/bin/" library))
+                     (("export BCUTREE=(tree)" _ library)
+                      (string-append "export BCUTREE="
+                                     #$(this-package-input "tree")
+                                     "/bin/" library))
+                     (("export BCUWHICH=(which)" _ library)
+                      (string-append "export BCUWHICH="
+                                     #$(this-package-input "which")
+                                     "/bin/" library))
+                     (("export XDG_DATA_DIRS=(.*)$")
+                      (string-append
+                       "[[ -e /run/current-system/profile/share ]] && "
+                       "export XDG_DATA_DIRS="
+                       "/run/current-system/profile/share"
+                       "${XDG_DATA_DIRS:+:}${XDG_DATA_DIRS}\n"))
+                     (("export BCUXARGS=(xargs)" _ library)
+                      (string-append "export BCUXARGS="
+                                     #$(this-package-input "findutils")
+                                     "/bin/" library))
+                     (("export BCUXDGOPEN=(xdg-open)" _ library)
+                      (string-append "export BCUXDGOPEN="
+                                     #$(this-package-input "xdg-utils")
+                                     "/bin/" library))
+                     (("export BCUXMLLINT=(xmllint)" _ library)
+                      (string-append "export BCUXMLLINT="
+                                     #$(this-package-input "libxml2-xpath0")
+                                     "/bin/" library)))
+
+                   ;; Symlink to bcu.sh from the output bin directory.
+                   (mkdir-p bin)
+                   (symlink (string-append bcu-root "/bcu.sh") bcu.sh)
+                   (chmod bcu.sh #o555)
+
+                   ;; Disable network and gui tests, and one test for setopts which
+                   ;; doesn't work inside the Guix build environment.
+                   (with-output-to-file (string-append bcu-root "/disabled_tests.txt")
+                     (lambda _
+                       (format #t "~{~a~%~}"
+                               (list "ip_of_test_1"
+                                     "setopts_test_4"
+                                     "web_media_server_test_1"
+                                     "web_api_server_test_1"
+                                     "find_gui_test_1"))))
+
+                   ;; Set up a minimal test environment & run the tests.
+                   (when tests?
+                     (setenv "PATH" (string-append bin ":"
+                                                   bash "/bin:"
+                                                   (getenv "PATH")))
+                     (setenv "SHELL"
+                             (string-append bash "/bin/bash"))
+                     (for-each (lambda (test-input)
+                                 (setenv "PATH"
+                                         (string-append
+                                          (assoc-ref %build-inputs test-input)
+                                          "/bin:" (getenv "PATH"))))
+                               (list "coreutils"))
+                     (setenv "HOME" "/tmp")
+                     (with-directory-excursion bcu-root
+                       (invoke "./bcu-test.sh")
+                       ;; No need to keep passed tests in the final output
+                       (for-each delete-file
+                                 (list "bcu-test.sh"
+                                       "disabled_tests.txt"))))))))
+      (native-inputs
+       `( ;; org-html-themes is bundled upstream as a git submodule,
+         ;; but we package it separately and copy it manually above.
+         ("org-html-themes" ,(package-source org-html-themes/methuselah-0))
+         ("coreutils" ,coreutils) ;; Needed for tests.
+         ;; TODO: unable to get the correct hash for pcre:bin output using
+         ;; the new notation (see inputs list below)
+         ("pcre:bin" ,pcre "bin")))
+      (inputs (list bash
+                    bash-ctypes
+                    coreutils
+                    diffutils
+                    file
+                    findutils
+                    gawk
+                    grep
+                    guile-3.0
+                    guile-bash-for-bash-coding-utils
+                    jq
+                    libxml2-xpath0
+                    lsof
+                    nmap
+                    ;;`(,pcre "bin") ;; TODO doesn't work when calling
+                    ;; #$(this-package-input pcre)!
+                    perl
+                    php
+                    procps
+                    pydaemon
+                    python
+                    python-elementpath
+                    python-lxml
+                    python-netaddr
+                    python-yq
+                    sed
+                    socat
+                    tree
+                    which
+                    xdg-utils
+                    util-linux))
+      (propagated-inputs
+       `(("bash" ,bash))) ;; the bash shell needs to be the same version
+      ;;as guile-bash is compiled against
+      (home-page "https://git.sr.ht/~methuselah-0/bash-coding-utils")
+      (synopsis "Functions and tools for software prototyping in Bash")
+      (description
+       "Bash-Coding-Utils is a library of Bash functions and wrappers that can
+be useful when writing quick implementations of new programs.  It helps you
+work with JSON, XML, API's and parallelization, and installs some helper
+programs commonly 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))))
diff --git a/gnu/packages/patches/guile-bash-args-from-stdin.patch b/gnu/packages/patches/guile-bash-args-from-stdin.patch
new file mode 100644
index 0000000000..ad42616c70
--- /dev/null
+++ b/gnu/packages/patches/guile-bash-args-from-stdin.patch
@@ -0,0 +1,42 @@
+From a124921666a16cb4e93f59a653f98b99c78eb2ca Mon Sep 17 00:00:00 2001
+From: David Larsson <david.larsson@selfhosted.xyz>
+Date: Thu, 11 Nov 2021 14:07:04 +0100
+Subject: [PATCH] Enable reading arguments from bash via stdin
+
+* lisp/gnu/bash.scm(define-bash-function): read from stdin
+to SCM_ARGS array when it is open, and separate args by null
+instead of newline if -z option is passed as $1.
+---
+ lisp/gnu/bash.scm | 16 ++++++++++++----
+ 1 file changed, 12 insertions(+), 4 deletions(-)
+
+diff --git a/lisp/gnu/bash.scm b/lisp/gnu/bash.scm
+index 199ebc0..e9dcea5 100644
+--- a/lisp/gnu/bash.scm
++++ b/lisp/gnu/bash.scm
+@@ -326,10 +326,18 @@
+       (hashq-set! *funcs* symbol thunk)
+       (unsafe-format/eval
+        "function ~a {
+-            SCM_ARGS=($@)    ;
+-            local retval=$~a ;
+-            unset SCM_ARGS   ;
+-            return $retval   ;
++            local -a Input SCM_ARGS                                          ;
++            [[ ! -t 0 ]] && mapfile -d '' Input                              ;
++            if [[ -n \"${Input[@]}\" ]]; then
++                if [[ \"$1\" == -z ]]; then
++                    local -a SCM_ARGS=\"(${Input[*]@Q})\"                    ;
++                else
++                    mapfile -t SCM_ARGS < <(printf '%s' \"${Input[@]}\"); fi ;
++            else
++                SCM_ARGS=(\"$@\"); fi                                        ;
++            local retval=$~a                                                 ;
++            unset SCM_ARGS                                                   ;
++            return $retval                                                   ;
+        }"
+        symbol special-varname))))
+ 
+-- 
+2.31.0
+
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [bug#51512] [PATCH]: gnu: Add bash-bcu.
  2021-10-30 14:59 [bug#51512] [PATCH]: gnu: Add bash-bcu david larsson
  2021-11-07 12:40 ` Tobias Geerinckx-Rice via Guix-patches via
@ 2022-07-04 21:11 ` ( via Guix-patches via
  2022-07-04 21:21   ` ( via Guix-patches via
  2023-05-21  6:58 ` [bug#51512] [PATCH v5]: " david larsson
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 24+ messages in thread
From: ( via Guix-patches via @ 2022-07-04 21:11 UTC (permalink / raw)
  To: 51512

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 :))

    -- (




^ permalink raw reply	[flat|nested] 24+ messages in thread

* [bug#51512] [PATCH]: gnu: Add bash-bcu.
  2022-07-04 21:11 ` [bug#51512] [PATCH]: gnu: Add bash-bcu ( via Guix-patches via
@ 2022-07-04 21:21   ` ( via Guix-patches via
  0 siblings, 0 replies; 24+ messages in thread
From: ( via Guix-patches via @ 2022-07-04 21:21 UTC (permalink / raw)
  To: (, 51512

On Mon Jul 4, 2022 at 10:11 PM BST, ( via Guix-patches via wrote:
> (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.

    -- (




^ permalink raw reply	[flat|nested] 24+ messages in thread

* [bug#51512] [PATCH v 3]: gnu: Add bash-bcu.
  2022-07-01 18:13     ` [bug#51512] [PATCH v 3]: " david larsson
@ 2022-08-02 20:21       ` david larsson
  2022-08-27 18:29         ` david larsson
  0 siblings, 1 reply; 24+ messages in thread
From: david larsson @ 2022-08-02 20:21 UTC (permalink / raw)
  To: 51512; +Cc: Guix-patches

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




^ permalink raw reply	[flat|nested] 24+ messages in thread

* [bug#51512] [PATCH v 3]: gnu: Add bash-bcu.
  2022-08-02 20:21       ` david larsson
@ 2022-08-27 18:29         ` david larsson
  2023-05-20 19:23           ` david larsson
  2023-05-20 20:16           ` [bug#51512] [PATCH v 4]: " david larsson
  0 siblings, 2 replies; 24+ messages in thread
From: david larsson @ 2022-08-27 18:29 UTC (permalink / raw)
  To: 51512; +Cc: Guix-patches

Ping!

On 2022-08-02 22:21, david larsson wrote:
> 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




^ permalink raw reply	[flat|nested] 24+ messages in thread

* [bug#51512] [PATCH v 3]: gnu: Add bash-bcu.
  2022-08-27 18:29         ` david larsson
@ 2023-05-20 19:23           ` david larsson
  2023-05-20 19:28             ` david larsson
  2023-05-20 20:16           ` [bug#51512] [PATCH v 4]: " david larsson
  1 sibling, 1 reply; 24+ messages in thread
From: david larsson @ 2023-05-20 19:23 UTC (permalink / raw)
  To: 51512; +Cc: me

[-- Attachment #1: Type: text/plain, Size: 37 bytes --]

New version with minified JS removed!

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnu-Add-bash-coding-utils.patch --]
[-- Type: text/x-diff; name=0001-gnu-Add-bash-coding-utils.patch, Size: 28941 bytes --]

From c0c966f4e2d5efca44b96bb450e6375963f29621 Mon Sep 17 00:00:00 2001
From: David Larsson <david.larsson@selfhosted.xyz>
Date: Wed, 29 Jun 2022 23:35:50 +0200
Subject: [PATCH] gnu: Add bash-coding-utils

* gnu/packages/bash.scm (guile-bash-for-bash-coding-utils,
 org-html-themes/methuselah-0, pydaemon, bash-coding-utils):
New variables.
* gnu/packages/patches/guile-bash-args-from-stdin.patch: New file.
* gnu/local.mk: Register patch.
---
 gnu/local.mk                                  |   1 +
 gnu/packages/bash.scm                         | 458 +++++++++++++++++-
 .../patches/guile-bash-args-from-stdin.patch  |  42 ++
 3 files changed, 497 insertions(+), 4 deletions(-)
 create mode 100644 gnu/packages/patches/guile-bash-args-from-stdin.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 17b07a1102..865c227bce 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1301,6 +1301,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/guile-1.8-cpp-4.5.patch			\
   %D%/packages/patches/guile-2.2-skip-oom-test.patch            \
   %D%/packages/patches/guile-2.2-skip-so-test.patch             \
+  %D%/packages/patches/guile-bash-args-from-stdin.patch		\
   %D%/packages/patches/guile-default-utf8.patch			\
   %D%/packages/patches/guile-2.2-default-utf8.patch		\
   %D%/packages/patches/guile-relocatable.patch			\
diff --git a/gnu/packages/bash.scm b/gnu/packages/bash.scm
index 43f38303f7..76d2680f00 100644
--- a/gnu/packages/bash.scm
+++ b/gnu/packages/bash.scm
@@ -26,19 +26,36 @@
 (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 bison)
   #:use-module (gnu packages bootstrap)
   #:use-module (gnu packages compression)
+  #:use-module (gnu packages curl)
+  #:use-module (gnu packages dns)
   #:use-module (gnu packages elf)
-  #:use-module (gnu packages ncurses)
-  #:use-module (gnu packages readline)
-  #:use-module (gnu packages bison)
+  #:use-module (gnu packages file)
+  #:use-module (gnu packages freedesktop)
+  #:use-module (gnu packages gawk)
+  #:use-module (gnu packages gtk)
+  #:use-module (gnu packages guile)
+  #:use-module (gnu packages guile-xyz)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages libffi)
+  #:use-module (gnu packages lsof)
+  #:use-module (gnu packages ncurses)
+  #:use-module (gnu packages networking)
+  #: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 guile)
   #:use-module (gnu packages version-control)
   #:use-module (gnu packages less)
+  #:use-module (gnu packages python)
+  #:use-module (gnu packages python-xyz)
+  #:use-module (gnu packages readline)
+  #:use-module (gnu packages web)
+  #:use-module (gnu packages xml)
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix git-download)
@@ -47,6 +64,7 @@ (define-module (gnu packages bash)
   #:use-module (guix monads)
   #:use-module (guix store)
   #:use-module (guix build-system gnu)
+  #:use-module (guix build-system copy)
   #:use-module (guix build-system trivial)
   #:autoload   (guix gnupg) (gnupg-verify*)
   #:autoload   (guix base32) (bytevector->nix-base32-string)
@@ -482,3 +500,435 @@ (define-public blesh
 which replaces the default GNU Readline.  It adds syntax highlighting, auto
 suggestions, vim modes, and more to Bash interactive sessions.")
     (license license:bsd-3)))
+
+(define-public guile-bash-for-bash-coding-utils
+  (let ((commit "1eabc563ca5692b3e08d84f1f0e6fd2283284469")
+        (revision "0"))
+    (package
+      (inherit guile2.0-bash)
+      (version (string-append "0.1.6-" revision "." (string-take commit 7)))
+      (home-page (package-home-page guile2.0-bash))
+      (name "guile-bash-for-bash-coding-utils")
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (commit commit)
+                      (url home-page)))
+                (sha256
+                 (base32
+                  "097vny990wp2qpjij6a5a5gwc6fxzg5wk56inhy18iki5v6pif1p"))
+                (file-name (string-append name "-" version "-checkout"))
+                (patches (search-patches "guile-bash-args-from-stdin.patch"))))
+      (inputs
+       `(("guile" ,guile-3.0-latest)
+         ,@(assoc-remove! (package-inputs guile2.0-bash) "guile")))
+      (propagated-inputs (list bash))
+      (arguments
+       `(#:tests? #f
+         #:phases (modify-phases %standard-phases
+                    (add-after 'install 'install-guile
+                      (lambda* (#:key inputs outputs #:allow-other-keys)
+                        (copy-recursively
+                         (string-append (assoc-ref outputs "out")
+                                        (assoc-ref inputs "guile") "/share")
+                         (string-append (assoc-ref outputs "out") "/share"))
+                      #t)))
+         ,@(package-arguments guile2.0-bash))))))
+
+(define org-html-themes/methuselah-0
+  ;; A form of https://github.com/fniessen/org-html-themes but not
+  ;; drop-in compatible (using that would break the BCU docs).
+  (let ((commit "2889f7b867867dbaf6e059755e1f4e9bc0892332")
+        (revision "0"))
+    (package
+      (name "org-html-themes")
+      (version (git-version "0.0.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (commit commit)
+               (url "https://gitlab.com/methuselah-0/org-html-themes.git")))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 "11zr7k8jqldaf6wx3yshiya7f8ryv4ms4bibghnxyrd45gknbnx9"))))
+      (build-system copy-build-system)
+      (home-page "https://github.com/fniessen/org-html-themes") ; XXX
+      (synopsis "Export Org mode files to HTML")
+      (description
+       "The Org-HMTL framework provides cross-browser themes for exporting Org
+documents to cross-browser HTML mark-up.")
+      (license license:cc-by-sa3.0))))
+
+(define-public pydaemon
+  (let ((commit "dae2798a2c1caa56025c6da69c0d464f70d9c79a")
+        (revision "0"))
+    (package
+      (name "pydaemon")
+      (version (git-version "0.0.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (commit commit)
+               (url "https://gitlab.com/methuselah-0/pydaemon.git")))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 "1cbg48ljyjqw1vxcb0sqhg9cxx0vgs6ggsdg8yvj441s6gakp2sh"))))
+      (build-system trivial-build-system)
+
+      (inputs (list coreutils netcat python socat util-linux))
+      (arguments
+       (list #:modules '((guix build utils))
+             #:builder
+             #~(begin
+                 (use-modules (guix build utils))
+                   (with-directory-excursion #$(package-source this-package)
+                     (mkdir-p (string-append (assoc-ref %outputs "out") "/bin"))
+                     (copy-file "pydaemon.py"
+                                (string-append (assoc-ref %outputs "out") "/bin/pydaemon.py"))
+                     (copy-file "py-net-daemon.py"
+                                (string-append (assoc-ref %outputs "out") "/bin/py-net-daemon.py"))
+                     (copy-file "pydaemon.sh"
+                                (string-append (assoc-ref %outputs "out") "/bin/pydaemon.sh"))
+
+                     (substitute* (find-files (string-append #$output "/bin") "\\.sh$")
+                       (("(flock) " library _)
+                        (string-append #$(this-package-input "util-linux") "/bin/" library))
+                       (("(socat) " library _)
+                        (string-append #$(this-package-input "socat") "/bin/" library))
+                       (("(nc) " library _)
+                        (string-append #$(this-package-input "netcat") "/bin/" library))
+                       (("( )(mkdir|cat|sleep|chown|id|kill|dirname) " all pre command _)
+                        (string-append pre #$(this-package-input "coreutils") "/bin/" command " "))
+                       (("(\\()(mkdir|cat|sleep|chown|id|kill|dirname) " all pre command _)
+                        (string-append pre #$(this-package-input "coreutils") "/bin/" command " "))
+                       (("(python3) " library _)
+                        (string-append #$(file-append (this-package-input "python")
+                                                      "/bin/python"
+                                                      (version-major+minor
+                                                       (package-version
+                                                        (this-package-input
+                                                         "python"))))
+                                       " ")))))))
+      (home-page "https://gitlab.com/methuselah-0/pydaemon")
+      (synopsis "Use python from bash")
+      (description "With pydaemon you can pipe strings of python code to one
+or multiple persistent python processes that keeps state, and get the results
+back as strings.  Can be used over either of a unix or tcp socket.")
+      (license license:cc-by-sa3.0))))
+
+(define-public bash-coding-utils
+  (let ((commit "ce9e7a8910d7debe29a07b48aa0770913b1ecdaf")
+        (revision "0"))
+    (package
+      (name "bash-coding-utils")
+      (version (git-version "0.3.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri
+          (git-reference
+           (commit commit)
+           (url "https://git.sr.ht/~methuselah-0/bash-coding-utils")
+           (recursive? #t))          )
+         (sha256
+          (base32 "0hgj0fy66bj5kbjs02fvjp5n9a5sz32fk45rc3id2bs0b2k9jrnx"))
+         (file-name (git-file-name name version))))
+      (build-system trivial-build-system)
+      (arguments
+       (list #:modules '((guix build utils))
+             #:builder
+             #~(begin
+                 (use-modules (guix build utils)
+                              (ice-9 ftw)
+                              (ice-9 match)
+                              (srfi srfi-26))
+                 (let* ((bash #$(this-package-input "bash"))
+                        (bin (string-append #$output "/bin"))
+                        (bcu.sh (string-append bin "/bcu.sh"))
+                        (share (string-append #$output "/share"))
+                        (doc (string-append share "/doc/" #$name))
+                        ;; Everything but bcu.sh itself is only ever accessed
+                        ;; internally by bcu, so put it all in share/.
+                        (bcu-root (string-append share "/bcu"))
+                        ;; XXX We should honour the without-tests transformation!
+                        (tests? (not #$(%current-target-system))))
+
+                   ;; Copy the ‘source’ to the output and replace submodules.
+                   (let ((source #$(package-source this-package)))
+                     (with-directory-excursion source
+                       (mkdir-p bcu-root)
+                       (for-each (lambda (file)
+                                   (copy-recursively file
+                                                     (string-append bcu-root
+                                                                    "/" file)))
+                                 (list "bcu.sh"
+                                       "dependency_paths.sh"
+                                       "bcu-test.sh"
+                                       "docs"
+                                       "src"))
+                       (copy-recursively (assoc-ref %build-inputs "org-html-themes")
+                                         (string-append bcu-root
+                                                        "/submodules/org-html-themes"))))
+
+                       ;; Moving docs/ out of bcu-root would break symlinks.
+                       (mkdir-p (dirname doc))
+                       (symlink (string-append bcu-root "/docs") doc)))
+
+                   ;; Patch absolute file name references.
+                   (let* ((original-path (getenv "PATH"))
+                          (shebang-inputs '(#$@(map (lambda (name)
+                                                      (this-package-input name))
+                                                    '("guile"
+                                                      "python"))))
+                          (shebang-path (string-join
+                                         (map (cut string-append <> "/bin")
+                                              (cons bash shebang-inputs))
+                                         ":")))
+                     (setenv "PATH" shebang-path)
+                     (for-each patch-shebang
+                               (find-files #$output "\\.(sh|scm|py)$"))
+                     (setenv "PATH" original-path))
+
+                   ;; Add paths to dependencies - defined in
+                   ;; dependency_paths.sh, except the libguile-bash.so
+                   ;; file.
+                   (substitute* (find-files #$output "\\.sh$")
+                     (("[^ ]*(/lib/bash/libguile-bash\\.so)" _ library)
+                      (string-append
+                       #$(this-package-input "guile-bash-for-bash-coding-utils")
+                       library)))
+
+                   (substitute* (find-files #$output "dependency_paths\\.sh$")
+                     (("export BCUCTYPES=(ctypes.sh)" _ library)
+                      (string-append "export BCUCTYPES="
+                                     #$(this-package-input "bash-ctypes")
+                                     "/bin/" library))
+                     (("export BCUDIFF=(diff)" _ library)
+                      (string-append "export BCUDIFF="
+                                     #$(this-package-input "diffutils")
+                                     "/bin/" library))
+                     (("export BCUPING=(ping)" _ library)
+                      (string-append "export BCUPING=/run/setuid-programs/ping"))
+                     (("export BCUPS=(ps)" _ library)
+                      (string-append "export BCUPS="
+                                     #$(this-package-input "procps")
+                                     "/bin/" library))
+                     (("export BCUFILE=(file)" _ library)
+                      (string-append "export BCUFILE="
+                                     #$(this-package-input "findutils")
+                                     "/bin/" library))
+                     (("export BCUFIND=(find)" _ library)
+                      (string-append "export BCUFIND="
+                                     #$(this-package-input "findutils")
+                                     "/bin/" library))
+                     (("export BCUFLOCK=(flock)" _ library)
+                      (string-append "export BCUFLOCK="
+                                     #$(this-package-input "util-linux")
+                                     "/bin/" library))
+                     (("export BCUGAWK=(gawk)" _ library)
+                      (string-append "export BCUGAWK="
+                                     #$(this-package-input "gawk")
+                                     "/bin/" library))
+                     (("export BCUGREP=(grep)" _ library)
+                      (string-append "export BCUGREP="
+                                     #$(this-package-input "grep")
+                                     "/bin/" library))
+                     (("export GUILE_LOAD_PATH=(.*)$")
+                      (string-append "export GUILE_LOAD_PATH=\""
+                                     (string-join
+                                      '(#$@(map (lambda (name)
+                                                  (file-append (this-package-input name)
+                                                               "/share/guile/site/"
+                                                               (version-major+minor
+                                                                (package-version
+                                                                 (this-package-input
+                                                                  "guile")))))
+                                                '("guile-bash-for-bash-coding-utils")))
+                                      ":")
+                                     "${GUILE_LOAD_PATH:+:}${GUILE_LOAD_PATH}\"\n"))
+                     (("export BCUJQ=(jq)" _ library)
+                      (string-append "export BCUJQ="
+                                     #$(this-package-input "jq")
+                                     "/bin/" library))
+                     (("export BCULSOF=(lsof)" _ library)
+                      (string-append "export BCULSOF="
+                                     #$(this-package-input "lsof")
+                                     "/bin/" library))
+                     (("export BCUNMAP=(nmap)" _ library)
+                      (string-append "export BCUNMAP="
+                                     #$(this-package-input "nmap")
+                                     "/bin/" library))
+                     (("export BCUPCREGREP=(pcregrep)" _ library)
+                      (string-append "export BCUPCREGREP="
+                                     (assoc-ref %build-inputs "pcre:bin")
+                                     "/bin/" library))
+                     (("export BCUPERL=(perl)" _ library)
+                      (string-append "export BCUPERL="
+                                     #$(this-package-input "perl")
+                                     "/bin/" library))
+                     (("export BCUPHP=(php)" _ library)
+                      (string-append "export BCUPHP="
+                                     #$(this-package-input "php")
+                                     "/bin/" library))
+                     (("export BCUPS=(ps)" _ library)
+                      (string-append "export BCUPS="
+                                     #$(this-package-input "procps")
+                                     "/bin/" library))
+                     (("export BCUPYDAEMON=(pydaemon.sh)" _ library)
+                      (string-append "export BCUPYDAEMON="
+                                     #$(this-package-input "pydaemon")
+                                     "/bin/" library))
+                     (("export BCUPYTHONVERSION=(.*)$" _)
+                      (string-append "export BCUPYTHONVERSION="
+                                     #$(version-major+minor
+                                        (package-version
+                                         (this-package-input
+                                          "python")))))
+                     (("export BCUPYTHON=python(.*)$" _)
+                      (string-append "export BCUPYTHON="
+                                     #$(file-append (this-package-input "python")
+                                                    "/bin/python"
+                                                    (version-major+minor
+                                                     (package-version
+                                                      (this-package-input
+                                                       "python"))))
+                                     "\n"))
+                     (("export PYTHONPATH=.*" all)
+                      (string-append "export PYTHONPATH=\""
+                                     (string-join
+                                      '(#$@(map (lambda (name)
+                                                  (file-append (this-package-input name)
+                                                               "/lib/python"
+                                                               (version-major+minor
+                                                                (package-version
+                                                                 (this-package-input
+                                                                  "python")))
+                                                               "/site-packages"))
+                                                '("python"
+                                                  "python-elementpath"
+                                                  "python-lxml"
+                                                  "python-netaddr")))
+                                      ":")
+                                     "${PYTHONPATH:+:}${PYTHONPATH}\"\n"))
+                     (("export BCUSED=(sed)" _ library)
+                      (string-append "export BCUSED="
+                                     #$(this-package-input "sed")
+                                     "/bin/" library))
+                     (("export BCUSOCAT=(socat)" _ library)
+                      (string-append "export BCUSOCAT="
+                                     #$(this-package-input "socat")
+                                     "/bin/" library))
+                     (("export BCUTREE=(tree)" _ library)
+                      (string-append "export BCUTREE="
+                                     #$(this-package-input "tree")
+                                     "/bin/" library))
+                     (("export BCUWHICH=(which)" _ library)
+                      (string-append "export BCUWHICH="
+                                     #$(this-package-input "which")
+                                     "/bin/" library))
+                     (("export XDG_DATA_DIRS=(.*)$")
+                      (string-append
+                       "[[ -e /run/current-system/profile/share ]] && "
+                       "export XDG_DATA_DIRS="
+                       "/run/current-system/profile/share"
+                       "${XDG_DATA_DIRS:+:}${XDG_DATA_DIRS}\n"))
+                     (("export BCUXARGS=(xargs)" _ library)
+                      (string-append "export BCUXARGS="
+                                     #$(this-package-input "findutils")
+                                     "/bin/" library))
+                     (("export BCUXDGOPEN=(xdg-open)" _ library)
+                      (string-append "export BCUXDGOPEN="
+                                     #$(this-package-input "xdg-utils")
+                                     "/bin/" library))
+                     (("export BCUXMLLINT=(xmllint)" _ library)
+                      (string-append "export BCUXMLLINT="
+                                     #$(this-package-input "libxml2-xpath0")
+                                     "/bin/" library)))
+
+                   ;; Symlink to bcu.sh from the output bin directory.
+                   (mkdir-p bin)
+                   (symlink (string-append bcu-root "/bcu.sh") bcu.sh)
+                   (chmod bcu.sh #o555)
+
+                   ;; Disable network and gui tests, and one test for setopts which
+                   ;; doesn't work inside the Guix build environment.
+                   (with-output-to-file (string-append bcu-root "/disabled_tests.txt")
+                     (lambda _
+                       (format #t "~{~a~%~}"
+                               (list "ip_of_test_1"
+                                     "setopts_test_4"
+                                     "web_media_server_test_1"
+                                     "web_api_server_test_1"
+                                     "find_gui_test_1"))))
+
+                   ;; Set up a minimal test environment & run the tests.
+                   (when tests?
+                     (setenv "PATH" (string-append bin ":"
+                                                   bash "/bin:"
+                                                   (getenv "PATH")))
+                     (setenv "SHELL"
+                             (string-append bash "/bin/bash"))
+                     (for-each (lambda (test-input)
+                                 (setenv "PATH"
+                                         (string-append
+                                          (assoc-ref %build-inputs test-input)
+                                          "/bin:" (getenv "PATH"))))
+                               (list "coreutils"))
+                     (setenv "HOME" "/tmp")
+                     (with-directory-excursion bcu-root
+                       (invoke "./bcu-test.sh")
+                       ;; No need to keep passed tests in the final output
+                       (for-each delete-file
+                                 (list "bcu-test.sh"
+                                       "disabled_tests.txt"))))))))
+      (native-inputs
+       `( ;; org-html-themes is bundled upstream as a git submodule,
+         ;; but we package it separately and copy it manually above.
+         ("org-html-themes" ,(package-source org-html-themes/methuselah-0))
+         ("coreutils" ,coreutils) ;; Needed for tests.
+         ("pcre:bin" ,pcre "bin")))
+      (inputs (list bash
+                    bash-ctypes
+                    coreutils
+                    diffutils
+                    file
+                    findutils
+                    gawk
+                    grep
+                    guile-3.0
+                    guile-bash-for-bash-coding-utils
+                    jq
+                    libxml2-xpath0
+                    lsof
+                    nmap
+                    perl
+                    php
+                    procps
+                    pydaemon
+                    python
+                    python-elementpath
+                    python-lxml
+                    python-netaddr
+                    python-yq
+                    sed
+                    socat
+                    tree
+                    which
+                    xdg-utils
+                    util-linux))
+      (propagated-inputs
+       `(("bash" ,bash))) ;; the bash shell needs to be the same version
+      ;;as guile-bash is compiled against
+      (home-page "https://git.sr.ht/~methuselah-0/bash-coding-utils")
+      (synopsis "Functions and tools for software prototyping in Bash")
+      (description
+       "Bash-Coding-Utils is a library of Bash functions and wrappers that can
+be useful when writing quick implementations of new programs.  It helps you
+work with JSON, XML, API's and parallelization, and installs some helper
+programs commonly 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))))
diff --git a/gnu/packages/patches/guile-bash-args-from-stdin.patch b/gnu/packages/patches/guile-bash-args-from-stdin.patch
new file mode 100644
index 0000000000..ad42616c70
--- /dev/null
+++ b/gnu/packages/patches/guile-bash-args-from-stdin.patch
@@ -0,0 +1,42 @@
+From a124921666a16cb4e93f59a653f98b99c78eb2ca Mon Sep 17 00:00:00 2001
+From: David Larsson <david.larsson@selfhosted.xyz>
+Date: Thu, 11 Nov 2021 14:07:04 +0100
+Subject: [PATCH] Enable reading arguments from bash via stdin
+
+* lisp/gnu/bash.scm(define-bash-function): read from stdin
+to SCM_ARGS array when it is open, and separate args by null
+instead of newline if -z option is passed as $1.
+---
+ lisp/gnu/bash.scm | 16 ++++++++++++----
+ 1 file changed, 12 insertions(+), 4 deletions(-)
+
+diff --git a/lisp/gnu/bash.scm b/lisp/gnu/bash.scm
+index 199ebc0..e9dcea5 100644
+--- a/lisp/gnu/bash.scm
++++ b/lisp/gnu/bash.scm
+@@ -326,10 +326,18 @@
+       (hashq-set! *funcs* symbol thunk)
+       (unsafe-format/eval
+        "function ~a {
+-            SCM_ARGS=($@)    ;
+-            local retval=$~a ;
+-            unset SCM_ARGS   ;
+-            return $retval   ;
++            local -a Input SCM_ARGS                                          ;
++            [[ ! -t 0 ]] && mapfile -d '' Input                              ;
++            if [[ -n \"${Input[@]}\" ]]; then
++                if [[ \"$1\" == -z ]]; then
++                    local -a SCM_ARGS=\"(${Input[*]@Q})\"                    ;
++                else
++                    mapfile -t SCM_ARGS < <(printf '%s' \"${Input[@]}\"); fi ;
++            else
++                SCM_ARGS=(\"$@\"); fi                                        ;
++            local retval=$~a                                                 ;
++            unset SCM_ARGS                                                   ;
++            return $retval                                                   ;
+        }"
+        symbol special-varname))))
+ 
+-- 
+2.31.0
+
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [bug#51512] [PATCH v 3]: gnu: Add bash-bcu.
  2023-05-20 19:23           ` david larsson
@ 2023-05-20 19:28             ` david larsson
  0 siblings, 0 replies; 24+ messages in thread
From: david larsson @ 2023-05-20 19:28 UTC (permalink / raw)
  To: 51512; +Cc: me

[-- Attachment #1: Type: text/plain, Size: 158 bytes --]

On 2023-05-20 21:23, david larsson wrote:
> New version with minified JS removed!

Sorry, attached the wrong patch earlier. Here is the correct one 
attached.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnu-Add-bash-coding-utils.patch --]
[-- Type: text/x-diff; name=0001-gnu-Add-bash-coding-utils.patch, Size: 28827 bytes --]

From f5e372875e31000a752e230bb3bcbe8e5b03b2c1 Mon Sep 17 00:00:00 2001
From: David Larsson <david.larsson@selfhosted.xyz>
Date: Wed, 29 Jun 2022 23:35:50 +0200
Subject: [PATCH] gnu: Add bash-coding-utils

* gnu/packages/bash.scm (guile-bash-for-bash-coding-utils,
 org-html-themes/methuselah-0, pydaemon, bash-coding-utils):
New variables.
* gnu/packages/patches/guile-bash-args-from-stdin.patch: New file.
* gnu/local.mk: Register patch.
---
 gnu/local.mk                                  |   1 +
 gnu/packages/bash.scm                         | 454 +++++++++++++++++-
 .../patches/guile-bash-args-from-stdin.patch  |  42 ++
 3 files changed, 493 insertions(+), 4 deletions(-)
 create mode 100644 gnu/packages/patches/guile-bash-args-from-stdin.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 17b07a1102..865c227bce 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1301,6 +1301,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/guile-1.8-cpp-4.5.patch			\
   %D%/packages/patches/guile-2.2-skip-oom-test.patch            \
   %D%/packages/patches/guile-2.2-skip-so-test.patch             \
+  %D%/packages/patches/guile-bash-args-from-stdin.patch		\
   %D%/packages/patches/guile-default-utf8.patch			\
   %D%/packages/patches/guile-2.2-default-utf8.patch		\
   %D%/packages/patches/guile-relocatable.patch			\
diff --git a/gnu/packages/bash.scm b/gnu/packages/bash.scm
index 43f38303f7..e4a12d8b3a 100644
--- a/gnu/packages/bash.scm
+++ b/gnu/packages/bash.scm
@@ -26,19 +26,36 @@
 (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 bison)
   #:use-module (gnu packages bootstrap)
   #:use-module (gnu packages compression)
+  #:use-module (gnu packages curl)
+  #:use-module (gnu packages dns)
   #:use-module (gnu packages elf)
-  #:use-module (gnu packages ncurses)
-  #:use-module (gnu packages readline)
-  #:use-module (gnu packages bison)
+  #:use-module (gnu packages file)
+  #:use-module (gnu packages freedesktop)
+  #:use-module (gnu packages gawk)
+  #:use-module (gnu packages gtk)
+  #:use-module (gnu packages guile)
+  #:use-module (gnu packages guile-xyz)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages libffi)
+  #:use-module (gnu packages lsof)
+  #:use-module (gnu packages ncurses)
+  #:use-module (gnu packages networking)
+  #: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 guile)
   #:use-module (gnu packages version-control)
   #:use-module (gnu packages less)
+  #:use-module (gnu packages python)
+  #:use-module (gnu packages python-xyz)
+  #:use-module (gnu packages readline)
+  #:use-module (gnu packages web)
+  #:use-module (gnu packages xml)
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix git-download)
@@ -47,6 +64,7 @@ (define-module (gnu packages bash)
   #:use-module (guix monads)
   #:use-module (guix store)
   #:use-module (guix build-system gnu)
+  #:use-module (guix build-system copy)
   #:use-module (guix build-system trivial)
   #:autoload   (guix gnupg) (gnupg-verify*)
   #:autoload   (guix base32) (bytevector->nix-base32-string)
@@ -482,3 +500,431 @@ (define-public blesh
 which replaces the default GNU Readline.  It adds syntax highlighting, auto
 suggestions, vim modes, and more to Bash interactive sessions.")
     (license license:bsd-3)))
+
+(define-public guile-bash-for-bash-coding-utils
+  (let ((commit "1eabc563ca5692b3e08d84f1f0e6fd2283284469")
+        (revision "0"))
+    (package
+      (inherit guile2.0-bash)
+      (version (string-append "0.1.6-" revision "." (string-take commit 7)))
+      (home-page (package-home-page guile2.0-bash))
+      (name "guile-bash-for-bash-coding-utils")
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (commit commit)
+                      (url home-page)))
+                (sha256
+                 (base32
+                  "097vny990wp2qpjij6a5a5gwc6fxzg5wk56inhy18iki5v6pif1p"))
+                (file-name (string-append name "-" version "-checkout"))
+                (patches (search-patches "guile-bash-args-from-stdin.patch"))))
+      (inputs
+       `(("guile" ,guile-3.0-latest)
+         ,@(assoc-remove! (package-inputs guile2.0-bash) "guile")))
+      (propagated-inputs (list bash))
+      (arguments
+       `(#:tests? #f
+         #:phases (modify-phases %standard-phases
+                    (add-after 'install 'install-guile
+                      (lambda* (#:key inputs outputs #:allow-other-keys)
+                        (copy-recursively
+                         (string-append (assoc-ref outputs "out")
+                                        (assoc-ref inputs "guile") "/share")
+                         (string-append (assoc-ref outputs "out") "/share"))
+                      #t)))
+         ,@(package-arguments guile2.0-bash))))))
+
+(define org-html-themes/methuselah-0
+  ;; A form of https://github.com/fniessen/org-html-themes but not
+  ;; drop-in compatible (using that would break the BCU docs).
+  (let ((commit "2889f7b867867dbaf6e059755e1f4e9bc0892332")
+        (revision "0"))
+    (package
+      (name "org-html-themes")
+      (version (git-version "0.0.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (commit commit)
+               (url "https://gitlab.com/methuselah-0/org-html-themes.git")))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 "11zr7k8jqldaf6wx3yshiya7f8ryv4ms4bibghnxyrd45gknbnx9"))))
+      (build-system copy-build-system)
+      (home-page "https://github.com/fniessen/org-html-themes") ; XXX
+      (synopsis "Export Org mode files to HTML")
+      (description
+       "The Org-HMTL framework provides cross-browser themes for exporting Org
+documents to cross-browser HTML mark-up.")
+      (license license:cc-by-sa3.0))))
+
+(define-public pydaemon
+  (let ((commit "dae2798a2c1caa56025c6da69c0d464f70d9c79a")
+        (revision "0"))
+    (package
+      (name "pydaemon")
+      (version (git-version "0.0.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (commit commit)
+               (url "https://gitlab.com/methuselah-0/pydaemon.git")))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 "1cbg48ljyjqw1vxcb0sqhg9cxx0vgs6ggsdg8yvj441s6gakp2sh"))))
+      (build-system trivial-build-system)
+
+      (inputs (list coreutils netcat python socat util-linux))
+      (arguments
+       (list #:modules '((guix build utils))
+             #:builder
+             #~(begin
+                 (use-modules (guix build utils))
+                   (with-directory-excursion #$(package-source this-package)
+                     (mkdir-p (string-append (assoc-ref %outputs "out") "/bin"))
+                     (copy-file "pydaemon.py"
+                                (string-append (assoc-ref %outputs "out") "/bin/pydaemon.py"))
+                     (copy-file "py-net-daemon.py"
+                                (string-append (assoc-ref %outputs "out") "/bin/py-net-daemon.py"))
+                     (copy-file "pydaemon.sh"
+                                (string-append (assoc-ref %outputs "out") "/bin/pydaemon.sh"))
+
+                     (substitute* (find-files (string-append #$output "/bin") "\\.sh$")
+                       (("(flock) " library _)
+                        (string-append #$(this-package-input "util-linux") "/bin/" library))
+                       (("(socat) " library _)
+                        (string-append #$(this-package-input "socat") "/bin/" library))
+                       (("(nc) " library _)
+                        (string-append #$(this-package-input "netcat") "/bin/" library))
+                       (("( )(mkdir|cat|sleep|chown|id|kill|dirname) " all pre command _)
+                        (string-append pre #$(this-package-input "coreutils") "/bin/" command " "))
+                       (("(\\()(mkdir|cat|sleep|chown|id|kill|dirname) " all pre command _)
+                        (string-append pre #$(this-package-input "coreutils") "/bin/" command " "))
+                       (("(python3) " library _)
+                        (string-append #$(file-append (this-package-input "python")
+                                                      "/bin/python"
+                                                      (version-major+minor
+                                                       (package-version
+                                                        (this-package-input
+                                                         "python"))))
+                                       " ")))))))
+      (home-page "https://gitlab.com/methuselah-0/pydaemon")
+      (synopsis "Use python from bash")
+      (description "With pydaemon you can pipe strings of python code to one
+or multiple persistent python processes that keeps state, and get the results
+back as strings.  Can be used over either of a unix or tcp socket.")
+      (license license:cc-by-sa3.0))))
+
+(define-public bash-coding-utils
+  (let ((commit "ce9e7a8910d7debe29a07b48aa0770913b1ecdaf")
+        (revision "0"))
+    (package
+      (name "bash-coding-utils")
+      (version (git-version "0.3.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri
+          (git-reference
+           (commit commit)
+           (url "https://git.sr.ht/~methuselah-0/bash-coding-utils")
+           (recursive? #t))          )
+         (sha256
+          (base32 "0hgj0fy66bj5kbjs02fvjp5n9a5sz32fk45rc3id2bs0b2k9jrnx"))
+         (file-name (git-file-name name version))))
+      (build-system trivial-build-system)
+      (arguments
+       (list #:modules '((guix build utils))
+             #:builder
+             #~(begin
+                 (use-modules (guix build utils)
+                              (ice-9 ftw)
+                              (ice-9 match)
+                              (srfi srfi-26))
+                 (let* ((bash #$(this-package-input "bash"))
+                        (bin (string-append #$output "/bin"))
+                        (bcu.sh (string-append bin "/bcu.sh"))
+                        (share (string-append #$output "/share"))
+                        (doc (string-append share "/doc/" #$name))
+                        ;; Everything but bcu.sh itself is only ever accessed
+                        ;; internally by bcu, so put it all in share/.
+                        (bcu-root (string-append share "/bcu"))
+                        ;; XXX We should honour the without-tests transformation!
+                        (tests? (not #$(%current-target-system))))
+
+                   ;; Copy the ‘source’ to the output and replace submodules.
+                   (let ((source #$(package-source this-package)))
+                     (with-directory-excursion source
+                       (mkdir-p (string-append bcu-root "/submodules"))
+                       (for-each (lambda (file)
+                                   (copy-recursively file
+                                                     (string-append bcu-root
+                                                                    "/" file)))
+                                 (list "bcu.sh"
+                                       "dependency_paths.sh"
+                                       "bcu-test.sh"
+                                       "docs"
+                                       "src"))
+                       (copy-recursively (assoc-ref %build-inputs "org-html-themes")
+                                         (string-append bcu-root
+                                                        "/submodules/org-html-themes"))))
+                   ;; Patch absolute file name references.
+                   (let* ((original-path (getenv "PATH"))
+                          (shebang-inputs '(#$@(map (lambda (name)
+                                                      (this-package-input name))
+                                                    '("guile"
+                                                      "python"))))
+                          (shebang-path (string-join
+                                         (map (cut string-append <> "/bin")
+                                              (cons bash shebang-inputs))
+                                         ":")))
+                     (setenv "PATH" shebang-path)
+                     (for-each patch-shebang
+                               (find-files #$output "\\.(sh|scm|py)$"))
+                     (setenv "PATH" original-path))
+
+                   ;; Add paths to dependencies - defined in
+                   ;; dependency_paths.sh, except the libguile-bash.so
+                   ;; file.
+                   (substitute* (find-files #$output "\\.sh$")
+                     (("[^ ]*(/lib/bash/libguile-bash\\.so)" _ library)
+                      (string-append
+                       #$(this-package-input "guile-bash-for-bash-coding-utils")
+                       library)))
+
+                   ;; TODO: condense below substitutions?
+                   (substitute* (find-files #$output "dependency_paths\\.sh$")
+                     (("export BCUCTYPES=(ctypes.sh)" _ library)
+                      (string-append "export BCUCTYPES="
+                                     #$(this-package-input "bash-ctypes")
+                                     "/bin/" library))
+                     (("export BCUDIFF=(diff)" _ library)
+                      (string-append "export BCUDIFF="
+                                     #$(this-package-input "diffutils")
+                                     "/bin/" library))
+                     (("export BCUPING=(ping)" _ library)
+                      (string-append "export BCUPING=/run/setuid-programs/ping"))
+                     (("export BCUPS=(ps)" _ library)
+                      (string-append "export BCUPS="
+                                     #$(this-package-input "procps")
+                                     "/bin/" library))
+                     (("export BCUFILE=(file)" _ library)
+                      (string-append "export BCUFILE="
+                                     #$(this-package-input "findutils")
+                                     "/bin/" library))
+                     (("export BCUFIND=(find)" _ library)
+                      (string-append "export BCUFIND="
+                                     #$(this-package-input "findutils")
+                                     "/bin/" library))
+                     (("export BCUFLOCK=(flock)" _ library)
+                      (string-append "export BCUFLOCK="
+                                     #$(this-package-input "util-linux")
+                                     "/bin/" library))
+                     (("export BCUGAWK=(gawk)" _ library)
+                      (string-append "export BCUGAWK="
+                                     #$(this-package-input "gawk")
+                                     "/bin/" library))
+                     (("export BCUGREP=(grep)" _ library)
+                      (string-append "export BCUGREP="
+                                     #$(this-package-input "grep")
+                                     "/bin/" library))
+                     (("export GUILE_LOAD_PATH=(.*)$")
+                      (string-append "export GUILE_LOAD_PATH=\""
+                                     (string-join
+                                      '(#$@(map (lambda (name)
+                                                  (file-append (this-package-input name)
+                                                               "/share/guile/site/"
+                                                               (version-major+minor
+                                                                (package-version
+                                                                 (this-package-input
+                                                                  "guile")))))
+                                                '("guile-bash-for-bash-coding-utils")))
+                                      ":")
+                                     "${GUILE_LOAD_PATH:+:}${GUILE_LOAD_PATH}\"\n"))
+                     (("export BCUJQ=(jq)" _ library)
+                      (string-append "export BCUJQ="
+                                     #$(this-package-input "jq")
+                                     "/bin/" library))
+                     (("export BCULSOF=(lsof)" _ library)
+                      (string-append "export BCULSOF="
+                                     #$(this-package-input "lsof")
+                                     "/bin/" library))
+                     (("export BCUNMAP=(nmap)" _ library)
+                      (string-append "export BCUNMAP="
+                                     #$(this-package-input "nmap")
+                                     "/bin/" library))
+                     (("export BCUPCREGREP=(pcregrep)" _ library)
+                      (string-append "export BCUPCREGREP="
+                                     (assoc-ref %build-inputs "pcre:bin")
+                                     "/bin/" library))
+                     (("export BCUPERL=(perl)" _ library)
+                      (string-append "export BCUPERL="
+                                     #$(this-package-input "perl")
+                                     "/bin/" library))
+                     (("export BCUPHP=(php)" _ library)
+                      (string-append "export BCUPHP="
+                                     #$(this-package-input "php")
+                                     "/bin/" library))
+                     (("export BCUPS=(ps)" _ library)
+                      (string-append "export BCUPS="
+                                     #$(this-package-input "procps")
+                                     "/bin/" library))
+                     (("export BCUPYDAEMON=(pydaemon.sh)" _ library)
+                      (string-append "export BCUPYDAEMON="
+                                     #$(this-package-input "pydaemon")
+                                     "/bin/" library))
+                     (("export BCUPYTHONVERSION=(.*)$" _)
+                      (string-append "export BCUPYTHONVERSION="
+                                     #$(version-major+minor
+                                        (package-version
+                                         (this-package-input
+                                          "python")))))
+                     (("export BCUPYTHON=python(.*)$" _)
+                      (string-append "export BCUPYTHON="
+                                     #$(file-append (this-package-input "python")
+                                                    "/bin/python"
+                                                    (version-major+minor
+                                                     (package-version
+                                                      (this-package-input
+                                                       "python"))))
+                                     "\n"))
+                     (("export PYTHONPATH=.*" all)
+                      (string-append "export PYTHONPATH=\""
+                                     (string-join
+                                      '(#$@(map (lambda (name)
+                                                  (file-append (this-package-input name)
+                                                               "/lib/python"
+                                                               (version-major+minor
+                                                                (package-version
+                                                                 (this-package-input
+                                                                  "python")))
+                                                               "/site-packages"))
+                                                '("python"
+                                                  "python-elementpath"
+                                                  "python-lxml"
+                                                  "python-netaddr")))
+                                      ":")
+                                     "${PYTHONPATH:+:}${PYTHONPATH}\"\n"))
+                     (("export BCUSED=(sed)" _ library)
+                      (string-append "export BCUSED="
+                                     #$(this-package-input "sed")
+                                     "/bin/" library))
+                     (("export BCUSOCAT=(socat)" _ library)
+                      (string-append "export BCUSOCAT="
+                                     #$(this-package-input "socat")
+                                     "/bin/" library))
+                     (("export BCUTREE=(tree)" _ library)
+                      (string-append "export BCUTREE="
+                                     #$(this-package-input "tree")
+                                     "/bin/" library))
+                     (("export BCUWHICH=(which)" _ library)
+                      (string-append "export BCUWHICH="
+                                     #$(this-package-input "which")
+                                     "/bin/" library))
+                     (("export XDG_DATA_DIRS=(.*)$")
+                      (string-append
+                       "[[ -e /run/current-system/profile/share ]] && "
+                       "export XDG_DATA_DIRS="
+                       "/run/current-system/profile/share"
+                       "${XDG_DATA_DIRS:+:}${XDG_DATA_DIRS}\n"))
+                     (("export BCUXARGS=(xargs)" _ library)
+                      (string-append "export BCUXARGS="
+                                     #$(this-package-input "findutils")
+                                     "/bin/" library))
+                     (("export BCUXDGOPEN=(xdg-open)" _ library)
+                      (string-append "export BCUXDGOPEN="
+                                     #$(this-package-input "xdg-utils")
+                                     "/bin/" library))
+                     (("export BCUXMLLINT=(xmllint)" _ library)
+                      (string-append "export BCUXMLLINT="
+                                     #$(this-package-input "libxml2-xpath0")
+                                     "/bin/" library)))
+
+                   ;; Symlink to bcu.sh from the output bin directory.
+                   (mkdir-p bin)
+                   (symlink (string-append bcu-root "/bcu.sh") bcu.sh)
+                   (chmod bcu.sh #o555)
+
+                   ;; Disable network and gui tests, and one test for setopts which
+                   ;; doesn't work inside the Guix build environment.
+                   (with-output-to-file (string-append bcu-root "/disabled_tests.txt")
+                     (lambda _
+                       (format #t "~{~a~%~}"
+                               (list "ip_of_test_1"
+                                     "setopts_test_4"
+                                     "web_media_server_test_1"
+                                     "web_api_server_test_1"
+                                     "find_gui_test_1"))))
+
+                   ;; Set up a minimal test environment & run the tests.
+                   (when tests?
+                     (setenv "PATH" (string-append bin ":"
+                                                   bash "/bin:"
+                                                   (getenv "PATH")))
+                     (setenv "SHELL"
+                             (string-append bash "/bin/bash"))
+                     (for-each (lambda (test-input)
+                                 (setenv "PATH"
+                                         (string-append
+                                          (assoc-ref %build-inputs test-input)
+                                          "/bin:" (getenv "PATH"))))
+                               (list "coreutils"))
+                     (setenv "HOME" "/tmp")
+                     (with-directory-excursion bcu-root
+                       (invoke "./bcu-test.sh")
+                       ;; No need to keep passed tests in the final output
+                       (for-each delete-file
+                                 (list "bcu-test.sh"
+                                       "disabled_tests.txt"))))))))
+      (native-inputs
+       `( ;; org-html-themes is bundled upstream as a git submodule,
+         ;; but we package it separately and copy it manually above.
+         ("org-html-themes" ,(package-source org-html-themes/methuselah-0))
+         ("coreutils" ,coreutils) ;; Needed for tests.
+         ("pcre:bin" ,pcre "bin")))
+      (inputs (list bash
+                    bash-ctypes
+                    coreutils
+                    diffutils
+                    file
+                    findutils
+                    gawk
+                    grep
+                    guile-3.0
+                    guile-bash-for-bash-coding-utils
+                    jq
+                    libxml2-xpath0
+                    lsof
+                    nmap
+                    perl
+                    php
+                    procps
+                    pydaemon
+                    python
+                    python-elementpath
+                    python-lxml
+                    python-netaddr
+                    python-yq
+                    sed
+                    socat
+                    tree
+                    which
+                    xdg-utils
+                    util-linux))
+      (propagated-inputs
+       `(("bash" ,bash))) ;; the bash shell needs to be the same version
+      ;;as guile-bash is compiled against
+      (home-page "https://git.sr.ht/~methuselah-0/bash-coding-utils")
+      (synopsis "Functions and tools for software prototyping in Bash")
+      (description
+       "Bash-Coding-Utils is a library of Bash functions and wrappers that can
+be useful when writing quick implementations of new programs.  It helps you
+work with JSON, XML, API's and parallelization, and installs some helper
+programs commonly 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))))
diff --git a/gnu/packages/patches/guile-bash-args-from-stdin.patch b/gnu/packages/patches/guile-bash-args-from-stdin.patch
new file mode 100644
index 0000000000..ad42616c70
--- /dev/null
+++ b/gnu/packages/patches/guile-bash-args-from-stdin.patch
@@ -0,0 +1,42 @@
+From a124921666a16cb4e93f59a653f98b99c78eb2ca Mon Sep 17 00:00:00 2001
+From: David Larsson <david.larsson@selfhosted.xyz>
+Date: Thu, 11 Nov 2021 14:07:04 +0100
+Subject: [PATCH] Enable reading arguments from bash via stdin
+
+* lisp/gnu/bash.scm(define-bash-function): read from stdin
+to SCM_ARGS array when it is open, and separate args by null
+instead of newline if -z option is passed as $1.
+---
+ lisp/gnu/bash.scm | 16 ++++++++++++----
+ 1 file changed, 12 insertions(+), 4 deletions(-)
+
+diff --git a/lisp/gnu/bash.scm b/lisp/gnu/bash.scm
+index 199ebc0..e9dcea5 100644
+--- a/lisp/gnu/bash.scm
++++ b/lisp/gnu/bash.scm
+@@ -326,10 +326,18 @@
+       (hashq-set! *funcs* symbol thunk)
+       (unsafe-format/eval
+        "function ~a {
+-            SCM_ARGS=($@)    ;
+-            local retval=$~a ;
+-            unset SCM_ARGS   ;
+-            return $retval   ;
++            local -a Input SCM_ARGS                                          ;
++            [[ ! -t 0 ]] && mapfile -d '' Input                              ;
++            if [[ -n \"${Input[@]}\" ]]; then
++                if [[ \"$1\" == -z ]]; then
++                    local -a SCM_ARGS=\"(${Input[*]@Q})\"                    ;
++                else
++                    mapfile -t SCM_ARGS < <(printf '%s' \"${Input[@]}\"); fi ;
++            else
++                SCM_ARGS=(\"$@\"); fi                                        ;
++            local retval=$~a                                                 ;
++            unset SCM_ARGS                                                   ;
++            return $retval                                                   ;
+        }"
+        symbol special-varname))))
+ 
+-- 
+2.31.0
+
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [bug#51512] [PATCH v 4]: gnu: Add bash-bcu.
  2022-08-27 18:29         ` david larsson
  2023-05-20 19:23           ` david larsson
@ 2023-05-20 20:16           ` david larsson
  1 sibling, 0 replies; 24+ messages in thread
From: david larsson @ 2023-05-20 20:16 UTC (permalink / raw)
  To: 51512; +Cc: Guix-patches, me

[-- Attachment #1: Type: text/plain, Size: 40 bytes --]

New version without minified javascript!

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnu-Add-bash-coding-utils.patch --]
[-- Type: text/x-diff; name=0001-gnu-Add-bash-coding-utils.patch, Size: 28827 bytes --]

From f5e372875e31000a752e230bb3bcbe8e5b03b2c1 Mon Sep 17 00:00:00 2001
From: David Larsson <david.larsson@selfhosted.xyz>
Date: Wed, 29 Jun 2022 23:35:50 +0200
Subject: [PATCH] gnu: Add bash-coding-utils

* gnu/packages/bash.scm (guile-bash-for-bash-coding-utils,
 org-html-themes/methuselah-0, pydaemon, bash-coding-utils):
New variables.
* gnu/packages/patches/guile-bash-args-from-stdin.patch: New file.
* gnu/local.mk: Register patch.
---
 gnu/local.mk                                  |   1 +
 gnu/packages/bash.scm                         | 454 +++++++++++++++++-
 .../patches/guile-bash-args-from-stdin.patch  |  42 ++
 3 files changed, 493 insertions(+), 4 deletions(-)
 create mode 100644 gnu/packages/patches/guile-bash-args-from-stdin.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 17b07a1102..865c227bce 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1301,6 +1301,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/guile-1.8-cpp-4.5.patch			\
   %D%/packages/patches/guile-2.2-skip-oom-test.patch            \
   %D%/packages/patches/guile-2.2-skip-so-test.patch             \
+  %D%/packages/patches/guile-bash-args-from-stdin.patch		\
   %D%/packages/patches/guile-default-utf8.patch			\
   %D%/packages/patches/guile-2.2-default-utf8.patch		\
   %D%/packages/patches/guile-relocatable.patch			\
diff --git a/gnu/packages/bash.scm b/gnu/packages/bash.scm
index 43f38303f7..e4a12d8b3a 100644
--- a/gnu/packages/bash.scm
+++ b/gnu/packages/bash.scm
@@ -26,19 +26,36 @@
 (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 bison)
   #:use-module (gnu packages bootstrap)
   #:use-module (gnu packages compression)
+  #:use-module (gnu packages curl)
+  #:use-module (gnu packages dns)
   #:use-module (gnu packages elf)
-  #:use-module (gnu packages ncurses)
-  #:use-module (gnu packages readline)
-  #:use-module (gnu packages bison)
+  #:use-module (gnu packages file)
+  #:use-module (gnu packages freedesktop)
+  #:use-module (gnu packages gawk)
+  #:use-module (gnu packages gtk)
+  #:use-module (gnu packages guile)
+  #:use-module (gnu packages guile-xyz)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages libffi)
+  #:use-module (gnu packages lsof)
+  #:use-module (gnu packages ncurses)
+  #:use-module (gnu packages networking)
+  #: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 guile)
   #:use-module (gnu packages version-control)
   #:use-module (gnu packages less)
+  #:use-module (gnu packages python)
+  #:use-module (gnu packages python-xyz)
+  #:use-module (gnu packages readline)
+  #:use-module (gnu packages web)
+  #:use-module (gnu packages xml)
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix git-download)
@@ -47,6 +64,7 @@ (define-module (gnu packages bash)
   #:use-module (guix monads)
   #:use-module (guix store)
   #:use-module (guix build-system gnu)
+  #:use-module (guix build-system copy)
   #:use-module (guix build-system trivial)
   #:autoload   (guix gnupg) (gnupg-verify*)
   #:autoload   (guix base32) (bytevector->nix-base32-string)
@@ -482,3 +500,431 @@ (define-public blesh
 which replaces the default GNU Readline.  It adds syntax highlighting, auto
 suggestions, vim modes, and more to Bash interactive sessions.")
     (license license:bsd-3)))
+
+(define-public guile-bash-for-bash-coding-utils
+  (let ((commit "1eabc563ca5692b3e08d84f1f0e6fd2283284469")
+        (revision "0"))
+    (package
+      (inherit guile2.0-bash)
+      (version (string-append "0.1.6-" revision "." (string-take commit 7)))
+      (home-page (package-home-page guile2.0-bash))
+      (name "guile-bash-for-bash-coding-utils")
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (commit commit)
+                      (url home-page)))
+                (sha256
+                 (base32
+                  "097vny990wp2qpjij6a5a5gwc6fxzg5wk56inhy18iki5v6pif1p"))
+                (file-name (string-append name "-" version "-checkout"))
+                (patches (search-patches "guile-bash-args-from-stdin.patch"))))
+      (inputs
+       `(("guile" ,guile-3.0-latest)
+         ,@(assoc-remove! (package-inputs guile2.0-bash) "guile")))
+      (propagated-inputs (list bash))
+      (arguments
+       `(#:tests? #f
+         #:phases (modify-phases %standard-phases
+                    (add-after 'install 'install-guile
+                      (lambda* (#:key inputs outputs #:allow-other-keys)
+                        (copy-recursively
+                         (string-append (assoc-ref outputs "out")
+                                        (assoc-ref inputs "guile") "/share")
+                         (string-append (assoc-ref outputs "out") "/share"))
+                      #t)))
+         ,@(package-arguments guile2.0-bash))))))
+
+(define org-html-themes/methuselah-0
+  ;; A form of https://github.com/fniessen/org-html-themes but not
+  ;; drop-in compatible (using that would break the BCU docs).
+  (let ((commit "2889f7b867867dbaf6e059755e1f4e9bc0892332")
+        (revision "0"))
+    (package
+      (name "org-html-themes")
+      (version (git-version "0.0.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (commit commit)
+               (url "https://gitlab.com/methuselah-0/org-html-themes.git")))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 "11zr7k8jqldaf6wx3yshiya7f8ryv4ms4bibghnxyrd45gknbnx9"))))
+      (build-system copy-build-system)
+      (home-page "https://github.com/fniessen/org-html-themes") ; XXX
+      (synopsis "Export Org mode files to HTML")
+      (description
+       "The Org-HMTL framework provides cross-browser themes for exporting Org
+documents to cross-browser HTML mark-up.")
+      (license license:cc-by-sa3.0))))
+
+(define-public pydaemon
+  (let ((commit "dae2798a2c1caa56025c6da69c0d464f70d9c79a")
+        (revision "0"))
+    (package
+      (name "pydaemon")
+      (version (git-version "0.0.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (commit commit)
+               (url "https://gitlab.com/methuselah-0/pydaemon.git")))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 "1cbg48ljyjqw1vxcb0sqhg9cxx0vgs6ggsdg8yvj441s6gakp2sh"))))
+      (build-system trivial-build-system)
+
+      (inputs (list coreutils netcat python socat util-linux))
+      (arguments
+       (list #:modules '((guix build utils))
+             #:builder
+             #~(begin
+                 (use-modules (guix build utils))
+                   (with-directory-excursion #$(package-source this-package)
+                     (mkdir-p (string-append (assoc-ref %outputs "out") "/bin"))
+                     (copy-file "pydaemon.py"
+                                (string-append (assoc-ref %outputs "out") "/bin/pydaemon.py"))
+                     (copy-file "py-net-daemon.py"
+                                (string-append (assoc-ref %outputs "out") "/bin/py-net-daemon.py"))
+                     (copy-file "pydaemon.sh"
+                                (string-append (assoc-ref %outputs "out") "/bin/pydaemon.sh"))
+
+                     (substitute* (find-files (string-append #$output "/bin") "\\.sh$")
+                       (("(flock) " library _)
+                        (string-append #$(this-package-input "util-linux") "/bin/" library))
+                       (("(socat) " library _)
+                        (string-append #$(this-package-input "socat") "/bin/" library))
+                       (("(nc) " library _)
+                        (string-append #$(this-package-input "netcat") "/bin/" library))
+                       (("( )(mkdir|cat|sleep|chown|id|kill|dirname) " all pre command _)
+                        (string-append pre #$(this-package-input "coreutils") "/bin/" command " "))
+                       (("(\\()(mkdir|cat|sleep|chown|id|kill|dirname) " all pre command _)
+                        (string-append pre #$(this-package-input "coreutils") "/bin/" command " "))
+                       (("(python3) " library _)
+                        (string-append #$(file-append (this-package-input "python")
+                                                      "/bin/python"
+                                                      (version-major+minor
+                                                       (package-version
+                                                        (this-package-input
+                                                         "python"))))
+                                       " ")))))))
+      (home-page "https://gitlab.com/methuselah-0/pydaemon")
+      (synopsis "Use python from bash")
+      (description "With pydaemon you can pipe strings of python code to one
+or multiple persistent python processes that keeps state, and get the results
+back as strings.  Can be used over either of a unix or tcp socket.")
+      (license license:cc-by-sa3.0))))
+
+(define-public bash-coding-utils
+  (let ((commit "ce9e7a8910d7debe29a07b48aa0770913b1ecdaf")
+        (revision "0"))
+    (package
+      (name "bash-coding-utils")
+      (version (git-version "0.3.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri
+          (git-reference
+           (commit commit)
+           (url "https://git.sr.ht/~methuselah-0/bash-coding-utils")
+           (recursive? #t))          )
+         (sha256
+          (base32 "0hgj0fy66bj5kbjs02fvjp5n9a5sz32fk45rc3id2bs0b2k9jrnx"))
+         (file-name (git-file-name name version))))
+      (build-system trivial-build-system)
+      (arguments
+       (list #:modules '((guix build utils))
+             #:builder
+             #~(begin
+                 (use-modules (guix build utils)
+                              (ice-9 ftw)
+                              (ice-9 match)
+                              (srfi srfi-26))
+                 (let* ((bash #$(this-package-input "bash"))
+                        (bin (string-append #$output "/bin"))
+                        (bcu.sh (string-append bin "/bcu.sh"))
+                        (share (string-append #$output "/share"))
+                        (doc (string-append share "/doc/" #$name))
+                        ;; Everything but bcu.sh itself is only ever accessed
+                        ;; internally by bcu, so put it all in share/.
+                        (bcu-root (string-append share "/bcu"))
+                        ;; XXX We should honour the without-tests transformation!
+                        (tests? (not #$(%current-target-system))))
+
+                   ;; Copy the ‘source’ to the output and replace submodules.
+                   (let ((source #$(package-source this-package)))
+                     (with-directory-excursion source
+                       (mkdir-p (string-append bcu-root "/submodules"))
+                       (for-each (lambda (file)
+                                   (copy-recursively file
+                                                     (string-append bcu-root
+                                                                    "/" file)))
+                                 (list "bcu.sh"
+                                       "dependency_paths.sh"
+                                       "bcu-test.sh"
+                                       "docs"
+                                       "src"))
+                       (copy-recursively (assoc-ref %build-inputs "org-html-themes")
+                                         (string-append bcu-root
+                                                        "/submodules/org-html-themes"))))
+                   ;; Patch absolute file name references.
+                   (let* ((original-path (getenv "PATH"))
+                          (shebang-inputs '(#$@(map (lambda (name)
+                                                      (this-package-input name))
+                                                    '("guile"
+                                                      "python"))))
+                          (shebang-path (string-join
+                                         (map (cut string-append <> "/bin")
+                                              (cons bash shebang-inputs))
+                                         ":")))
+                     (setenv "PATH" shebang-path)
+                     (for-each patch-shebang
+                               (find-files #$output "\\.(sh|scm|py)$"))
+                     (setenv "PATH" original-path))
+
+                   ;; Add paths to dependencies - defined in
+                   ;; dependency_paths.sh, except the libguile-bash.so
+                   ;; file.
+                   (substitute* (find-files #$output "\\.sh$")
+                     (("[^ ]*(/lib/bash/libguile-bash\\.so)" _ library)
+                      (string-append
+                       #$(this-package-input "guile-bash-for-bash-coding-utils")
+                       library)))
+
+                   ;; TODO: condense below substitutions?
+                   (substitute* (find-files #$output "dependency_paths\\.sh$")
+                     (("export BCUCTYPES=(ctypes.sh)" _ library)
+                      (string-append "export BCUCTYPES="
+                                     #$(this-package-input "bash-ctypes")
+                                     "/bin/" library))
+                     (("export BCUDIFF=(diff)" _ library)
+                      (string-append "export BCUDIFF="
+                                     #$(this-package-input "diffutils")
+                                     "/bin/" library))
+                     (("export BCUPING=(ping)" _ library)
+                      (string-append "export BCUPING=/run/setuid-programs/ping"))
+                     (("export BCUPS=(ps)" _ library)
+                      (string-append "export BCUPS="
+                                     #$(this-package-input "procps")
+                                     "/bin/" library))
+                     (("export BCUFILE=(file)" _ library)
+                      (string-append "export BCUFILE="
+                                     #$(this-package-input "findutils")
+                                     "/bin/" library))
+                     (("export BCUFIND=(find)" _ library)
+                      (string-append "export BCUFIND="
+                                     #$(this-package-input "findutils")
+                                     "/bin/" library))
+                     (("export BCUFLOCK=(flock)" _ library)
+                      (string-append "export BCUFLOCK="
+                                     #$(this-package-input "util-linux")
+                                     "/bin/" library))
+                     (("export BCUGAWK=(gawk)" _ library)
+                      (string-append "export BCUGAWK="
+                                     #$(this-package-input "gawk")
+                                     "/bin/" library))
+                     (("export BCUGREP=(grep)" _ library)
+                      (string-append "export BCUGREP="
+                                     #$(this-package-input "grep")
+                                     "/bin/" library))
+                     (("export GUILE_LOAD_PATH=(.*)$")
+                      (string-append "export GUILE_LOAD_PATH=\""
+                                     (string-join
+                                      '(#$@(map (lambda (name)
+                                                  (file-append (this-package-input name)
+                                                               "/share/guile/site/"
+                                                               (version-major+minor
+                                                                (package-version
+                                                                 (this-package-input
+                                                                  "guile")))))
+                                                '("guile-bash-for-bash-coding-utils")))
+                                      ":")
+                                     "${GUILE_LOAD_PATH:+:}${GUILE_LOAD_PATH}\"\n"))
+                     (("export BCUJQ=(jq)" _ library)
+                      (string-append "export BCUJQ="
+                                     #$(this-package-input "jq")
+                                     "/bin/" library))
+                     (("export BCULSOF=(lsof)" _ library)
+                      (string-append "export BCULSOF="
+                                     #$(this-package-input "lsof")
+                                     "/bin/" library))
+                     (("export BCUNMAP=(nmap)" _ library)
+                      (string-append "export BCUNMAP="
+                                     #$(this-package-input "nmap")
+                                     "/bin/" library))
+                     (("export BCUPCREGREP=(pcregrep)" _ library)
+                      (string-append "export BCUPCREGREP="
+                                     (assoc-ref %build-inputs "pcre:bin")
+                                     "/bin/" library))
+                     (("export BCUPERL=(perl)" _ library)
+                      (string-append "export BCUPERL="
+                                     #$(this-package-input "perl")
+                                     "/bin/" library))
+                     (("export BCUPHP=(php)" _ library)
+                      (string-append "export BCUPHP="
+                                     #$(this-package-input "php")
+                                     "/bin/" library))
+                     (("export BCUPS=(ps)" _ library)
+                      (string-append "export BCUPS="
+                                     #$(this-package-input "procps")
+                                     "/bin/" library))
+                     (("export BCUPYDAEMON=(pydaemon.sh)" _ library)
+                      (string-append "export BCUPYDAEMON="
+                                     #$(this-package-input "pydaemon")
+                                     "/bin/" library))
+                     (("export BCUPYTHONVERSION=(.*)$" _)
+                      (string-append "export BCUPYTHONVERSION="
+                                     #$(version-major+minor
+                                        (package-version
+                                         (this-package-input
+                                          "python")))))
+                     (("export BCUPYTHON=python(.*)$" _)
+                      (string-append "export BCUPYTHON="
+                                     #$(file-append (this-package-input "python")
+                                                    "/bin/python"
+                                                    (version-major+minor
+                                                     (package-version
+                                                      (this-package-input
+                                                       "python"))))
+                                     "\n"))
+                     (("export PYTHONPATH=.*" all)
+                      (string-append "export PYTHONPATH=\""
+                                     (string-join
+                                      '(#$@(map (lambda (name)
+                                                  (file-append (this-package-input name)
+                                                               "/lib/python"
+                                                               (version-major+minor
+                                                                (package-version
+                                                                 (this-package-input
+                                                                  "python")))
+                                                               "/site-packages"))
+                                                '("python"
+                                                  "python-elementpath"
+                                                  "python-lxml"
+                                                  "python-netaddr")))
+                                      ":")
+                                     "${PYTHONPATH:+:}${PYTHONPATH}\"\n"))
+                     (("export BCUSED=(sed)" _ library)
+                      (string-append "export BCUSED="
+                                     #$(this-package-input "sed")
+                                     "/bin/" library))
+                     (("export BCUSOCAT=(socat)" _ library)
+                      (string-append "export BCUSOCAT="
+                                     #$(this-package-input "socat")
+                                     "/bin/" library))
+                     (("export BCUTREE=(tree)" _ library)
+                      (string-append "export BCUTREE="
+                                     #$(this-package-input "tree")
+                                     "/bin/" library))
+                     (("export BCUWHICH=(which)" _ library)
+                      (string-append "export BCUWHICH="
+                                     #$(this-package-input "which")
+                                     "/bin/" library))
+                     (("export XDG_DATA_DIRS=(.*)$")
+                      (string-append
+                       "[[ -e /run/current-system/profile/share ]] && "
+                       "export XDG_DATA_DIRS="
+                       "/run/current-system/profile/share"
+                       "${XDG_DATA_DIRS:+:}${XDG_DATA_DIRS}\n"))
+                     (("export BCUXARGS=(xargs)" _ library)
+                      (string-append "export BCUXARGS="
+                                     #$(this-package-input "findutils")
+                                     "/bin/" library))
+                     (("export BCUXDGOPEN=(xdg-open)" _ library)
+                      (string-append "export BCUXDGOPEN="
+                                     #$(this-package-input "xdg-utils")
+                                     "/bin/" library))
+                     (("export BCUXMLLINT=(xmllint)" _ library)
+                      (string-append "export BCUXMLLINT="
+                                     #$(this-package-input "libxml2-xpath0")
+                                     "/bin/" library)))
+
+                   ;; Symlink to bcu.sh from the output bin directory.
+                   (mkdir-p bin)
+                   (symlink (string-append bcu-root "/bcu.sh") bcu.sh)
+                   (chmod bcu.sh #o555)
+
+                   ;; Disable network and gui tests, and one test for setopts which
+                   ;; doesn't work inside the Guix build environment.
+                   (with-output-to-file (string-append bcu-root "/disabled_tests.txt")
+                     (lambda _
+                       (format #t "~{~a~%~}"
+                               (list "ip_of_test_1"
+                                     "setopts_test_4"
+                                     "web_media_server_test_1"
+                                     "web_api_server_test_1"
+                                     "find_gui_test_1"))))
+
+                   ;; Set up a minimal test environment & run the tests.
+                   (when tests?
+                     (setenv "PATH" (string-append bin ":"
+                                                   bash "/bin:"
+                                                   (getenv "PATH")))
+                     (setenv "SHELL"
+                             (string-append bash "/bin/bash"))
+                     (for-each (lambda (test-input)
+                                 (setenv "PATH"
+                                         (string-append
+                                          (assoc-ref %build-inputs test-input)
+                                          "/bin:" (getenv "PATH"))))
+                               (list "coreutils"))
+                     (setenv "HOME" "/tmp")
+                     (with-directory-excursion bcu-root
+                       (invoke "./bcu-test.sh")
+                       ;; No need to keep passed tests in the final output
+                       (for-each delete-file
+                                 (list "bcu-test.sh"
+                                       "disabled_tests.txt"))))))))
+      (native-inputs
+       `( ;; org-html-themes is bundled upstream as a git submodule,
+         ;; but we package it separately and copy it manually above.
+         ("org-html-themes" ,(package-source org-html-themes/methuselah-0))
+         ("coreutils" ,coreutils) ;; Needed for tests.
+         ("pcre:bin" ,pcre "bin")))
+      (inputs (list bash
+                    bash-ctypes
+                    coreutils
+                    diffutils
+                    file
+                    findutils
+                    gawk
+                    grep
+                    guile-3.0
+                    guile-bash-for-bash-coding-utils
+                    jq
+                    libxml2-xpath0
+                    lsof
+                    nmap
+                    perl
+                    php
+                    procps
+                    pydaemon
+                    python
+                    python-elementpath
+                    python-lxml
+                    python-netaddr
+                    python-yq
+                    sed
+                    socat
+                    tree
+                    which
+                    xdg-utils
+                    util-linux))
+      (propagated-inputs
+       `(("bash" ,bash))) ;; the bash shell needs to be the same version
+      ;;as guile-bash is compiled against
+      (home-page "https://git.sr.ht/~methuselah-0/bash-coding-utils")
+      (synopsis "Functions and tools for software prototyping in Bash")
+      (description
+       "Bash-Coding-Utils is a library of Bash functions and wrappers that can
+be useful when writing quick implementations of new programs.  It helps you
+work with JSON, XML, API's and parallelization, and installs some helper
+programs commonly 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))))
diff --git a/gnu/packages/patches/guile-bash-args-from-stdin.patch b/gnu/packages/patches/guile-bash-args-from-stdin.patch
new file mode 100644
index 0000000000..ad42616c70
--- /dev/null
+++ b/gnu/packages/patches/guile-bash-args-from-stdin.patch
@@ -0,0 +1,42 @@
+From a124921666a16cb4e93f59a653f98b99c78eb2ca Mon Sep 17 00:00:00 2001
+From: David Larsson <david.larsson@selfhosted.xyz>
+Date: Thu, 11 Nov 2021 14:07:04 +0100
+Subject: [PATCH] Enable reading arguments from bash via stdin
+
+* lisp/gnu/bash.scm(define-bash-function): read from stdin
+to SCM_ARGS array when it is open, and separate args by null
+instead of newline if -z option is passed as $1.
+---
+ lisp/gnu/bash.scm | 16 ++++++++++++----
+ 1 file changed, 12 insertions(+), 4 deletions(-)
+
+diff --git a/lisp/gnu/bash.scm b/lisp/gnu/bash.scm
+index 199ebc0..e9dcea5 100644
+--- a/lisp/gnu/bash.scm
++++ b/lisp/gnu/bash.scm
+@@ -326,10 +326,18 @@
+       (hashq-set! *funcs* symbol thunk)
+       (unsafe-format/eval
+        "function ~a {
+-            SCM_ARGS=($@)    ;
+-            local retval=$~a ;
+-            unset SCM_ARGS   ;
+-            return $retval   ;
++            local -a Input SCM_ARGS                                          ;
++            [[ ! -t 0 ]] && mapfile -d '' Input                              ;
++            if [[ -n \"${Input[@]}\" ]]; then
++                if [[ \"$1\" == -z ]]; then
++                    local -a SCM_ARGS=\"(${Input[*]@Q})\"                    ;
++                else
++                    mapfile -t SCM_ARGS < <(printf '%s' \"${Input[@]}\"); fi ;
++            else
++                SCM_ARGS=(\"$@\"); fi                                        ;
++            local retval=$~a                                                 ;
++            unset SCM_ARGS                                                   ;
++            return $retval                                                   ;
+        }"
+        symbol special-varname))))
+ 
+-- 
+2.31.0
+
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [bug#51512] [PATCH v5]: gnu: Add bash-bcu.
  2021-10-30 14:59 [bug#51512] [PATCH]: gnu: Add bash-bcu david larsson
  2021-11-07 12:40 ` Tobias Geerinckx-Rice via Guix-patches via
  2022-07-04 21:11 ` [bug#51512] [PATCH]: gnu: Add bash-bcu ( via Guix-patches via
@ 2023-05-21  6:58 ` david larsson
  2023-05-23  4:51 ` [bug#51512] [PATCH v6 0/3]: " david larsson
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 24+ messages in thread
From: david larsson @ 2023-05-21  6:58 UTC (permalink / raw)
  To: 51512; +Cc: me

[-- Attachment #1: Type: text/plain, Size: 294 bytes --]

On 2021-10-30 16:59, david larsson wrote:
> Hi,
> This patch adds "bash-coding-utils" as the bash-bcu package.
> 
> Best regards,
> David

This new version 5 corrects the licenses (and still no minified 
javascript, and the package is named bash-coding-utils not bash-bcu).

Best regards,
David

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnu-Add-bash-coding-utils.patch --]
[-- Type: text/x-diff; name=0001-gnu-Add-bash-coding-utils.patch, Size: 28807 bytes --]

From 088d60e09f5e0c182052be4bbd970adf72931ff6 Mon Sep 17 00:00:00 2001
From: David Larsson <david.larsson@selfhosted.xyz>
Date: Wed, 29 Jun 2022 23:35:50 +0200
Subject: [PATCH] gnu: Add bash-coding-utils

* gnu/packages/bash.scm (guile-bash-for-bash-coding-utils,
 org-html-themes/methuselah-0, pydaemon, bash-coding-utils):
New variables.
* gnu/packages/patches/guile-bash-args-from-stdin.patch: New file.
* gnu/local.mk: Register patch.
---
 gnu/local.mk                                  |   1 +
 gnu/packages/bash.scm                         | 454 +++++++++++++++++-
 .../patches/guile-bash-args-from-stdin.patch  |  42 ++
 3 files changed, 493 insertions(+), 4 deletions(-)
 create mode 100644 gnu/packages/patches/guile-bash-args-from-stdin.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 17b07a1102..865c227bce 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1301,6 +1301,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/guile-1.8-cpp-4.5.patch			\
   %D%/packages/patches/guile-2.2-skip-oom-test.patch            \
   %D%/packages/patches/guile-2.2-skip-so-test.patch             \
+  %D%/packages/patches/guile-bash-args-from-stdin.patch		\
   %D%/packages/patches/guile-default-utf8.patch			\
   %D%/packages/patches/guile-2.2-default-utf8.patch		\
   %D%/packages/patches/guile-relocatable.patch			\
diff --git a/gnu/packages/bash.scm b/gnu/packages/bash.scm
index 43f38303f7..03dfe8d284 100644
--- a/gnu/packages/bash.scm
+++ b/gnu/packages/bash.scm
@@ -26,19 +26,36 @@
 (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 bison)
   #:use-module (gnu packages bootstrap)
   #:use-module (gnu packages compression)
+  #:use-module (gnu packages curl)
+  #:use-module (gnu packages dns)
   #:use-module (gnu packages elf)
-  #:use-module (gnu packages ncurses)
-  #:use-module (gnu packages readline)
-  #:use-module (gnu packages bison)
+  #:use-module (gnu packages file)
+  #:use-module (gnu packages freedesktop)
+  #:use-module (gnu packages gawk)
+  #:use-module (gnu packages gtk)
+  #:use-module (gnu packages guile)
+  #:use-module (gnu packages guile-xyz)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages libffi)
+  #:use-module (gnu packages lsof)
+  #:use-module (gnu packages ncurses)
+  #:use-module (gnu packages networking)
+  #: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 guile)
   #:use-module (gnu packages version-control)
   #:use-module (gnu packages less)
+  #:use-module (gnu packages python)
+  #:use-module (gnu packages python-xyz)
+  #:use-module (gnu packages readline)
+  #:use-module (gnu packages web)
+  #:use-module (gnu packages xml)
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix git-download)
@@ -47,6 +64,7 @@ (define-module (gnu packages bash)
   #:use-module (guix monads)
   #:use-module (guix store)
   #:use-module (guix build-system gnu)
+  #:use-module (guix build-system copy)
   #:use-module (guix build-system trivial)
   #:autoload   (guix gnupg) (gnupg-verify*)
   #:autoload   (guix base32) (bytevector->nix-base32-string)
@@ -482,3 +500,431 @@ (define-public blesh
 which replaces the default GNU Readline.  It adds syntax highlighting, auto
 suggestions, vim modes, and more to Bash interactive sessions.")
     (license license:bsd-3)))
+
+(define-public guile-bash-for-bash-coding-utils
+  (let ((commit "1eabc563ca5692b3e08d84f1f0e6fd2283284469")
+        (revision "0"))
+    (package
+      (inherit guile2.0-bash)
+      (version (string-append "0.1.6-" revision "." (string-take commit 7)))
+      (home-page (package-home-page guile2.0-bash))
+      (name "guile-bash-for-bash-coding-utils")
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (commit commit)
+                      (url home-page)))
+                (sha256
+                 (base32
+                  "097vny990wp2qpjij6a5a5gwc6fxzg5wk56inhy18iki5v6pif1p"))
+                (file-name (string-append name "-" version "-checkout"))
+                (patches (search-patches "guile-bash-args-from-stdin.patch"))))
+      (inputs
+       `(("guile" ,guile-3.0-latest)
+         ,@(assoc-remove! (package-inputs guile2.0-bash) "guile")))
+      (propagated-inputs (list bash))
+      (arguments
+       `(#:tests? #f
+         #:phases (modify-phases %standard-phases
+                    (add-after 'install 'install-guile
+                      (lambda* (#:key inputs outputs #:allow-other-keys)
+                        (copy-recursively
+                         (string-append (assoc-ref outputs "out")
+                                        (assoc-ref inputs "guile") "/share")
+                         (string-append (assoc-ref outputs "out") "/share"))
+                      #t)))
+         ,@(package-arguments guile2.0-bash))))))
+
+(define org-html-themes/methuselah-0
+  ;; A form of https://github.com/fniessen/org-html-themes but not
+  ;; drop-in compatible (using that would break the BCU docs).
+  (let ((commit "e85bcdb39fd63d992263c7f64272b9a970909f8a")
+        (revision "0"))
+    (package
+      (name "org-html-themes")
+      (version (git-version "0.0.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (commit commit)
+               (url "https://gitlab.com/methuselah-0/org-html-themes.git")))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 "10phgcykpv7nyf3fvvvwf6vz3x4s1x53gzhhknr09f06mdjnkcfg"))))
+      (build-system copy-build-system)
+      (home-page "https://github.com/fniessen/org-html-themes")
+      (synopsis "Export Org mode files to HTML")
+      (description
+       "The Org-HMTL framework provides cross-browser themes for exporting Org
+documents to cross-browser HTML mark-up.")
+      (license license:gpl3))))
+
+(define-public pydaemon
+  (let ((commit "dae2798a2c1caa56025c6da69c0d464f70d9c79a")
+        (revision "0"))
+    (package
+      (name "pydaemon")
+      (version (git-version "0.0.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (commit commit)
+               (url "https://gitlab.com/methuselah-0/pydaemon.git")))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 "1cbg48ljyjqw1vxcb0sqhg9cxx0vgs6ggsdg8yvj441s6gakp2sh"))))
+      (build-system trivial-build-system)
+
+      (inputs (list coreutils netcat python socat util-linux))
+      (arguments
+       (list #:modules '((guix build utils))
+             #:builder
+             #~(begin
+                 (use-modules (guix build utils))
+                   (with-directory-excursion #$(package-source this-package)
+                     (mkdir-p (string-append (assoc-ref %outputs "out") "/bin"))
+                     (copy-file "pydaemon.py"
+                                (string-append (assoc-ref %outputs "out") "/bin/pydaemon.py"))
+                     (copy-file "py-net-daemon.py"
+                                (string-append (assoc-ref %outputs "out") "/bin/py-net-daemon.py"))
+                     (copy-file "pydaemon.sh"
+                                (string-append (assoc-ref %outputs "out") "/bin/pydaemon.sh"))
+
+                     (substitute* (find-files (string-append #$output "/bin") "\\.sh$")
+                       (("(flock) " library _)
+                        (string-append #$(this-package-input "util-linux") "/bin/" library))
+                       (("(socat) " library _)
+                        (string-append #$(this-package-input "socat") "/bin/" library))
+                       (("(nc) " library _)
+                        (string-append #$(this-package-input "netcat") "/bin/" library))
+                       (("( )(mkdir|cat|sleep|chown|id|kill|dirname) " all pre command _)
+                        (string-append pre #$(this-package-input "coreutils") "/bin/" command " "))
+                       (("(\\()(mkdir|cat|sleep|chown|id|kill|dirname) " all pre command _)
+                        (string-append pre #$(this-package-input "coreutils") "/bin/" command " "))
+                       (("(python3) " library _)
+                        (string-append #$(file-append (this-package-input "python")
+                                                      "/bin/python"
+                                                      (version-major+minor
+                                                       (package-version
+                                                        (this-package-input
+                                                         "python"))))
+                                       " ")))))))
+      (home-page "https://gitlab.com/methuselah-0/pydaemon")
+      (synopsis "Use python from bash")
+      (description "With pydaemon you can pipe strings of python code to one
+or multiple persistent python processes that keeps state, and get the results
+back as strings.  Can be used over either of a unix or tcp socket.")
+      (license license:gpl3))))
+
+(define-public bash-coding-utils
+  (let ((commit "ce9e7a8910d7debe29a07b48aa0770913b1ecdaf")
+        (revision "0"))
+    (package
+      (name "bash-coding-utils")
+      (version (git-version "0.3.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri
+          (git-reference
+           (commit commit)
+           (url "https://git.sr.ht/~methuselah-0/bash-coding-utils")
+           (recursive? #t))          )
+         (sha256
+          (base32 "0hgj0fy66bj5kbjs02fvjp5n9a5sz32fk45rc3id2bs0b2k9jrnx"))
+         (file-name (git-file-name name version))))
+      (build-system trivial-build-system)
+      (arguments
+       (list #:modules '((guix build utils))
+             #:builder
+             #~(begin
+                 (use-modules (guix build utils)
+                              (ice-9 ftw)
+                              (ice-9 match)
+                              (srfi srfi-26))
+                 (let* ((bash #$(this-package-input "bash"))
+                        (bin (string-append #$output "/bin"))
+                        (bcu.sh (string-append bin "/bcu.sh"))
+                        (share (string-append #$output "/share"))
+                        (doc (string-append share "/doc/" #$name))
+                        ;; Everything but bcu.sh itself is only ever accessed
+                        ;; internally by bcu, so put it all in share/.
+                        (bcu-root (string-append share "/bcu"))
+                        ;; XXX We should honour the without-tests transformation!
+                        (tests? (not #$(%current-target-system))))
+
+                   ;; Copy the ‘source’ to the output and replace submodules.
+                   (let ((source #$(package-source this-package)))
+                     (with-directory-excursion source
+                       (mkdir-p (string-append bcu-root "/submodules"))
+                       (for-each (lambda (file)
+                                   (copy-recursively file
+                                                     (string-append bcu-root
+                                                                    "/" file)))
+                                 (list "bcu.sh"
+                                       "dependency_paths.sh"
+                                       "bcu-test.sh"
+                                       "docs"
+                                       "src"))
+                       (copy-recursively (assoc-ref %build-inputs "org-html-themes")
+                                         (string-append bcu-root
+                                                        "/submodules/org-html-themes"))))
+                   ;; Patch absolute file name references.
+                   (let* ((original-path (getenv "PATH"))
+                          (shebang-inputs '(#$@(map (lambda (name)
+                                                      (this-package-input name))
+                                                    '("guile"
+                                                      "python"))))
+                          (shebang-path (string-join
+                                         (map (cut string-append <> "/bin")
+                                              (cons bash shebang-inputs))
+                                         ":")))
+                     (setenv "PATH" shebang-path)
+                     (for-each patch-shebang
+                               (find-files #$output "\\.(sh|scm|py)$"))
+                     (setenv "PATH" original-path))
+
+                   ;; Add paths to dependencies - defined in
+                   ;; dependency_paths.sh, except the libguile-bash.so
+                   ;; file.
+                   (substitute* (find-files #$output "\\.sh$")
+                     (("[^ ]*(/lib/bash/libguile-bash\\.so)" _ library)
+                      (string-append
+                       #$(this-package-input "guile-bash-for-bash-coding-utils")
+                       library)))
+
+                   ;; TODO: condense below substitutions?
+                   (substitute* (find-files #$output "dependency_paths\\.sh$")
+                     (("export BCUCTYPES=(ctypes.sh)" _ library)
+                      (string-append "export BCUCTYPES="
+                                     #$(this-package-input "bash-ctypes")
+                                     "/bin/" library))
+                     (("export BCUDIFF=(diff)" _ library)
+                      (string-append "export BCUDIFF="
+                                     #$(this-package-input "diffutils")
+                                     "/bin/" library))
+                     (("export BCUPING=(ping)" _ library)
+                      (string-append "export BCUPING=/run/setuid-programs/ping"))
+                     (("export BCUPS=(ps)" _ library)
+                      (string-append "export BCUPS="
+                                     #$(this-package-input "procps")
+                                     "/bin/" library))
+                     (("export BCUFILE=(file)" _ library)
+                      (string-append "export BCUFILE="
+                                     #$(this-package-input "findutils")
+                                     "/bin/" library))
+                     (("export BCUFIND=(find)" _ library)
+                      (string-append "export BCUFIND="
+                                     #$(this-package-input "findutils")
+                                     "/bin/" library))
+                     (("export BCUFLOCK=(flock)" _ library)
+                      (string-append "export BCUFLOCK="
+                                     #$(this-package-input "util-linux")
+                                     "/bin/" library))
+                     (("export BCUGAWK=(gawk)" _ library)
+                      (string-append "export BCUGAWK="
+                                     #$(this-package-input "gawk")
+                                     "/bin/" library))
+                     (("export BCUGREP=(grep)" _ library)
+                      (string-append "export BCUGREP="
+                                     #$(this-package-input "grep")
+                                     "/bin/" library))
+                     (("export GUILE_LOAD_PATH=(.*)$")
+                      (string-append "export GUILE_LOAD_PATH=\""
+                                     (string-join
+                                      '(#$@(map (lambda (name)
+                                                  (file-append (this-package-input name)
+                                                               "/share/guile/site/"
+                                                               (version-major+minor
+                                                                (package-version
+                                                                 (this-package-input
+                                                                  "guile")))))
+                                                '("guile-bash-for-bash-coding-utils")))
+                                      ":")
+                                     "${GUILE_LOAD_PATH:+:}${GUILE_LOAD_PATH}\"\n"))
+                     (("export BCUJQ=(jq)" _ library)
+                      (string-append "export BCUJQ="
+                                     #$(this-package-input "jq")
+                                     "/bin/" library))
+                     (("export BCULSOF=(lsof)" _ library)
+                      (string-append "export BCULSOF="
+                                     #$(this-package-input "lsof")
+                                     "/bin/" library))
+                     (("export BCUNMAP=(nmap)" _ library)
+                      (string-append "export BCUNMAP="
+                                     #$(this-package-input "nmap")
+                                     "/bin/" library))
+                     (("export BCUPCREGREP=(pcregrep)" _ library)
+                      (string-append "export BCUPCREGREP="
+                                     (assoc-ref %build-inputs "pcre:bin")
+                                     "/bin/" library))
+                     (("export BCUPERL=(perl)" _ library)
+                      (string-append "export BCUPERL="
+                                     #$(this-package-input "perl")
+                                     "/bin/" library))
+                     (("export BCUPHP=(php)" _ library)
+                      (string-append "export BCUPHP="
+                                     #$(this-package-input "php")
+                                     "/bin/" library))
+                     (("export BCUPS=(ps)" _ library)
+                      (string-append "export BCUPS="
+                                     #$(this-package-input "procps")
+                                     "/bin/" library))
+                     (("export BCUPYDAEMON=(pydaemon.sh)" _ library)
+                      (string-append "export BCUPYDAEMON="
+                                     #$(this-package-input "pydaemon")
+                                     "/bin/" library))
+                     (("export BCUPYTHONVERSION=(.*)$" _)
+                      (string-append "export BCUPYTHONVERSION="
+                                     #$(version-major+minor
+                                        (package-version
+                                         (this-package-input
+                                          "python")))))
+                     (("export BCUPYTHON=python(.*)$" _)
+                      (string-append "export BCUPYTHON="
+                                     #$(file-append (this-package-input "python")
+                                                    "/bin/python"
+                                                    (version-major+minor
+                                                     (package-version
+                                                      (this-package-input
+                                                       "python"))))
+                                     "\n"))
+                     (("export PYTHONPATH=.*" all)
+                      (string-append "export PYTHONPATH=\""
+                                     (string-join
+                                      '(#$@(map (lambda (name)
+                                                  (file-append (this-package-input name)
+                                                               "/lib/python"
+                                                               (version-major+minor
+                                                                (package-version
+                                                                 (this-package-input
+                                                                  "python")))
+                                                               "/site-packages"))
+                                                '("python"
+                                                  "python-elementpath"
+                                                  "python-lxml"
+                                                  "python-netaddr")))
+                                      ":")
+                                     "${PYTHONPATH:+:}${PYTHONPATH}\"\n"))
+                     (("export BCUSED=(sed)" _ library)
+                      (string-append "export BCUSED="
+                                     #$(this-package-input "sed")
+                                     "/bin/" library))
+                     (("export BCUSOCAT=(socat)" _ library)
+                      (string-append "export BCUSOCAT="
+                                     #$(this-package-input "socat")
+                                     "/bin/" library))
+                     (("export BCUTREE=(tree)" _ library)
+                      (string-append "export BCUTREE="
+                                     #$(this-package-input "tree")
+                                     "/bin/" library))
+                     (("export BCUWHICH=(which)" _ library)
+                      (string-append "export BCUWHICH="
+                                     #$(this-package-input "which")
+                                     "/bin/" library))
+                     (("export XDG_DATA_DIRS=(.*)$")
+                      (string-append
+                       "[[ -e /run/current-system/profile/share ]] && "
+                       "export XDG_DATA_DIRS="
+                       "/run/current-system/profile/share"
+                       "${XDG_DATA_DIRS:+:}${XDG_DATA_DIRS}\n"))
+                     (("export BCUXARGS=(xargs)" _ library)
+                      (string-append "export BCUXARGS="
+                                     #$(this-package-input "findutils")
+                                     "/bin/" library))
+                     (("export BCUXDGOPEN=(xdg-open)" _ library)
+                      (string-append "export BCUXDGOPEN="
+                                     #$(this-package-input "xdg-utils")
+                                     "/bin/" library))
+                     (("export BCUXMLLINT=(xmllint)" _ library)
+                      (string-append "export BCUXMLLINT="
+                                     #$(this-package-input "libxml2-xpath0")
+                                     "/bin/" library)))
+
+                   ;; Symlink to bcu.sh from the output bin directory.
+                   (mkdir-p bin)
+                   (symlink (string-append bcu-root "/bcu.sh") bcu.sh)
+                   (chmod bcu.sh #o555)
+
+                   ;; Disable network and gui tests, and one test for setopts which
+                   ;; doesn't work inside the Guix build environment.
+                   (with-output-to-file (string-append bcu-root "/disabled_tests.txt")
+                     (lambda _
+                       (format #t "~{~a~%~}"
+                               (list "ip_of_test_1"
+                                     "setopts_test_4"
+                                     "web_media_server_test_1"
+                                     "web_api_server_test_1"
+                                     "find_gui_test_1"))))
+
+                   ;; Set up a minimal test environment & run the tests.
+                   (when tests?
+                     (setenv "PATH" (string-append bin ":"
+                                                   bash "/bin:"
+                                                   (getenv "PATH")))
+                     (setenv "SHELL"
+                             (string-append bash "/bin/bash"))
+                     (for-each (lambda (test-input)
+                                 (setenv "PATH"
+                                         (string-append
+                                          (assoc-ref %build-inputs test-input)
+                                          "/bin:" (getenv "PATH"))))
+                               (list "coreutils"))
+                     (setenv "HOME" "/tmp")
+                     (with-directory-excursion bcu-root
+                       (invoke "./bcu-test.sh")
+                       ;; No need to keep passed tests in the final output
+                       (for-each delete-file
+                                 (list "bcu-test.sh"
+                                       "disabled_tests.txt"))))))))
+      (native-inputs
+       `( ;; org-html-themes is bundled upstream as a git submodule,
+         ;; but we package it separately and copy it manually above.
+         ("org-html-themes" ,(package-source org-html-themes/methuselah-0))
+         ("coreutils" ,coreutils) ;; Needed for tests.
+         ("pcre:bin" ,pcre "bin")))
+      (inputs (list bash
+                    bash-ctypes
+                    coreutils
+                    diffutils
+                    file
+                    findutils
+                    gawk
+                    grep
+                    guile-3.0
+                    guile-bash-for-bash-coding-utils
+                    jq
+                    libxml2-xpath0
+                    lsof
+                    nmap
+                    perl
+                    php
+                    procps
+                    pydaemon
+                    python
+                    python-elementpath
+                    python-lxml
+                    python-netaddr
+                    python-yq
+                    sed
+                    socat
+                    tree
+                    which
+                    xdg-utils
+                    util-linux))
+      (propagated-inputs
+       `(("bash" ,bash))) ;; the bash shell needs to be the same version
+      ;;as guile-bash is compiled against
+      (home-page "https://git.sr.ht/~methuselah-0/bash-coding-utils")
+      (synopsis "Functions and tools for software prototyping in Bash")
+      (description
+       "Bash-Coding-Utils is a library of Bash functions and wrappers that can
+be useful when writing quick implementations of new programs.  It helps you
+work with JSON, XML, API's and parallelization, and installs some helper
+programs commonly 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))))
diff --git a/gnu/packages/patches/guile-bash-args-from-stdin.patch b/gnu/packages/patches/guile-bash-args-from-stdin.patch
new file mode 100644
index 0000000000..ad42616c70
--- /dev/null
+++ b/gnu/packages/patches/guile-bash-args-from-stdin.patch
@@ -0,0 +1,42 @@
+From a124921666a16cb4e93f59a653f98b99c78eb2ca Mon Sep 17 00:00:00 2001
+From: David Larsson <david.larsson@selfhosted.xyz>
+Date: Thu, 11 Nov 2021 14:07:04 +0100
+Subject: [PATCH] Enable reading arguments from bash via stdin
+
+* lisp/gnu/bash.scm(define-bash-function): read from stdin
+to SCM_ARGS array when it is open, and separate args by null
+instead of newline if -z option is passed as $1.
+---
+ lisp/gnu/bash.scm | 16 ++++++++++++----
+ 1 file changed, 12 insertions(+), 4 deletions(-)
+
+diff --git a/lisp/gnu/bash.scm b/lisp/gnu/bash.scm
+index 199ebc0..e9dcea5 100644
+--- a/lisp/gnu/bash.scm
++++ b/lisp/gnu/bash.scm
+@@ -326,10 +326,18 @@
+       (hashq-set! *funcs* symbol thunk)
+       (unsafe-format/eval
+        "function ~a {
+-            SCM_ARGS=($@)    ;
+-            local retval=$~a ;
+-            unset SCM_ARGS   ;
+-            return $retval   ;
++            local -a Input SCM_ARGS                                          ;
++            [[ ! -t 0 ]] && mapfile -d '' Input                              ;
++            if [[ -n \"${Input[@]}\" ]]; then
++                if [[ \"$1\" == -z ]]; then
++                    local -a SCM_ARGS=\"(${Input[*]@Q})\"                    ;
++                else
++                    mapfile -t SCM_ARGS < <(printf '%s' \"${Input[@]}\"); fi ;
++            else
++                SCM_ARGS=(\"$@\"); fi                                        ;
++            local retval=$~a                                                 ;
++            unset SCM_ARGS                                                   ;
++            return $retval                                                   ;
+        }"
+        symbol special-varname))))
+ 
+-- 
+2.31.0
+
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [bug#51512] [PATCH v6 0/3]: gnu: Add bash-bcu.
  2021-10-30 14:59 [bug#51512] [PATCH]: gnu: Add bash-bcu david larsson
                   ` (2 preceding siblings ...)
  2023-05-21  6:58 ` [bug#51512] [PATCH v5]: " david larsson
@ 2023-05-23  4:51 ` david larsson
  2023-05-23  4:53 ` [bug#51512] [PATCH v6 1/3]: " david larsson
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 24+ messages in thread
From: david larsson @ 2023-05-23  4:51 UTC (permalink / raw)
  To: 51512; +Cc: Guix-patches

On 2021-10-30 16:59, david larsson wrote:
> Hi,
> This patch adds "bash-coding-utils" as the bash-bcu package.
> 
> Best regards,
> David

Hi!

Based on review from IRC conversation, this version fixes:
   - uses the new packaging style and some substitute* simplifications.
   - breaks up the new packages to individual commits.
   - more recent upstream commit.

Best regards,
David




^ permalink raw reply	[flat|nested] 24+ messages in thread

* [bug#51512] [PATCH v6 1/3]: gnu: Add bash-bcu.
  2021-10-30 14:59 [bug#51512] [PATCH]: gnu: Add bash-bcu david larsson
                   ` (3 preceding siblings ...)
  2023-05-23  4:51 ` [bug#51512] [PATCH v6 0/3]: " david larsson
@ 2023-05-23  4:53 ` david larsson
  2023-05-23  4:55 ` [bug#51512] [PATCH v6 2/3]: gnu: Add guile-bash-for-bash-coding-utils david larsson
  2023-05-23  4:56 ` [bug#51512] [PATCH v6 3/3]: gnu: Add bash-coding-utils david larsson
  6 siblings, 0 replies; 24+ messages in thread
From: david larsson @ 2023-05-23  4:53 UTC (permalink / raw)
  To: 51512; +Cc: Guix-patches

[-- Attachment #1: Type: text/plain, Size: 5090 bytes --]

 From b0a982abeb698997bd124b56cb2d33f2fdbd5dac Mon Sep 17 00:00:00 2001
 From: David Larsson <david.larsson@selfhosted.xyz>
Date: Tue, 23 May 2023 05:31:06 +0200
Subject: [PATCH 1/3] gnu: Add pydaemon

* gnu/packages/bash.scm (pydaemon): new variable.
---
  gnu/packages/bash.scm | 58 +++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 58 insertions(+)

diff --git a/gnu/packages/bash.scm b/gnu/packages/bash.scm
index 43f38303f7..1650fdeb72 100644
--- a/gnu/packages/bash.scm
+++ b/gnu/packages/bash.scm
@@ -26,16 +26,19 @@
  (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 elf)
    #: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 pkg-config)
+  #:use-module (gnu packages python)
    #:use-module (gnu packages guile)
    #:use-module (gnu packages version-control)
    #:use-module (gnu packages less)
@@ -46,6 +49,7 @@ (define-module (gnu packages bash)
    #:use-module (guix gexp)
    #:use-module (guix monads)
    #:use-module (guix store)
+  #:use-module (guix build-system copy)
    #:use-module (guix build-system gnu)
    #:use-module (guix build-system trivial)
    #:autoload   (guix gnupg) (gnupg-verify*)
@@ -482,3 +486,57 @@ (define-public blesh
  which replaces the default GNU Readline.  It adds syntax highlighting, 
auto
  suggestions, vim modes, and more to Bash interactive sessions.")
      (license license:bsd-3)))
+
+(define-public pydaemon
+  (let ((commit "dae2798a2c1caa56025c6da69c0d464f70d9c79a")
+        (revision "0"))
+    (package
+      (name "pydaemon")
+      (version (git-version "0.0.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (commit commit)
+               (url "https://gitlab.com/methuselah-0/pydaemon.git")))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 
"1cbg48ljyjqw1vxcb0sqhg9cxx0vgs6ggsdg8yvj441s6gakp2sh"))))
+      (build-system trivial-build-system)
+      (arguments
+       (list #:modules '((guix build utils))
+             #:builder
+             #~(begin
+                 (use-modules (guix build utils))
+                   (with-directory-excursion #$(package-source 
this-package)
+                     (mkdir-p (string-append (assoc-ref %outputs "out") 
"/bin"))
+                     (copy-file "pydaemon.py" (string-append (assoc-ref 
%outputs "out")
+                                               "/bin/pydaemon.py"))
+                     (copy-file "py-net-daemon.py" (string-append 
(assoc-ref %outputs "out")
+                                               
"/bin/py-net-daemon.py"))
+                     (copy-file "pydaemon.sh" (string-append (assoc-ref 
%outputs "out")
+                                               "/bin/pydaemon.sh"))
+                     ;; Substitute paths to binaries directly in the 
shell scripts
+                     (substitute* (find-files (string-append #$output 
"/bin") "\\.sh$")
+                       (("flock ") (string-append #$(this-package-input 
"util-linux") "/bin/flock "))
+                       (("socat ") (string-append #$(this-package-input 
"socat") "/bin/socat "))
+                       (("nc ") (string-append #$(this-package-input 
"netcat") "/bin/nc "))
+                       (("( )(mkdir|cat|sleep|chown|id|kill|dirname) " 
all pre command _)
+                        (string-append pre #$(this-package-input 
"coreutils") "/bin/" command " "))
+                       (("(\\()(mkdir|cat|sleep|chown|id|kill|dirname) 
" all pre command _)
+                        (string-append pre #$(this-package-input 
"coreutils") "/bin/" command " "))
+                       (("(python3) " library _)
+                        (string-append #$(file-append 
(this-package-input "python")
+                                                      "/bin/python"
+                                                      
(version-major+minor
+                                                       (package-version
+                                                        
(this-package-input
+                                                         "python"))))
+                                       " ")))))))
+      (inputs (list coreutils netcat python socat util-linux))
+      (synopsis "Use python from bash")
+      (description "With pydaemon you can pipe strings of python code 
to one
+or multiple persistent python processes that keeps state, and get the 
results
+back as strings.  Can be used over either of a unix or tcp socket.")
+      (home-page "https://gitlab.com/methuselah-0/pydaemon")
+      (license license:gpl3))))
--
2.39.1

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnu-Add-pydaemon.patch --]
[-- Type: text/x-diff; name=0001-gnu-Add-pydaemon.patch, Size: 5042 bytes --]

From b0a982abeb698997bd124b56cb2d33f2fdbd5dac Mon Sep 17 00:00:00 2001
From: David Larsson <david.larsson@selfhosted.xyz>
Date: Tue, 23 May 2023 05:31:06 +0200
Subject: [PATCH 1/3] gnu: Add pydaemon

* gnu/packages/bash.scm (pydaemon): new variable.
---
 gnu/packages/bash.scm | 58 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/gnu/packages/bash.scm b/gnu/packages/bash.scm
index 43f38303f7..1650fdeb72 100644
--- a/gnu/packages/bash.scm
+++ b/gnu/packages/bash.scm
@@ -26,16 +26,19 @@
 (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 elf)
   #: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 pkg-config)
+  #:use-module (gnu packages python)
   #:use-module (gnu packages guile)
   #:use-module (gnu packages version-control)
   #:use-module (gnu packages less)
@@ -46,6 +49,7 @@ (define-module (gnu packages bash)
   #:use-module (guix gexp)
   #:use-module (guix monads)
   #:use-module (guix store)
+  #:use-module (guix build-system copy)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system trivial)
   #:autoload   (guix gnupg) (gnupg-verify*)
@@ -482,3 +486,57 @@ (define-public blesh
 which replaces the default GNU Readline.  It adds syntax highlighting, auto
 suggestions, vim modes, and more to Bash interactive sessions.")
     (license license:bsd-3)))
+
+(define-public pydaemon
+  (let ((commit "dae2798a2c1caa56025c6da69c0d464f70d9c79a")
+        (revision "0"))
+    (package
+      (name "pydaemon")
+      (version (git-version "0.0.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (commit commit)
+               (url "https://gitlab.com/methuselah-0/pydaemon.git")))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 "1cbg48ljyjqw1vxcb0sqhg9cxx0vgs6ggsdg8yvj441s6gakp2sh"))))
+      (build-system trivial-build-system)
+      (arguments
+       (list #:modules '((guix build utils))
+             #:builder
+             #~(begin
+                 (use-modules (guix build utils))
+                   (with-directory-excursion #$(package-source this-package)
+                     (mkdir-p (string-append (assoc-ref %outputs "out") "/bin"))
+                     (copy-file "pydaemon.py" (string-append (assoc-ref %outputs "out")
+                                               "/bin/pydaemon.py"))
+                     (copy-file "py-net-daemon.py" (string-append (assoc-ref %outputs "out")
+                                               "/bin/py-net-daemon.py"))
+                     (copy-file "pydaemon.sh" (string-append (assoc-ref %outputs "out")
+                                               "/bin/pydaemon.sh"))
+                     ;; Substitute paths to binaries directly in the shell scripts
+                     (substitute* (find-files (string-append #$output "/bin") "\\.sh$")
+                       (("flock ") (string-append #$(this-package-input "util-linux") "/bin/flock "))
+                       (("socat ") (string-append #$(this-package-input "socat") "/bin/socat "))
+                       (("nc ") (string-append #$(this-package-input "netcat") "/bin/nc "))
+                       (("( )(mkdir|cat|sleep|chown|id|kill|dirname) " all pre command _)
+                        (string-append pre #$(this-package-input "coreutils") "/bin/" command " "))
+                       (("(\\()(mkdir|cat|sleep|chown|id|kill|dirname) " all pre command _)
+                        (string-append pre #$(this-package-input "coreutils") "/bin/" command " "))
+                       (("(python3) " library _)
+                        (string-append #$(file-append (this-package-input "python")
+                                                      "/bin/python"
+                                                      (version-major+minor
+                                                       (package-version
+                                                        (this-package-input
+                                                         "python"))))
+                                       " ")))))))
+      (inputs (list coreutils netcat python socat util-linux))
+      (synopsis "Use python from bash")
+      (description "With pydaemon you can pipe strings of python code to one
+or multiple persistent python processes that keeps state, and get the results
+back as strings.  Can be used over either of a unix or tcp socket.")
+      (home-page "https://gitlab.com/methuselah-0/pydaemon")
+      (license license:gpl3))))
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [bug#51512] [PATCH v6 2/3]: gnu: Add guile-bash-for-bash-coding-utils
  2021-10-30 14:59 [bug#51512] [PATCH]: gnu: Add bash-bcu david larsson
                   ` (4 preceding siblings ...)
  2023-05-23  4:53 ` [bug#51512] [PATCH v6 1/3]: " david larsson
@ 2023-05-23  4:55 ` david larsson
  2023-05-23  4:56 ` [bug#51512] [PATCH v6 3/3]: gnu: Add bash-coding-utils david larsson
  6 siblings, 0 replies; 24+ messages in thread
From: david larsson @ 2023-05-23  4:55 UTC (permalink / raw)
  To: 51512; +Cc: Guix-patches

[-- Attachment #1: Type: text/plain, Size: 5576 bytes --]

 From 7f2df5fd5b6ec44170b44ac74cae554405d939b6 Mon Sep 17 00:00:00 2001
 From: David Larsson <david.larsson@selfhosted.xyz>
Date: Tue, 23 May 2023 05:38:36 +0200
Subject: [PATCH 2/3] gnu: Add guile-bash-for-bash-coding-utils

* gnu/packages/bash.scm (guile-bash-for-bash-coding-utils): New 
variable.
---
  gnu/local.mk                                  |  1 +
  gnu/packages/bash.scm                         | 34 +++++++++++++++
  .../patches/guile-bash-args-from-stdin.patch  | 42 +++++++++++++++++++
  3 files changed, 77 insertions(+)
  create mode 100644 
gnu/packages/patches/guile-bash-args-from-stdin.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index c10fb01bb3..1db38d093c 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1302,6 +1302,7 @@ dist_patch_DATA =						\
    %D%/packages/patches/guile-1.8-cpp-4.5.patch			\
    %D%/packages/patches/guile-2.2-skip-oom-test.patch            \
    %D%/packages/patches/guile-2.2-skip-so-test.patch             \
+  %D%/packages/patches/guile-bash-args-from-stdin.patch		\
    %D%/packages/patches/guile-default-utf8.patch			\
    %D%/packages/patches/guile-2.2-default-utf8.patch		\
    %D%/packages/patches/guile-relocatable.patch			\
diff --git a/gnu/packages/bash.scm b/gnu/packages/bash.scm
index 1650fdeb72..64d6e8d65e 100644
--- a/gnu/packages/bash.scm
+++ b/gnu/packages/bash.scm
@@ -40,6 +40,7 @@ (define-module (gnu packages bash)
    #:use-module (gnu packages pkg-config)
    #:use-module (gnu packages python)
    #:use-module (gnu packages guile)
+  #:use-module (gnu packages guile-xyz)
    #:use-module (gnu packages version-control)
    #:use-module (gnu packages less)
    #:use-module (guix packages)
@@ -540,3 +541,36 @@ (define-public pydaemon
  back as strings.  Can be used over either of a unix or tcp socket.")
        (home-page "https://gitlab.com/methuselah-0/pydaemon")
        (license license:gpl3))))
+
+(define-public guile-bash-for-bash-coding-utils
+  (let ((commit "1eabc563ca5692b3e08d84f1f0e6fd2283284469")
+        (revision "0"))
+    (package
+      (inherit guile2.0-bash)
+      (version (string-append "0.1.6-" revision "." (string-take commit 
7)))
+      (name "guile-bash-for-bash-coding-utils")
+      (home-page (package-home-page guile2.0-bash))
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (commit commit)
+                      (url home-page)))
+                (sha256
+                 (base32
+                  
"097vny990wp2qpjij6a5a5gwc6fxzg5wk56inhy18iki5v6pif1p"))
+                (file-name (string-append name "-" version 
"-checkout"))
+                (patches (search-patches 
"guile-bash-args-from-stdin.patch"))))
+      (arguments (substitute-keyword-arguments (package-arguments 
guile2.0-bash)
+                   ((#:tests? _ #f) #f)
+                   ((#:phases phases #~%standard-phases)
+                    #~(modify-phases #$phases
+                        (add-after 'install 'install-guile
+                          (lambda* (#:key inputs outputs 
#:allow-other-keys)
+                            (copy-recursively
+                             (string-append (assoc-ref outputs "out")
+                                            (assoc-ref inputs "guile") 
"/share")
+                             (string-append (assoc-ref outputs "out") 
"/share"))
+                            #t))))))
+      (inputs (modify-inputs (package-inputs guile2.0-bash)
+                (replace "guile" guile-3.0-latest)))
+      (propagated-inputs (list bash)))))
diff --git a/gnu/packages/patches/guile-bash-args-from-stdin.patch 
b/gnu/packages/patches/guile-bash-args-from-stdin.patch
new file mode 100644
index 0000000000..ad42616c70
--- /dev/null
+++ b/gnu/packages/patches/guile-bash-args-from-stdin.patch
@@ -0,0 +1,42 @@
+From a124921666a16cb4e93f59a653f98b99c78eb2ca Mon Sep 17 00:00:00 2001
+From: David Larsson <david.larsson@selfhosted.xyz>
+Date: Thu, 11 Nov 2021 14:07:04 +0100
+Subject: [PATCH] Enable reading arguments from bash via stdin
+
+* lisp/gnu/bash.scm(define-bash-function): read from stdin
+to SCM_ARGS array when it is open, and separate args by null
+instead of newline if -z option is passed as $1.
+---
+ lisp/gnu/bash.scm | 16 ++++++++++++----
+ 1 file changed, 12 insertions(+), 4 deletions(-)
+
+diff --git a/lisp/gnu/bash.scm b/lisp/gnu/bash.scm
+index 199ebc0..e9dcea5 100644
+--- a/lisp/gnu/bash.scm
++++ b/lisp/gnu/bash.scm
+@@ -326,10 +326,18 @@
+       (hashq-set! *funcs* symbol thunk)
+       (unsafe-format/eval
+        "function ~a {
+-            SCM_ARGS=($@)    ;
+-            local retval=$~a ;
+-            unset SCM_ARGS   ;
+-            return $retval   ;
++            local -a Input SCM_ARGS                                    
       ;
++            [[ ! -t 0 ]] && mapfile -d '' Input                        
       ;
++            if [[ -n \"${Input[@]}\" ]]; then
++                if [[ \"$1\" == -z ]]; then
++                    local -a SCM_ARGS=\"(${Input[*]@Q})\"              
       ;
++                else
++                    mapfile -t SCM_ARGS < <(printf '%s' 
\"${Input[@]}\"); fi ;
++            else
++                SCM_ARGS=(\"$@\"); fi                                  
       ;
++            local retval=$~a                                           
       ;
++            unset SCM_ARGS                                             
       ;
++            return $retval                                             
       ;
+        }"
+        symbol special-varname))))
+
+--
+2.31.0
+
--
2.39.1

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-gnu-Add-guile-bash-for-bash-coding-utils.patch --]
[-- Type: text/x-diff; name=0002-gnu-Add-guile-bash-for-bash-coding-utils.patch, Size: 5533 bytes --]

From 7f2df5fd5b6ec44170b44ac74cae554405d939b6 Mon Sep 17 00:00:00 2001
From: David Larsson <david.larsson@selfhosted.xyz>
Date: Tue, 23 May 2023 05:38:36 +0200
Subject: [PATCH 2/3] gnu: Add guile-bash-for-bash-coding-utils

* gnu/packages/bash.scm (guile-bash-for-bash-coding-utils): New variable.
---
 gnu/local.mk                                  |  1 +
 gnu/packages/bash.scm                         | 34 +++++++++++++++
 .../patches/guile-bash-args-from-stdin.patch  | 42 +++++++++++++++++++
 3 files changed, 77 insertions(+)
 create mode 100644 gnu/packages/patches/guile-bash-args-from-stdin.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index c10fb01bb3..1db38d093c 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1302,6 +1302,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/guile-1.8-cpp-4.5.patch			\
   %D%/packages/patches/guile-2.2-skip-oom-test.patch            \
   %D%/packages/patches/guile-2.2-skip-so-test.patch             \
+  %D%/packages/patches/guile-bash-args-from-stdin.patch		\
   %D%/packages/patches/guile-default-utf8.patch			\
   %D%/packages/patches/guile-2.2-default-utf8.patch		\
   %D%/packages/patches/guile-relocatable.patch			\
diff --git a/gnu/packages/bash.scm b/gnu/packages/bash.scm
index 1650fdeb72..64d6e8d65e 100644
--- a/gnu/packages/bash.scm
+++ b/gnu/packages/bash.scm
@@ -40,6 +40,7 @@ (define-module (gnu packages bash)
   #:use-module (gnu packages pkg-config)
   #:use-module (gnu packages python)
   #:use-module (gnu packages guile)
+  #:use-module (gnu packages guile-xyz)
   #:use-module (gnu packages version-control)
   #:use-module (gnu packages less)
   #:use-module (guix packages)
@@ -540,3 +541,36 @@ (define-public pydaemon
 back as strings.  Can be used over either of a unix or tcp socket.")
       (home-page "https://gitlab.com/methuselah-0/pydaemon")
       (license license:gpl3))))
+
+(define-public guile-bash-for-bash-coding-utils
+  (let ((commit "1eabc563ca5692b3e08d84f1f0e6fd2283284469")
+        (revision "0"))
+    (package
+      (inherit guile2.0-bash)
+      (version (string-append "0.1.6-" revision "." (string-take commit 7)))
+      (name "guile-bash-for-bash-coding-utils")
+      (home-page (package-home-page guile2.0-bash))
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (commit commit)
+                      (url home-page)))
+                (sha256
+                 (base32
+                  "097vny990wp2qpjij6a5a5gwc6fxzg5wk56inhy18iki5v6pif1p"))
+                (file-name (string-append name "-" version "-checkout"))
+                (patches (search-patches "guile-bash-args-from-stdin.patch"))))
+      (arguments (substitute-keyword-arguments (package-arguments guile2.0-bash)
+                   ((#:tests? _ #f) #f)
+                   ((#:phases phases #~%standard-phases)
+                    #~(modify-phases #$phases
+                        (add-after 'install 'install-guile
+                          (lambda* (#:key inputs outputs #:allow-other-keys)
+                            (copy-recursively
+                             (string-append (assoc-ref outputs "out")
+                                            (assoc-ref inputs "guile") "/share")
+                             (string-append (assoc-ref outputs "out") "/share"))
+                            #t))))))
+      (inputs (modify-inputs (package-inputs guile2.0-bash)
+                (replace "guile" guile-3.0-latest)))
+      (propagated-inputs (list bash)))))
diff --git a/gnu/packages/patches/guile-bash-args-from-stdin.patch b/gnu/packages/patches/guile-bash-args-from-stdin.patch
new file mode 100644
index 0000000000..ad42616c70
--- /dev/null
+++ b/gnu/packages/patches/guile-bash-args-from-stdin.patch
@@ -0,0 +1,42 @@
+From a124921666a16cb4e93f59a653f98b99c78eb2ca Mon Sep 17 00:00:00 2001
+From: David Larsson <david.larsson@selfhosted.xyz>
+Date: Thu, 11 Nov 2021 14:07:04 +0100
+Subject: [PATCH] Enable reading arguments from bash via stdin
+
+* lisp/gnu/bash.scm(define-bash-function): read from stdin
+to SCM_ARGS array when it is open, and separate args by null
+instead of newline if -z option is passed as $1.
+---
+ lisp/gnu/bash.scm | 16 ++++++++++++----
+ 1 file changed, 12 insertions(+), 4 deletions(-)
+
+diff --git a/lisp/gnu/bash.scm b/lisp/gnu/bash.scm
+index 199ebc0..e9dcea5 100644
+--- a/lisp/gnu/bash.scm
++++ b/lisp/gnu/bash.scm
+@@ -326,10 +326,18 @@
+       (hashq-set! *funcs* symbol thunk)
+       (unsafe-format/eval
+        "function ~a {
+-            SCM_ARGS=($@)    ;
+-            local retval=$~a ;
+-            unset SCM_ARGS   ;
+-            return $retval   ;
++            local -a Input SCM_ARGS                                          ;
++            [[ ! -t 0 ]] && mapfile -d '' Input                              ;
++            if [[ -n \"${Input[@]}\" ]]; then
++                if [[ \"$1\" == -z ]]; then
++                    local -a SCM_ARGS=\"(${Input[*]@Q})\"                    ;
++                else
++                    mapfile -t SCM_ARGS < <(printf '%s' \"${Input[@]}\"); fi ;
++            else
++                SCM_ARGS=(\"$@\"); fi                                        ;
++            local retval=$~a                                                 ;
++            unset SCM_ARGS                                                   ;
++            return $retval                                                   ;
+        }"
+        symbol special-varname))))
+ 
+-- 
+2.31.0
+
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [bug#51512] [PATCH v6 3/3]: gnu: Add bash-coding-utils
  2021-10-30 14:59 [bug#51512] [PATCH]: gnu: Add bash-bcu david larsson
                   ` (5 preceding siblings ...)
  2023-05-23  4:55 ` [bug#51512] [PATCH v6 2/3]: gnu: Add guile-bash-for-bash-coding-utils david larsson
@ 2023-05-23  4:56 ` david larsson
  6 siblings, 0 replies; 24+ messages in thread
From: david larsson @ 2023-05-23  4:56 UTC (permalink / raw)
  To: 51512; +Cc: Guix-patches

[-- Attachment #1: Type: text/plain, Size: 16680 bytes --]

 From bb7ab11b11058d609a89cad164308b5b52ebadca Mon Sep 17 00:00:00 2001
 From: David Larsson <david.larsson@selfhosted.xyz>
Date: Tue, 23 May 2023 06:42:03 +0200
Subject: [PATCH 3/3] gnu: Add bash-coding-utils

* gnu/packages/bash.scm (bash-coding-utils)
(org-html-themes/methuselah-0): new variables.
---
  gnu/packages/bash.scm | 260 ++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 260 insertions(+)

diff --git a/gnu/packages/bash.scm b/gnu/packages/bash.scm
index 64d6e8d65e..986ec68b3f 100644
--- a/gnu/packages/bash.scm
+++ b/gnu/packages/bash.scm
@@ -31,17 +31,28 @@ (define-module (gnu packages bash)
    #:use-module (gnu packages bootstrap)
    #:use-module (gnu packages compression)
    #:use-module (gnu packages elf)
+  #:use-module (gnu packages file)
+  #:use-module (gnu packages freedesktop)
+  #:use-module (gnu packages gawk)
    #: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 lsof)
+  #: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 search)
    #:use-module (gnu packages version-control)
+  #:use-module (gnu packages web)
+  #:use-module (gnu packages xml)
    #:use-module (gnu packages less)
    #:use-module (guix packages)
    #:use-module (guix download)
@@ -574,3 +585,252 @@ (define-public guile-bash-for-bash-coding-utils
        (inputs (modify-inputs (package-inputs guile2.0-bash)
                  (replace "guile" guile-3.0-latest)))
        (propagated-inputs (list bash)))))
+
+(define org-html-themes/methuselah-0
+  ;; A form of https://github.com/fniessen/org-html-themes but not
+  ;; drop-in compatible (using that would break the BCU docs).
+  (let ((commit "cce6e288649d6555cb74583f3c02a1e4e97fa1f8")
+        (revision "0"))
+    (package
+      (name "org-html-themes")
+      (version (git-version "0.0.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (commit commit)
+               (url 
"https://gitlab.com/methuselah-0/org-html-themes.git")))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 
"1ka40r5a7xc522wc03v3rwfwq3abb8c1h8sr3hw5v1gsws9s18y9"))))
+      (build-system copy-build-system)
+      (home-page "https://gitlab.com/methuselah-0/org-html-themes")
+      (synopsis "Export Org mode files to HTML")
+      (description
+       "The Org-HMTL framework provides cross-browser themes for 
exporting Org
+documents to cross-browser HTML mark-up.")
+      (license license:gpl3))))
+
+(define-public bash-coding-utils
+  (let ((commit "f1f0ed8bc39db2d5a2b6d3c5aca3e5cbadebfb29")
+        (revision "0"))
+    (package
+      (name "bash-coding-utils")
+      (version (git-version "0.3.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri
+          (git-reference
+           (commit commit)
+           (url "https://git.sr.ht/~methuselah-0/bash-coding-utils")
+           (recursive? #t))          )
+         (sha256
+          (base32 
"1vpp91nsp0gyp5n4kkq0cjsndry9wclxrcr5y41fi1g35vw3m3zz"))
+         (file-name (git-file-name name version))))
+      (build-system trivial-build-system)
+      (arguments
+       (list #:modules '((guix build utils))
+             #:builder
+             #~(begin
+                 (use-modules (guix build utils)
+                              (ice-9 ftw)
+                              (ice-9 match)
+                              (srfi srfi-26))
+                 (let* ((bash #$(this-package-input "bash"))
+                        (bin (string-append #$output "/bin"))
+                        (bcu.sh (string-append bin "/bcu.sh"))
+                        (share (string-append #$output "/share"))
+                        (doc (string-append share "/doc/" #$name))
+                        ;; Everything but bcu.sh itself is only ever 
accessed
+                        ;; internally by bcu, so put it all in share/.
+                        (bcu-root (string-append share "/bcu"))
+                        ;; XXX We should honour the without-tests 
transformation!
+                        (tests? (not #$(%current-target-system))))
+
+                   ;; Copy the ‘source’ to the output and replace 
submodules.
+                   (let ((source #$(package-source this-package)))
+                     (with-directory-excursion source
+                       (mkdir-p (string-append bcu-root "/submodules"))
+                       (for-each (lambda (file)
+                                   (copy-recursively file
+                                                     (string-append 
bcu-root
+                                                                    "/" 
file)))
+                                 (list "bcu.sh"
+                                       "dependency_paths.sh"
+                                       "bcu-test.sh"
+                                       "docs"
+                                       "src"))
+                       (copy-recursively
+                        #$(package-source (this-package-input
+                                           "org-html-themes"))
+                        (string-append bcu-root
+                                       
"/submodules/org-html-themes"))))
+                   ;; Patch absolute file name references.
+                   (let* ((original-path (getenv "PATH"))
+                          (shebang-inputs '(#$@(map (lambda (name)
+                                                      
(this-package-input name))
+                                                    '("guile"
+                                                      "python"))))
+                          (shebang-path (string-join
+                                         (map (cut string-append <> 
"/bin")
+                                              (cons bash 
shebang-inputs))
+                                         ":")))
+                     (setenv "PATH" shebang-path)
+                     (for-each patch-shebang
+                               (find-files #$output "\\.(sh|scm|py)$"))
+                     (setenv "PATH" original-path))
+
+                   ;; Add paths to dependencies - defined in
+                   ;; dependency_paths.sh, except the libguile-bash.so
+                   ;; file.
+                   (substitute* (find-files #$output "\\.sh$")
+                     (("[^ ]*(/lib/bash/libguile-bash\\.so)" _ library)
+                      (string-append
+                       #$(this-package-input 
"guile-bash-for-bash-coding-utils")
+                       library)))
+
+                   (substitute* (find-files #$output 
"dependency_paths\\.sh$")
+                     (("=ctypes.sh") (string-append "=" 
#$(this-package-input "bash-ctypes") "/bin/ctypes.sh"))
+                     (("=diff") (string-append "=" 
#$(this-package-input "diffutils") "/bin/diff"))
+                     (("=ping") (string-append "=" 
"/run/setuid-programs/ping"))
+                     (("=ps") (string-append "=" #$(this-package-input 
"procps") "/bin/ps"))
+                     (("=file") (string-append "=" 
#$(this-package-input "findutils") "/bin/file"))
+                     (("=find") (string-append "=" 
#$(this-package-input "findutils") "/bin/find"))
+                     (("=flock") (string-append "=" 
#$(this-package-input "util-linux") "/bin/flock"))
+                     (("=gawk") (string-append "=" 
#$(this-package-input "gawk") "/bin/gawk"))
+                     (("=ugrep") (string-append "=" 
#$(this-package-input "ugrep") "/bin/ugrep"))
+                     (("=jq") (string-append "=" #$(this-package-input 
"jq") "/bin/jq"))
+                     (("=lsof") (string-append "=" 
#$(this-package-input "lsof") "/bin/lsof"))
+                     (("=nmap") (string-append "=" 
#$(this-package-input "nmap") "/bin/nmap"))
+                     (("=perl") (string-append "=" 
#$(this-package-input "perl") "/bin/perl"))
+                     (("=php") (string-append "=" #$(this-package-input 
"php") "/bin/php"))
+                     (("=ps") (string-append "=" #$(this-package-input 
"procps") "/bin/ps"))
+                     (("=pydaemon.sh") (string-append "=" 
#$(this-package-input "pydaemon") "/bin/pydaemon.sh"))
+                     (("=sed") (string-append "=" #$(this-package-input 
"sed") "/bin/sed"))
+                     (("=socat") (string-append "=" 
#$(this-package-input "socat") "/bin/socat"))
+                     (("=tree") (string-append "=" 
#$(this-package-input "tree") "/bin/tree"))
+                     (("=pcre2grep") (string-append "=" 
#$(this-package-input "pcre2") "/bin/pcre2grep"))
+                     (("=which") (string-append "=" 
#$(this-package-input "which") "/bin/which"))
+                     (("=xargs") (string-append "=" 
#$(this-package-input "findutils") "/bin/xargs"))
+                     (("=xdg-open") (string-append "=" 
#$(this-package-input "xdg-utils") "/bin/xdg-open"))
+                     (("=xmllint") (string-append "=" 
#$(this-package-input "libxml2-xpath0") "/bin/xmllint"))
+                     (("export GUILE_LOAD_PATH=(.*)$")
+                      (string-append "export GUILE_LOAD_PATH=\""
+                                     (string-join
+                                      '(#$@(map (lambda (name)
+                                                  (file-append 
(this-package-input name)
+                                                               
"/share/guile/site/"
+                                                               
(version-major+minor
+                                                                
(package-version
+                                                                 
(this-package-input
+                                                                  
"guile")))))
+                                                
'("guile-bash-for-bash-coding-utils")))
+                                      ":")
+                                     
"${GUILE_LOAD_PATH:+:}${GUILE_LOAD_PATH}\"\n"))
+                     (("export BCUPYTHONVERSION=(.*)$" _)
+                      (string-append "export BCUPYTHONVERSION="
+                                     #$(version-major+minor
+                                        (package-version
+                                         (this-package-input
+                                          "python")))))
+                     (("export BCUPYTHON=python(.*)$" _)
+                      (string-append "export BCUPYTHON="
+                                     #$(file-append (this-package-input 
"python")
+                                                    "/bin/python"
+                                                    
(version-major+minor
+                                                     (package-version
+                                                      
(this-package-input
+                                                       "python"))))
+                                     "\n"))
+                     (("export PYTHONPATH=.*" all)
+                      (string-append "export PYTHONPATH=\""
+                                     (string-join
+                                      '(#$@(map (lambda (name)
+                                                  (file-append 
(this-package-input name)
+                                                               
"/lib/python"
+                                                               
(version-major+minor
+                                                                
(package-version
+                                                                 
(this-package-input
+                                                                  
"python")))
+                                                               
"/site-packages"))
+                                                '("python"
+                                                  "python-elementpath"
+                                                  "python-lxml"
+                                                  "python-netaddr")))
+                                      ":")
+                                     
"${PYTHONPATH:+:}${PYTHONPATH}\"\n"))
+                     (("export XDG_DATA_DIRS=(.*)$")
+                      (string-append
+                       "[[ -e /run/current-system/profile/share ]] && "
+                       "export XDG_DATA_DIRS="
+                       "/run/current-system/profile/share"
+                       "${XDG_DATA_DIRS:+:}${XDG_DATA_DIRS}\n")))
+
+                   ;; Symlink to bcu.sh from the output bin directory.
+                   (mkdir-p bin)
+                   (symlink (string-append bcu-root "/bcu.sh") bcu.sh)
+                   (chmod bcu.sh #o555)
+
+                   ;; Disable network and gui tests, and one test for 
setopts which
+                   ;; doesn't work inside the Guix build environment.
+                   (with-output-to-file (string-append bcu-root 
"/disabled_tests.txt")
+                     (lambda _
+                       (format #t "~{~a~%~}"
+                               (list "ip_of_test_1"
+                                     "setopts_test_4"
+                                     "web_media_server_test_1"
+                                     "web_api_server_test_1"
+                                     "find_gui_test_1"))))
+
+                   ;; Set up a minimal test environment & run the 
tests.
+                   (when tests?
+                     (setenv "PATH" (string-append bin ":"
+                                                   bash "/bin:"
+                                                   (getenv "PATH")))
+                     (setenv "SHELL"
+                             (string-append bash "/bin/bash"))
+                     (for-each (lambda (test-input)
+                                 (setenv "PATH"
+                                         (string-append
+                                          (assoc-ref %build-inputs 
test-input)
+                                          "/bin:" (getenv "PATH"))))
+                               (list "coreutils"))
+                     (setenv "HOME" "/tmp")
+                     (with-directory-excursion bcu-root
+                       (invoke "./bcu-test.sh")
+                       ;; No need to keep passed tests in the final 
output
+                       (for-each delete-file
+                                 (list "bcu-test.sh"
+                                       "disabled_tests.txt"))))))))
+      (inputs (list bash bash-ctypes coreutils
+                    diffutils file findutils
+                    gawk guile-3.0 guile-bash-for-bash-coding-utils
+                    jq libxml2-xpath0
+                    lsof
+                    nmap
+                    ;; org-html-themes is bundled upstream as a git 
submodule,
+                    ;; but we package it separately and copy it 
manually above.
+                    org-html-themes/methuselah-0
+                    pcre2 perl php
+                    procps
+                    pydaemon python python-elementpath python-lxml
+                    python-netaddr python-yq
+                    sed
+                    socat
+                    tree ugrep util-linux which
+                    xdg-utils ))
+      ;; the bash shell needs to be the same version
+      ;; as guile-bash is compiled against
+      (propagated-inputs (list bash))
+      (home-page "https://git.sr.ht/~methuselah-0/bash-coding-utils")
+      (synopsis "Functions and tools for software prototyping in Bash")
+      (description
+       "Bash-Coding-Utils is a library of Bash functions and wrappers 
that can
+be useful when writing quick implementations of new programs.  It helps 
you
+work with JSON, XML, API's and parallelization, and installs some 
helper
+programs commonly 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.39.1

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0003-gnu-Add-bash-coding-utils.patch --]
[-- Type: text/x-diff; name=0003-gnu-Add-bash-coding-utils.patch, Size: 16587 bytes --]

From bb7ab11b11058d609a89cad164308b5b52ebadca Mon Sep 17 00:00:00 2001
From: David Larsson <david.larsson@selfhosted.xyz>
Date: Tue, 23 May 2023 06:42:03 +0200
Subject: [PATCH 3/3] gnu: Add bash-coding-utils

* gnu/packages/bash.scm (bash-coding-utils)
(org-html-themes/methuselah-0): new variables.
---
 gnu/packages/bash.scm | 260 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 260 insertions(+)

diff --git a/gnu/packages/bash.scm b/gnu/packages/bash.scm
index 64d6e8d65e..986ec68b3f 100644
--- a/gnu/packages/bash.scm
+++ b/gnu/packages/bash.scm
@@ -31,17 +31,28 @@ (define-module (gnu packages bash)
   #:use-module (gnu packages bootstrap)
   #:use-module (gnu packages compression)
   #:use-module (gnu packages elf)
+  #:use-module (gnu packages file)
+  #:use-module (gnu packages freedesktop)
+  #:use-module (gnu packages gawk)
   #: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 lsof)
+  #: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 search)
   #:use-module (gnu packages version-control)
+  #:use-module (gnu packages web)
+  #:use-module (gnu packages xml)
   #:use-module (gnu packages less)
   #:use-module (guix packages)
   #:use-module (guix download)
@@ -574,3 +585,252 @@ (define-public guile-bash-for-bash-coding-utils
       (inputs (modify-inputs (package-inputs guile2.0-bash)
                 (replace "guile" guile-3.0-latest)))
       (propagated-inputs (list bash)))))
+
+(define org-html-themes/methuselah-0
+  ;; A form of https://github.com/fniessen/org-html-themes but not
+  ;; drop-in compatible (using that would break the BCU docs).
+  (let ((commit "cce6e288649d6555cb74583f3c02a1e4e97fa1f8")
+        (revision "0"))
+    (package
+      (name "org-html-themes")
+      (version (git-version "0.0.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (commit commit)
+               (url "https://gitlab.com/methuselah-0/org-html-themes.git")))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 "1ka40r5a7xc522wc03v3rwfwq3abb8c1h8sr3hw5v1gsws9s18y9"))))
+      (build-system copy-build-system)
+      (home-page "https://gitlab.com/methuselah-0/org-html-themes")
+      (synopsis "Export Org mode files to HTML")
+      (description
+       "The Org-HMTL framework provides cross-browser themes for exporting Org
+documents to cross-browser HTML mark-up.")
+      (license license:gpl3))))
+
+(define-public bash-coding-utils
+  (let ((commit "f1f0ed8bc39db2d5a2b6d3c5aca3e5cbadebfb29")
+        (revision "0"))
+    (package
+      (name "bash-coding-utils")
+      (version (git-version "0.3.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri
+          (git-reference
+           (commit commit)
+           (url "https://git.sr.ht/~methuselah-0/bash-coding-utils")
+           (recursive? #t))          )
+         (sha256
+          (base32 "1vpp91nsp0gyp5n4kkq0cjsndry9wclxrcr5y41fi1g35vw3m3zz"))
+         (file-name (git-file-name name version))))
+      (build-system trivial-build-system)
+      (arguments
+       (list #:modules '((guix build utils))
+             #:builder
+             #~(begin
+                 (use-modules (guix build utils)
+                              (ice-9 ftw)
+                              (ice-9 match)
+                              (srfi srfi-26))
+                 (let* ((bash #$(this-package-input "bash"))
+                        (bin (string-append #$output "/bin"))
+                        (bcu.sh (string-append bin "/bcu.sh"))
+                        (share (string-append #$output "/share"))
+                        (doc (string-append share "/doc/" #$name))
+                        ;; Everything but bcu.sh itself is only ever accessed
+                        ;; internally by bcu, so put it all in share/.
+                        (bcu-root (string-append share "/bcu"))
+                        ;; XXX We should honour the without-tests transformation!
+                        (tests? (not #$(%current-target-system))))
+
+                   ;; Copy the ‘source’ to the output and replace submodules.
+                   (let ((source #$(package-source this-package)))
+                     (with-directory-excursion source
+                       (mkdir-p (string-append bcu-root "/submodules"))
+                       (for-each (lambda (file)
+                                   (copy-recursively file
+                                                     (string-append bcu-root
+                                                                    "/" file)))
+                                 (list "bcu.sh"
+                                       "dependency_paths.sh"
+                                       "bcu-test.sh"
+                                       "docs"
+                                       "src"))
+                       (copy-recursively
+                        #$(package-source (this-package-input
+                                           "org-html-themes"))
+                        (string-append bcu-root
+                                       "/submodules/org-html-themes"))))
+                   ;; Patch absolute file name references.
+                   (let* ((original-path (getenv "PATH"))
+                          (shebang-inputs '(#$@(map (lambda (name)
+                                                      (this-package-input name))
+                                                    '("guile"
+                                                      "python"))))
+                          (shebang-path (string-join
+                                         (map (cut string-append <> "/bin")
+                                              (cons bash shebang-inputs))
+                                         ":")))
+                     (setenv "PATH" shebang-path)
+                     (for-each patch-shebang
+                               (find-files #$output "\\.(sh|scm|py)$"))
+                     (setenv "PATH" original-path))
+
+                   ;; Add paths to dependencies - defined in
+                   ;; dependency_paths.sh, except the libguile-bash.so
+                   ;; file.
+                   (substitute* (find-files #$output "\\.sh$")
+                     (("[^ ]*(/lib/bash/libguile-bash\\.so)" _ library)
+                      (string-append
+                       #$(this-package-input "guile-bash-for-bash-coding-utils")
+                       library)))
+
+                   (substitute* (find-files #$output "dependency_paths\\.sh$")
+                     (("=ctypes.sh") (string-append "=" #$(this-package-input "bash-ctypes") "/bin/ctypes.sh"))
+                     (("=diff") (string-append "=" #$(this-package-input "diffutils") "/bin/diff"))
+                     (("=ping") (string-append "=" "/run/setuid-programs/ping"))
+                     (("=ps") (string-append "=" #$(this-package-input "procps") "/bin/ps"))
+                     (("=file") (string-append "=" #$(this-package-input "findutils") "/bin/file"))
+                     (("=find") (string-append "=" #$(this-package-input "findutils") "/bin/find"))
+                     (("=flock") (string-append "=" #$(this-package-input "util-linux") "/bin/flock"))
+                     (("=gawk") (string-append "=" #$(this-package-input "gawk") "/bin/gawk"))
+                     (("=ugrep") (string-append "=" #$(this-package-input "ugrep") "/bin/ugrep"))
+                     (("=jq") (string-append "=" #$(this-package-input "jq") "/bin/jq"))
+                     (("=lsof") (string-append "=" #$(this-package-input "lsof") "/bin/lsof"))
+                     (("=nmap") (string-append "=" #$(this-package-input "nmap") "/bin/nmap"))
+                     (("=perl") (string-append "=" #$(this-package-input "perl") "/bin/perl"))
+                     (("=php") (string-append "=" #$(this-package-input "php") "/bin/php"))
+                     (("=ps") (string-append "=" #$(this-package-input "procps") "/bin/ps"))
+                     (("=pydaemon.sh") (string-append "=" #$(this-package-input "pydaemon") "/bin/pydaemon.sh"))
+                     (("=sed") (string-append "=" #$(this-package-input "sed") "/bin/sed"))
+                     (("=socat") (string-append "=" #$(this-package-input "socat") "/bin/socat"))
+                     (("=tree") (string-append "=" #$(this-package-input "tree") "/bin/tree"))
+                     (("=pcre2grep") (string-append "=" #$(this-package-input "pcre2") "/bin/pcre2grep"))
+                     (("=which") (string-append "=" #$(this-package-input "which") "/bin/which"))
+                     (("=xargs") (string-append "=" #$(this-package-input "findutils") "/bin/xargs"))
+                     (("=xdg-open") (string-append "=" #$(this-package-input "xdg-utils") "/bin/xdg-open"))
+                     (("=xmllint") (string-append "=" #$(this-package-input "libxml2-xpath0") "/bin/xmllint"))
+                     (("export GUILE_LOAD_PATH=(.*)$")
+                      (string-append "export GUILE_LOAD_PATH=\""
+                                     (string-join
+                                      '(#$@(map (lambda (name)
+                                                  (file-append (this-package-input name)
+                                                               "/share/guile/site/"
+                                                               (version-major+minor
+                                                                (package-version
+                                                                 (this-package-input
+                                                                  "guile")))))
+                                                '("guile-bash-for-bash-coding-utils")))
+                                      ":")
+                                     "${GUILE_LOAD_PATH:+:}${GUILE_LOAD_PATH}\"\n"))
+                     (("export BCUPYTHONVERSION=(.*)$" _)
+                      (string-append "export BCUPYTHONVERSION="
+                                     #$(version-major+minor
+                                        (package-version
+                                         (this-package-input
+                                          "python")))))
+                     (("export BCUPYTHON=python(.*)$" _)
+                      (string-append "export BCUPYTHON="
+                                     #$(file-append (this-package-input "python")
+                                                    "/bin/python"
+                                                    (version-major+minor
+                                                     (package-version
+                                                      (this-package-input
+                                                       "python"))))
+                                     "\n"))
+                     (("export PYTHONPATH=.*" all)
+                      (string-append "export PYTHONPATH=\""
+                                     (string-join
+                                      '(#$@(map (lambda (name)
+                                                  (file-append (this-package-input name)
+                                                               "/lib/python"
+                                                               (version-major+minor
+                                                                (package-version
+                                                                 (this-package-input
+                                                                  "python")))
+                                                               "/site-packages"))
+                                                '("python"
+                                                  "python-elementpath"
+                                                  "python-lxml"
+                                                  "python-netaddr")))
+                                      ":")
+                                     "${PYTHONPATH:+:}${PYTHONPATH}\"\n"))
+                     (("export XDG_DATA_DIRS=(.*)$")
+                      (string-append
+                       "[[ -e /run/current-system/profile/share ]] && "
+                       "export XDG_DATA_DIRS="
+                       "/run/current-system/profile/share"
+                       "${XDG_DATA_DIRS:+:}${XDG_DATA_DIRS}\n")))
+
+                   ;; Symlink to bcu.sh from the output bin directory.
+                   (mkdir-p bin)
+                   (symlink (string-append bcu-root "/bcu.sh") bcu.sh)
+                   (chmod bcu.sh #o555)
+
+                   ;; Disable network and gui tests, and one test for setopts which
+                   ;; doesn't work inside the Guix build environment.
+                   (with-output-to-file (string-append bcu-root "/disabled_tests.txt")
+                     (lambda _
+                       (format #t "~{~a~%~}"
+                               (list "ip_of_test_1"
+                                     "setopts_test_4"
+                                     "web_media_server_test_1"
+                                     "web_api_server_test_1"
+                                     "find_gui_test_1"))))
+
+                   ;; Set up a minimal test environment & run the tests.
+                   (when tests?
+                     (setenv "PATH" (string-append bin ":"
+                                                   bash "/bin:"
+                                                   (getenv "PATH")))
+                     (setenv "SHELL"
+                             (string-append bash "/bin/bash"))
+                     (for-each (lambda (test-input)
+                                 (setenv "PATH"
+                                         (string-append
+                                          (assoc-ref %build-inputs test-input)
+                                          "/bin:" (getenv "PATH"))))
+                               (list "coreutils"))
+                     (setenv "HOME" "/tmp")
+                     (with-directory-excursion bcu-root
+                       (invoke "./bcu-test.sh")
+                       ;; No need to keep passed tests in the final output
+                       (for-each delete-file
+                                 (list "bcu-test.sh"
+                                       "disabled_tests.txt"))))))))
+      (inputs (list bash bash-ctypes coreutils
+                    diffutils file findutils
+                    gawk guile-3.0 guile-bash-for-bash-coding-utils
+                    jq libxml2-xpath0
+                    lsof
+                    nmap
+                    ;; org-html-themes is bundled upstream as a git submodule,
+                    ;; but we package it separately and copy it manually above.
+                    org-html-themes/methuselah-0
+                    pcre2 perl php
+                    procps
+                    pydaemon python python-elementpath python-lxml
+                    python-netaddr python-yq
+                    sed
+                    socat
+                    tree ugrep util-linux which
+                    xdg-utils ))
+      ;; the bash shell needs to be the same version
+      ;; as guile-bash is compiled against
+      (propagated-inputs (list bash))
+      (home-page "https://git.sr.ht/~methuselah-0/bash-coding-utils")
+      (synopsis "Functions and tools for software prototyping in Bash")
+      (description
+       "Bash-Coding-Utils is a library of Bash functions and wrappers that can
+be useful when writing quick implementations of new programs.  It helps you
+work with JSON, XML, API's and parallelization, and installs some helper
+programs commonly 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.39.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2023-05-23  4:57 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-30 14:59 [bug#51512] [PATCH]: gnu: Add bash-bcu david larsson
2021-11-07 12:40 ` Tobias Geerinckx-Rice via Guix-patches via
2021-11-09 12:32   ` [bug#51512] [PATCH v 2]: " david larsson
2021-11-20 14:11     ` Tobias Geerinckx-Rice via Guix-patches via
2021-11-23 12:44       ` david larsson
2022-07-01 18:13     ` [bug#51512] [PATCH v 3]: " david larsson
2022-08-02 20:21       ` david larsson
2022-08-27 18:29         ` david larsson
2023-05-20 19:23           ` david larsson
2023-05-20 19:28             ` david larsson
2023-05-20 20:16           ` [bug#51512] [PATCH v 4]: " david larsson
2021-11-15 16:45   ` Recommend order for package fields? zimoun
2021-11-16 18:54     ` Katherine Cox-Buday
2021-11-17 11:15       ` Ludovic Courtès
2021-11-17 11:18     ` Ludovic Courtès
2021-11-17 11:40       ` zimoun
2021-11-19 14:51         ` Ludovic Courtès
2022-07-04 21:11 ` [bug#51512] [PATCH]: gnu: Add bash-bcu ( via Guix-patches via
2022-07-04 21:21   ` ( via Guix-patches via
2023-05-21  6:58 ` [bug#51512] [PATCH v5]: " david larsson
2023-05-23  4:51 ` [bug#51512] [PATCH v6 0/3]: " david larsson
2023-05-23  4:53 ` [bug#51512] [PATCH v6 1/3]: " david larsson
2023-05-23  4:55 ` [bug#51512] [PATCH v6 2/3]: gnu: Add guile-bash-for-bash-coding-utils david larsson
2023-05-23  4:56 ` [bug#51512] [PATCH v6 3/3]: gnu: Add bash-coding-utils david larsson

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.