Also add some error checks and use Bash features. No other functional change intended. Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com> --- Changes since v2: - Do not use wrapper script. - Make script non-executable. - Invoke script as 'bash FILE' to work around /usr/bin/env not working during a Nix build. --- host/initramfs/Makefile | 4 ++-- host/rootfs/Makefile | 2 +- img/app/Makefile | 2 +- release/live/Makefile | 4 ++-- scripts/make-gpt.sh | 20 ++++++++++---------- vm/sys/net/Makefile | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/host/initramfs/Makefile b/host/initramfs/Makefile index 13bb548d6146684a25dab1e31228c0b9a4ca8db7..fd8cbb6c3e775ed27d0a524bf167cb4d3940d799 100644 --- a/host/initramfs/Makefile +++ b/host/initramfs/Makefile @@ -36,7 +36,7 @@ build/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) - ../../scripts/make-gpt.sh $@.tmp \ + 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):root:$$(../../scripts/format-uuid.sh "$$(head -c 32 $(ROOT_FS_VERITY_ROOTHASH))") mv $@.tmp $@ @@ -45,7 +45,7 @@ build/loop.tar: build/live.img $(TAR) -cf $@ build/live.img build/loop.img: ../../scripts/make-gpt.sh ../../scripts/sfdisk-field.awk build/loop.ext4 - ../../scripts/make-gpt.sh $@.tmp \ + bash ../../scripts/make-gpt.sh $@.tmp \ build/loop.ext4:56a3bbc3-aefa-43d9-a64d-7b3fd59bbc4e mv $@.tmp $@ diff --git a/host/rootfs/Makefile b/host/rootfs/Makefile index 4c14d3acfa8f7ffd276fdfb684d08bf58fd80a15..533471c58591d305f386157e04e9e48da7259fd5 100644 --- a/host/rootfs/Makefile +++ b/host/rootfs/Makefile @@ -96,7 +96,7 @@ clean: .PHONY: clean build/live.img: ../../scripts/format-uuid.sh ../../scripts/make-gpt.sh ../../scripts/sfdisk-field.awk $(ROOT_FS_DIR)/verity-timestamp $(ROOT_FS) - ../../scripts/make-gpt.sh $@.tmp \ + bash ../../scripts/make-gpt.sh $@.tmp \ $(ROOT_FS)/rootfs.verity.superblock:verity:$$(../../scripts/format-uuid.sh "$$(dd if=$(ROOT_FS_VERITY_ROOTHASH) bs=32 skip=1 count=1 status=none)") \ $(ROOT_FS)/rootfs:root:$$(../../scripts/format-uuid.sh "$$(head -c 32 $(ROOT_FS_VERITY_ROOTHASH)") mv $@.tmp $@ diff --git a/img/app/Makefile b/img/app/Makefile index 48eba871339d314479f730101246ace3fa39e2db..f16c2df1b90bbec6750f2980da4dbaf49c9cb0ea 100644 --- a/img/app/Makefile +++ b/img/app/Makefile @@ -26,7 +26,7 @@ $(imgdir)/appvm/vmlinux: $(KERNEL) $(imgdir)/appvm/blk/root.img: ../../scripts/make-gpt.sh ../../scripts/sfdisk-field.awk build/rootfs.erofs mkdir -p $$(dirname $@) - ../../scripts/make-gpt.sh $@.tmp \ + bash ../../scripts/make-gpt.sh $@.tmp \ build/rootfs.erofs:root:5460386f-2203-4911-8694-91400125c604:root mv $@.tmp $@ diff --git a/release/live/Makefile b/release/live/Makefile index d61248e94599adc5229d0ad38d54b9f649d66ca1..4dbac28a90dc6f64a253961c33c597220d0e85cf 100644 --- a/release/live/Makefile +++ b/release/live/Makefile @@ -9,8 +9,8 @@ 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) - ../../scripts/make-gpt.sh $@.tmp \ +$(dest): ../../scripts/format-uuid.sh ../../scripts/make-gpt.bash ../../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):root:$$(../../scripts/format-uuid.sh "$$(head -c 32 $(ROOT_FS_VERITY_ROOTHASH))") diff --git a/scripts/make-gpt.sh b/scripts/make-gpt.sh old mode 100755 new mode 100644 index 96f0d2c8494c093558c0e32e7e920b569bb078ef..0ae3d0005e5ae7d6214270fedb2fafb0a7064cf5 --- a/scripts/make-gpt.sh +++ b/scripts/make-gpt.sh @@ -1,11 +1,11 @@ -#!/bin/sh -eu -# +#!/usr/bin/env -S bash -- # SPDX-FileCopyrightText: 2021-2023 Alyssa Ross <hi@alyssa.is> # SPDX-FileCopyrightText: 2022 Unikie # SPDX-License-Identifier: EUPL-1.2+ # -# usage: make-gpt.sh GPT_PATH PATH:PARTTYPE[:PARTUUID[:PARTLABEL]]... +# usage: bash make-gpt.sh GPT_PATH PATH:PARTTYPE[:PARTUUID[:PARTLABEL]]... +set -xeuo pipefail ONE_MiB=1048576 # Prints the number of 1MiB blocks required to store the file named @@ -40,16 +40,15 @@ scriptsDir="$(dirname "$0")" out="$1" shift -nl=' -' table="label: gpt" # Keep 1MiB free at the start, and 1MiB free at the end. gptBytes=$((ONE_MiB * 2)) for partition; do - sizeMiB="$(sizeMiB "$(partitionPath "$partition")")" - table="$table${nl}size=${sizeMiB}MiB,$(awk -f "$scriptsDir/sfdisk-field.awk" -v partition="$partition")" - gptBytes="$((gptBytes + sizeMiB * ONE_MiB))" + partitionPath=$(partitionPath "$partition") + sizeMiB=$(sizeMiB "$partitionPath") + table+=$'\n'"size=${sizeMiB}MiB,$(awk -f "$scriptsDir/sfdisk-field.awk" -v partition="$partition")" + gptBytes=$((gptBytes + sizeMiB * ONE_MiB)) done rm -f "$out" @@ -60,6 +59,7 @@ EOF n=0 for partition; do - fillPartition "$out" "$n" "$(partitionPath "$partition")" - n="$((n + 1))" + partitionPath=$(partitionPath "$partition") + fillPartition "$out" "$n" "$partitionPath" + n=$((n + 1)) done diff --git a/vm/sys/net/Makefile b/vm/sys/net/Makefile index d71c2325eff3bae921f33c61f799846d35e401c2..e403d697d90c0021a7a8d1dbc1553cfbda74a117 100644 --- a/vm/sys/net/Makefile +++ b/vm/sys/net/Makefile @@ -25,7 +25,7 @@ $(vmdir)/netvm/vmlinux: $(KERNEL) $(vmdir)/netvm/blk/root.img: ../../../scripts/make-gpt.sh ../../../scripts/sfdisk-field.awk build/rootfs.erofs mkdir -p $$(dirname $@) - ../../../scripts/make-gpt.sh $@.tmp \ + bash ../../../scripts/make-gpt.sh $@.tmp \ build/rootfs.erofs:root:ea21da27-0391-48da-9235-9d2ab2ca7844:root mv $@.tmp $@ -- 2.52.0