From patchwork Tue Nov 9 12:32:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: david larsson X-Patchwork-Id: 34327 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id B9FB627BBE1; Tue, 9 Nov 2021 12:33:38 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id DCCFB27BBE3 for ; Tue, 9 Nov 2021 12:33:37 +0000 (GMT) Received: from localhost ([::1]:57700 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mkQJl-0004bv-2S for patchwork@mira.cbaines.net; Tue, 09 Nov 2021 07:33:37 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41702) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mkQJD-0004Y3-EU for guix-patches@gnu.org; Tue, 09 Nov 2021 07:33:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:49553) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mkQJC-0000bX-FP for guix-patches@gnu.org; Tue, 09 Nov 2021 07:33:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mkQJC-0006c0-DC for guix-patches@gnu.org; Tue, 09 Nov 2021 07:33:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51512] [PATCH v 2]: gnu: Add bash-bcu. Resent-From: david larsson Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 09 Nov 2021 12:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51512 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51512@debbugs.gnu.org X-Debbugs-Original-To: 51512@debbugs.gnu.org, guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.163646117325401 (code B ref -1); Tue, 09 Nov 2021 12:33:02 +0000 Received: (at submit) by debbugs.gnu.org; 9 Nov 2021 12:32:53 +0000 Received: from localhost ([127.0.0.1]:32866 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mkQJ3-0006bd-5m for submit@debbugs.gnu.org; Tue, 09 Nov 2021 07:32:53 -0500 Received: from lists.gnu.org ([209.51.188.17]:59178) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mkQJ1-0006bU-79 for submit@debbugs.gnu.org; Tue, 09 Nov 2021 07:32:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mkQIx-0004Te-Iy for guix-patches@gnu.org; Tue, 09 Nov 2021 07:32:51 -0500 Received: from server0.selfhosted.xyz ([217.64.149.7]:49994) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mkQIq-0000ZL-9U for guix-patches@gnu.org; Tue, 09 Nov 2021 07:32:47 -0500 Received: from server0.selfhosted.xyz (localhost [127.0.0.1]) by server0.selfhosted.xyz (Postfix) with ESMTP id 4F3AD2727165; Tue, 9 Nov 2021 13:32:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=selfhosted.xyz; s=dkim; t=1636461154; bh=JXFgOGEb90i/5dJwsJ4X7tZWDbIv1QKGsecwrdiX4yI=; h=Date:From:To:Subject:In-Reply-To:References; b=uJJ+sWifWHzOwlY4jNa1fPCP4w4KcuE0MKihRhsQZKcuLo8R9FTLcz9jJ82j3kQzN 9+fi9UMg/lCW76JlY5ombPG5Dlc8HwSP15+c1d7HVml3HNYh4I/Vtlh4WfHuWCQmck fLf++8tPyF0AA2bqq/z0X2jkvRs2GiLBZAXRFoOWJAkaoBk4VYVHcXWsK21CkNIUsL 71XKzAdVbnAjXOii3xoHJMfLIAN/4VTmUeHruyfDi4gGtvrR+22rspj7VD76m7XdU3 mb3/8lbqlEdTDBJQ1Dmg0wfupadSCtDLDsyueka3GL53YYb5zJBuL4KCWrCUJ8KUgy HhlTKbmdbiziw== X-Fuglu-Suspect: c92537c2bf0846be8fa2545d09a38fd3 X-Fuglu-Spamstatus: NO Received: from webmail.selfhosted.xyz (office.selfhosted.xyz [192.168.1.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: mail@selfhosted.xyz) by server0.selfhosted.xyz (Postfix) with ESMTPSA; Tue, 9 Nov 2021 13:32:28 +0100 (CET) MIME-Version: 1.0 Date: Tue, 09 Nov 2021 13:32:28 +0100 From: david larsson In-Reply-To: <87r1bsqdy8.fsf@nckx> References: <3add15b77522d6e9ebd715a19d966666@selfhosted.xyz> <87r1bsqdy8.fsf@nckx> Message-ID: <93d8232c104dc63f46f6b975073b56ca@selfhosted.xyz> X-Sender: david.larsson@selfhosted.xyz Received-SPF: pass client-ip=217.64.149.7; envelope-from=david.larsson@selfhosted.xyz; helo=server0.selfhosted.xyz X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FROM_SUSPICIOUS_NTLD=0.001, PDS_OTHER_BAD_TLD=0.001, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches 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 From d3ee10521b981fb4b97b2020bf9e3cd8373c3d5b Mon Sep 17 00:00:00 2001 From: David Larsson 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