From patchwork Sat Nov 20 14:11:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Geerinckx-Rice X-Patchwork-Id: 34705 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 5367C27BBE3; Sat, 20 Nov 2021 14:26:17 +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 88F0A27BBE1 for ; Sat, 20 Nov 2021 14:26:16 +0000 (GMT) Received: from localhost ([::1]:56840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1moRJn-0006ji-H1 for patchwork@mira.cbaines.net; Sat, 20 Nov 2021 09:26:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1moRJa-0006jG-Q6 for guix-patches@gnu.org; Sat, 20 Nov 2021 09:26:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:58701) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1moRJa-00079p-IA for guix-patches@gnu.org; Sat, 20 Nov 2021 09:26:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1moRJa-0007C7-2w for guix-patches@gnu.org; Sat, 20 Nov 2021 09:26:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51512] [PATCH v 2]: gnu: Add bash-bcu. Resent-From: Tobias Geerinckx-Rice Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 20 Nov 2021 14:26: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: david larsson Cc: 51512@debbugs.gnu.org X-Debbugs-Original-Cc: 51512@debbugs.gnu.org, guix-patches@gnu.org Received: via spool by 51512-submit@debbugs.gnu.org id=B51512.163741833327609 (code B ref 51512); Sat, 20 Nov 2021 14:26:02 +0000 Received: (at 51512) by debbugs.gnu.org; 20 Nov 2021 14:25:33 +0000 Received: from localhost ([127.0.0.1]:42014 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1moRJ3-0007B5-1Q for submit@debbugs.gnu.org; Sat, 20 Nov 2021 09:25:33 -0500 Received: from tobias.gr ([80.241.217.52]:44600) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1moRJ1-0007Au-9p for 51512@debbugs.gnu.org; Sat, 20 Nov 2021 09:25:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=2018; bh=q7SZqdmhq5m3o nAhgpZwRe0H7zeAlVCQ9V0xPQ0eyvo=; h=in-reply-to:date:subject:cc:to: from:references; d=tobias.gr; b=AxVPK282YAut54Z1IbyJVzdYIiJ3MMpm7yhPv4 MPx9dFSN7jVBp+AwKow2cWMxWN8r26gxCvmp9RURcdOJG2sfBGjb8fNrsffeM6ldyDdL14 FF7o/FmdrFaW344kW847+PlcscCgQsMq52bj5RXiGWikqp38a8e9SQ0OS3rbymqiYD7bly P+grlxIIfRHBXLU2uktHtG1iC9L5PS0s8WsYMxK12QjuMzEDnVDgm7yHsDJsB+9uE1HsTa uT0Tb47SdMM6XdWrC40oeI1H5DP2+3wwMzi3Vzs0NY4KAk62aJnGB2/R9cguKuUpBT9g+8 TU0Q5pmV+BJPrxJhaso7yrPQ== Received: by submission.tobias.gr (OpenSMTPD) with ESMTPSA id b7cb816f (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sat, 20 Nov 2021 14:25:23 +0000 (UTC) References: <3add15b77522d6e9ebd715a19d966666@selfhosted.xyz> <87r1bsqdy8.fsf@nckx> <93d8232c104dc63f46f6b975073b56ca@selfhosted.xyz> Date: Sat, 20 Nov 2021 15:11:30 +0100 In-reply-to: <93d8232c104dc63f46f6b975073b56ca@selfhosted.xyz> BIMI-Selector: v=BIMI1; s=default; Message-ID: <87y25inbsu.fsf@nckx> MIME-Version: 1.0 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" Reply-to: Tobias Geerinckx-Rice X-ACL-Warn: , Tobias Geerinckx-Rice via Guix-patches X-Patchwork-Original-From: Tobias Geerinckx-Rice via Guix-patches via From: Tobias Geerinckx-Rice X-getmail-retrieved-from-mailbox: Patches 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 From 2ee51b0224c6f3bf9720d217346f53e3cb94e68a Mon Sep 17 00:00:00 2001 From: Tobias Geerinckx-Rice 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