[PATCH v5 04/13] Port scripts/format-uuid.sh to awk

Demi Marie Obenour
2025-11-26T19:42:05Z

This makes it significantly easier to extend. Future changes will
require it to be able to output multiple UUIDs at once.

Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
---
Changes since v4:

- Convert script from sh to awk before making any functional changes.
---
host/initramfs/Makefile | 6 +++---
host/rootfs/Makefile | 6 +++---
release/live/Makefile | 6 +++---
release/live/default.nix | 2 +-
scripts/format-uuid.awk | 9 +++++++++
scripts/format-uuid.sh | 19 -------------------
6 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/host/initramfs/Makefile b/host/initramfs/Makefile
index 2304b0885a152d8a659dddcc58f948d096034e2d..e04e2ff471750410926f14099cee9786d582de86 100644
--- a/host/initramfs/Makefile
+++ b/host/initramfs/Makefile
@@ -35,10 +35,10 @@ build/mountpoints:
cd build/mountpoints && mkdir -p $(MOUNTPOINTS)
find build/mountpoints -mindepth 1 -exec touch -d @0 {} ';'

-build/live.img: ../../scripts/format-uuid.sh ../../scripts/make-gpt.sh ../../scripts/sfdisk-field.awk $(ROOT_FS_IMAGES)
+build/live.img: ../../scripts/format-uuid.awk ../../scripts/make-gpt.sh ../../scripts/sfdisk-field.awk $(ROOT_FS_IMAGES)
bash ../../scripts/make-gpt.sh $@.tmp \
- $(ROOT_FS_VERITY):verity:$$(../../scripts/format-uuid.sh "$$(dd if=$(ROOT_FS_VERITY_ROOTHASH) bs=32 skip=1 count=1 status=none)") \
- $(ROOT_FS_IMAGE):root:$$(../../scripts/format-uuid.sh "$$(head -c 32 $(ROOT_FS_VERITY_ROOTHASH))")
+ $(ROOT_FS_VERITY):verity:$$(awk -f ../../scripts/format-uuid.awk "$$(dd if=$(ROOT_FS_VERITY_ROOTHASH) bs=32 skip=1 count=1 status=none)") \
+ $(ROOT_FS_IMAGE):root:$$(awk -f ../../scripts/format-uuid.awk "$$(head -c 32 $(ROOT_FS_VERITY_ROOTHASH))")
mv $@.tmp $@

build/loop.tar: build/live.img
diff --git a/host/rootfs/Makefile b/host/rootfs/Makefile
index f45758041f2f682618cb0f9e54e5a74f0b49874e..b2c0c6176fe0de4a99d1a3737d50054b532af598 100644
--- a/host/rootfs/Makefile
+++ b/host/rootfs/Makefile
@@ -92,10 +92,10 @@ clean:
rm -rf build
.PHONY: clean

-build/live.img: ../../scripts/format-uuid.sh ../../scripts/make-gpt.sh ../../scripts/sfdisk-field.awk build/verity-timestamp $(ROOT_FS_IMAGES)
+build/live.img: ../../scripts/format-uuid.awk ../../scripts/make-gpt.sh ../../scripts/sfdisk-field.awk build/verity-timestamp $(ROOT_FS_IMAGES)
bash ../../scripts/make-gpt.sh $@.tmp \
- $(ROOT_FS_VERITY):verity:$$(../../scripts/format-uuid.sh "$$(dd if=$(ROOT_FS_VERITY_ROOTHASH) bs=32 skip=1 count=1 status=none)") \
- $(ROOT_FS_IMAGE):root:$$(../../scripts/format-uuid.sh "$$(head -c 32 $(ROOT_FS_VERITY_ROOTHASH))")
+ $(ROOT_FS_VERITY):verity:$$(awk -f ../../scripts/format-uuid.awk "$$(dd if=$(ROOT_FS_VERITY_ROOTHASH) bs=32 skip=1 count=1 status=none)") \
+ $(ROOT_FS_IMAGE):root:$$(awk -f ../../scripts/format-uuid.awk "$$(head -c 32 $(ROOT_FS_VERITY_ROOTHASH))")
mv $@.tmp $@

debug:
diff --git a/release/live/Makefile b/release/live/Makefile
index c712db3727b7008105388a278552fd3d81eb3b4c..48df3ef4ad3faab4e0ad09380bd70dbdc980109f 100644
--- a/release/live/Makefile
+++ b/release/live/Makefile
@@ -9,11 +9,11 @@ DTBS ?= build/empty

dest = build/live.img

-$(dest): ../../scripts/format-uuid.sh ../../scripts/make-gpt.sh ../../scripts/sfdisk-field.awk build/boot.fat $(ROOT_FS_IMAGES)
+$(dest): ../../scripts/format-uuid.awk ../../scripts/make-gpt.sh ../../scripts/sfdisk-field.awk build/boot.fat $(ROOT_FS_IMAGES)
bash ../../scripts/make-gpt.sh $@.tmp \
build/boot.fat:c12a7328-f81f-11d2-ba4b-00a0c93ec93b \
- $(ROOT_FS_VERITY):verity:$$(../../scripts/format-uuid.sh "$$(dd if=$(ROOT_FS_VERITY_ROOTHASH) bs=32 skip=1 count=1 status=none)") \
- $(ROOT_FS_IMAGE):root:$$(../../scripts/format-uuid.sh "$$(head -c 32 $(ROOT_FS_VERITY_ROOTHASH))")
+ $(ROOT_FS_VERITY):verity:$$(awk -f ../../scripts/format-uuid.awk "$$(dd if=$(ROOT_FS_VERITY_ROOTHASH) bs=32 skip=1 count=1 status=none)") \
+ $(ROOT_FS_IMAGE):root:$$(awk -f ../../scripts/format-uuid.awk "$$(head -c 32 $(ROOT_FS_VERITY_ROOTHASH))")
mv $@.tmp $@

build/empty:
diff --git a/release/live/default.nix b/release/live/default.nix
index ba9bb17e697a6ecfe81e52a4ffbc375ef443b6f3..d1e2422e9f1ba666af7ad7a5cce1c80a242d0777 100644
--- a/release/live/default.nix
+++ b/release/live/default.nix
@@ -29,7 +29,7 @@ stdenv.mkDerivation {
fileset = lib.fileset.intersection src (lib.fileset.unions [
./.
../../lib/common.mk
- ../../scripts/format-uuid.sh
+ ../../scripts/format-uuid.awk
../../scripts/make-gpt.sh
../../scripts/sfdisk-field.awk
]);
diff --git a/scripts/format-uuid.awk b/scripts/format-uuid.awk
new file mode 100644
index 0000000000000000000000000000000000000000..17831221bbef2d2d038f4822b22f88939eab7437
--- /dev/null
+++ b/scripts/format-uuid.awk
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: EUPL-1.2+
+# SPDX-FileCopyrightText: 2025 Demi Marie Obenour <demiobenour@gmail.com>
+BEGIN {
+ print (substr(ARGV[1], 1, 8) "-" \
+ substr(ARGV[1], 9, 4) "-" \
+ substr(ARGV[1], 13, 4) "-" \
+ substr(ARGV[1], 17, 4) "-" \
+ substr(ARGV[1], 21, 12));
+}
diff --git a/scripts/format-uuid.sh b/scripts/format-uuid.sh
deleted file mode 100755
index 3b38278aef640b2cd540d6606b05dd62018e48a6..0000000000000000000000000000000000000000
--- a/scripts/format-uuid.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/bin/sh -eu
-#
-# SPDX-FileCopyrightText: 2021-2022 Alyssa Ross <hi@alyssa.is>
-# SPDX-FileCopyrightText: 2022 Unikie
-# SPDX-License-Identifier: EUPL-1.2+
-
-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"

--
2.52.0