From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from atuin.qyliss.net (localhost [IPv6:::1]) by atuin.qyliss.net (Postfix) with ESMTP id 9847114898; Tue, 8 Nov 2022 15:05:28 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 496) id 079BF14800; Tue, 8 Nov 2022 15:05:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on atuin.qyliss.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,LOTS_OF_MONEY,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.6 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by atuin.qyliss.net (Postfix) with ESMTPS id 26C38147FE for ; Tue, 8 Nov 2022 15:05:22 +0000 (UTC) Received: by mail-lj1-x234.google.com with SMTP id z24so21533967ljn.4 for ; Tue, 08 Nov 2022 07:05:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unikie.com; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=iSrj9lBPuz3rdqKS/Ueqg9Sz7US9BUMcVhXMylTORk8=; b=RhqLkKvxhS9LZwc13oN/vk1F2rWS3kKHd5W0TiMhYy7oN2+mFC8bzbGAYmcwiLK3ld GKiBiUtnnQiRZ/ksUUNCezFNybb7JZ/imlnPi9apMcw/ZEhHtDjsXZtq9Tg4lAHS3V10 RqN0SILMfzUh/fWN9sNhqLMLLQDDj6f1LNA6EvHlrAEMJBxBSUCawG6j9/hKxSl/l4cK QD5ztwIZtAcuinVr5YlKCDQgTopt7YzR6AkQXnEB9g/i1T/EKu5V94NWlnFVz+FppZxt iYD5iEy6G3womESIjVF2Q513IEJG8eJy9tWgwQr0ACL5zRWe4JbEsaLUijlbto1i/0hL /FeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=iSrj9lBPuz3rdqKS/Ueqg9Sz7US9BUMcVhXMylTORk8=; b=Doam0n248yuBt85CZRhF2N5cPHlKS1e3WrUfCw86s1uyHe24gXgvp9jlGKPX4s4t5F fWtGNE9ibetjFF5y7MuA+Feo0GvO1mBF6eczdQvsGoxI66ysIFjMSRgvoKSo7mpe27gb 0g9tXkctWQnACS78fXoIQ5bqJ3Hr0GjGpyga60TOaNfx0otPRdAezLl6VICPnVxUEdzw RwwKLgtAXPIWQxTK9owZnGBHYnnj6Ir1Quw95x/dBsyJtZBcduVGKoV9dzf1buv2ywAC nMms+yWykbcU3HQ0Tko5YxYesvHYt+qBaJP9SU+ZB6Wm60WKc9et0kXGiZdxPkkqAFvL 5ZpQ== X-Gm-Message-State: ACrzQf268gNvvwKGc8r5LLm2bqzOCHRSz6gU5AbjB7Lh9v6SmxJnKNPa KPqT4GVE6kof0Z0otGYVvLmczw== X-Google-Smtp-Source: AMsMyM6DG4V9qHy6kqKG6Jlz/33jKGRNIFe7mAG7mObxRiMc7Uzgz4bJehh16ZuTcpQ7boiruu+Qzg== X-Received: by 2002:a2e:9dd0:0:b0:277:c94:8247 with SMTP id x16-20020a2e9dd0000000b002770c948247mr19652108ljj.397.1667919918666; Tue, 08 Nov 2022 07:05:18 -0800 (PST) Received: from buamix (86-60-162-79.dynamic.lounea.fi. [86.60.162.79]) by smtp.gmail.com with ESMTPSA id n12-20020a0565120acc00b0048a9b197863sm1826509lfu.235.2022.11.08.07.05.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 07:05:18 -0800 (PST) Date: Tue, 8 Nov 2022 17:05:12 +0200 From: Henri Rosten To: Alyssa Ross Subject: Re: [PATCH] Remove bashisms from spectrum shell scripts Message-ID: <20221108150512.GA833412@buamix> References: <20221108100544.721808-1-henri.rosten@unikie.com> <20221108132727.5ekxh47up5woquoy@x220> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221108132727.5ekxh47up5woquoy@x220> Message-ID-Hash: Z3B5XDUNX4IBBDHIMVHWNCHEPY7ZM7S5 X-Message-ID-Hash: Z3B5XDUNX4IBBDHIMVHWNCHEPY7ZM7S5 X-MailFrom: henri.rosten@unikie.com X-Mailman-Rule-Hits: header-match-devel.spectrum-os.org-0 X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1 CC: devel@spectrum-os.org X-Mailman-Version: 3.3.5 Precedence: list List-Id: Patches and low-level development discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-TUID: iEm6Md6k8TSD On Tue, Nov 08, 2022 at 01:27:27PM +0000, Alyssa Ross wrote: > On Tue, Nov 08, 2022 at 12:05:44PM +0200, Henri Rosten wrote: > > This commit removes bashisms from spectrum shell scripts. This change is > > needed to be able to use the scripts from POSIX-compliant shells which > > are not bash compatible - such as dash. > > > > Signed-off-by: Henri Rosten > > --- > > Documentation/scripts/undocumented-uuids.sh | 6 +++++- > > scripts/format-uuid.sh | 15 ++++++++++++++- > > scripts/make-gpt.sh | 7 +++---- > > 3 files changed, 22 insertions(+), 6 deletions(-) > > > > Thanks! I definitely prefer to stick to portable shell, awk, make etc. > functionality, so I'm happy to receive this patch. I'll look into > integrating shellcheck into the build to ensure the bashisms don't creep > back in. > > I've left some comments below. > > > diff --git a/Documentation/scripts/undocumented-uuids.sh b/Documentation/scripts/undocumented-uuids.sh > > index 34c2d22..0434407 100755 > > --- a/Documentation/scripts/undocumented-uuids.sh > > +++ b/Documentation/scripts/undocumented-uuids.sh > > @@ -1,5 +1,6 @@ > > #!/bin/sh -eu > > # SPDX-FileCopyrightText: 2022 Alyssa Ross > > +# SPDX-FileCopyrightText: 2022 Unikie > > # SPDX-License-Identifier: EUPL-1.2+ > > > > cd "$(dirname "$0")/../.." > > @@ -7,8 +8,11 @@ cd "$(dirname "$0")/../.." > > PATTERN='\b[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}\b' > > UUID_REFERENCE_PATH=Documentation/uuid-reference.adoc > > > > +tmp=$(mktemp) > > Let's clean this up with a trap, so that it gets cleaned up even if > something fails: > > trap "rm -f $tmp" EXIT > > And since we have to give it a name, maybe we could use the opportunity > to make it descriptive? "documented_uuids", maybe? > I'll fix this in a follow-up version. > > +grep -Eio "$PATTERN" "$UUID_REFERENCE_PATH" | sort -u >$tmp > > git ls-files -coz --exclude-standard | > > grep -Fxvz "$UUID_REFERENCE_PATH" | > > xargs -0 git grep -Ehio --no-index --no-line-number "$PATTERN" -- | > > sort -u | > > - comm -23 - <(grep -Eio "$PATTERN" "$UUID_REFERENCE_PATH" | sort -u) > > + comm -23 - $tmp > > +rm -f $tmp > > diff --git a/scripts/format-uuid.sh b/scripts/format-uuid.sh > > index fa07eb9..c7b94da 100755 > > --- a/scripts/format-uuid.sh > > +++ b/scripts/format-uuid.sh > > @@ -1,6 +1,19 @@ > > #!/bin/sh -eu > > # > > # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross > > +# SPDX-FileCopyrightText: 2022 Unikie > > # SPDX-License-Identifier: EUPL-1.2+ > > > > -printf "%s\n" "${1:0:8}-${1:8:4}-${1:12:4}-${1:16:4}-${1:20}" > > +substr () { > > + str=$1 > > + beg=$2 > > + end=$3 > > + echo $(echo $str | cut -c $beg-$end) > > This should work fine if we drop the echo $(...), right? > True, the outer echo is not needed. I'll fix this too in a follow-up version. > > +} > > + > > +u1=$(substr $1 1 8) > > +u2=$(substr $1 9 12) > > +u3=$(substr $1 13 16) > > +u4=$(substr $1 17 20) > > +u5=$(substr $1 21 32) > > +printf "%s\n" "$u1-$u2-$u3-$u4-$u5" > > diff --git a/scripts/make-gpt.sh b/scripts/make-gpt.sh > > index 56076d3..351aa69 100755 > > --- a/scripts/make-gpt.sh > > +++ b/scripts/make-gpt.sh > > @@ -1,6 +1,7 @@ > > #!/bin/sh -eu > > # > > # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross > > +# SPDX-FileCopyrightText: 2022 Unikie > > # SPDX-License-Identifier: EUPL-1.2+ > > # > > # usage: make-gpt.sh GPT_PATH PATH:PARTTYPE[:PARTUUID]... > > @@ -38,7 +39,7 @@ scriptsDir="$(dirname "$0")" > > out="$1" > > shift > > > > -nl=$'\n' > > +nl='\n' > > table="label: gpt" > > > > # Keep 1MiB free at the start, and 1MiB free at the end. > > @@ -51,9 +52,7 @@ done > > > > rm -f "$out" > > truncate -s "$gptBytes" "$out" > > -sfdisk "$out" < > -$table > > -EOF > > +printf "$table" | sfdisk "$out" > > The heredoc previously used here should be POSIX: > > https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07_04 > > Does it not work in dash? > Heredoc works in dash too, but I couldn't find out how to expand the newlines in variable inside heredoc so that it would work in dash. Therefore I simply removed the heredoc and used printf instead. > > > > n=0 > > for partition; do > > -- > > 2.25.1 > > > >