patches and low-level development discussion
 help / color / mirror / code / Atom feed
From: Henri Rosten <henri.rosten@unikie.com>
To: devel@spectrum-os.org
Cc: Henri Rosten <henri.rosten@unikie.com>
Subject: [PATCH v3] Remove bashisms from spectrum shell scripts
Date: Wed,  9 Nov 2022 15:27:30 +0200	[thread overview]
Message-ID: <20221109132730.941054-1-henri.rosten@unikie.com> (raw)

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 <henri.rosten@unikie.com>
---
 Documentation/scripts/undocumented-uuids.sh |  9 +++++++--
 scripts/format-uuid.sh                      | 15 ++++++++++++++-
 scripts/make-gpt.sh                         |  4 +++-
 3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/Documentation/scripts/undocumented-uuids.sh b/Documentation/scripts/undocumented-uuids.sh
index 34c2d22..c75bfd2 100755
--- a/Documentation/scripts/undocumented-uuids.sh
+++ b/Documentation/scripts/undocumented-uuids.sh
@@ -1,14 +1,19 @@
 #!/bin/sh -eu
 # SPDX-FileCopyrightText: 2022 Alyssa Ross <hi@alyssa.is>
+# SPDX-FileCopyrightText: 2022 Unikie
 # SPDX-License-Identifier: EUPL-1.2+
 
 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
+UUID_REFERENCE_PATH=Documentation/appendices/uuid-reference.adoc
 
+documented_uuids=$(mktemp)
+trap 'rm -f -- "$documented_uuids"' EXIT
+
+grep -Eio "$PATTERN" "$UUID_REFERENCE_PATH" | sort -u >"$documented_uuids"
 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 - "$documented_uuids"
diff --git a/scripts/format-uuid.sh b/scripts/format-uuid.sh
index fa07eb9..6758088 100755
--- a/scripts/format-uuid.sh
+++ b/scripts/format-uuid.sh
@@ -1,6 +1,19 @@
 #!/bin/sh -eu
 #
 # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross <hi@alyssa.is>
+# 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 $str | cut -c $beg-$end
+}
+
+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..3215edb 100755
--- a/scripts/make-gpt.sh
+++ b/scripts/make-gpt.sh
@@ -1,6 +1,7 @@
 #!/bin/sh -eu
 #
 # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross <hi@alyssa.is>
+# SPDX-FileCopyrightText: 2022 Unikie
 # SPDX-License-Identifier: EUPL-1.2+
 #
 # usage: make-gpt.sh GPT_PATH PATH:PARTTYPE[:PARTUUID]...
@@ -38,7 +39,8 @@ scriptsDir="$(dirname "$0")"
 out="$1"
 shift
 
-nl=$'\n'
+nl='
+'
 table="label: gpt"
 
 # Keep 1MiB free at the start, and 1MiB free at the end.
-- 
2.25.1




             reply	other threads:[~2022-11-09 13:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09 13:27 Henri Rosten [this message]
2022-11-10  8:18 ` Alyssa Ross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221109132730.941054-1-henri.rosten@unikie.com \
    --to=henri.rosten@unikie.com \
    --cc=devel@spectrum-os.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).