git: 045c8f526484 - main - mkisoimages.sh: Avoid creating temporary files in the current directory

From: Jessica Clarke <jrtc27_at_FreeBSD.org>
Date: Mon, 28 Feb 2022 22:41:07 UTC
The branch main has been updated by jrtc27:

URL: https://cgit.FreeBSD.org/src/commit/?id=045c8f526484cb3b97f5fd693987f4376fa43c5f

commit 045c8f526484cb3b97f5fd693987f4376fa43c5f
Author:     Jessica Clarke <jrtc27@FreeBSD.org>
AuthorDate: 2022-02-28 22:36:51 +0000
Commit:     Jessica Clarke <jrtc27@FreeBSD.org>
CommitDate: 2022-02-28 22:36:51 +0000

    mkisoimages.sh: Avoid creating temporary files in the current directory
    
    Currently the current directory is the parent of the rootfs directory,
    but this will change in order to support NO_ROOT builds that use a
    metalog manifest, since those need to have the current directory be the
    rootfs itself in order for the relative paths to be correct, and we do
    not want the non-METALOG case (which passes the directory to makefs) to
    pick up leftover temporary .img files from a previous failed build.
    
    Reviewed by:    brooks, emaste, gjb
    Differential Revision:  https://reviews.freebsd.org/D33998
---
 release/amd64/mkisoimages.sh | 7 ++++---
 release/arm64/mkisoimages.sh | 7 ++++---
 release/riscv/mkisoimages.sh | 7 ++++---
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/release/amd64/mkisoimages.sh b/release/amd64/mkisoimages.sh
index a9e8a2c04392..7f79ddc800e9 100644
--- a/release/amd64/mkisoimages.sh
+++ b/release/amd64/mkisoimages.sh
@@ -85,15 +85,16 @@ if [ "$bootable" != "" ]; then
 	done
 
 	# Create a GPT image containing the partitions we need for hybrid boot.
+	hybridfilename=$(mktemp /tmp/hybrid.img.XXXXXX)
 	imgsize=`stat -f %z "$NAME"`
 	$MKIMG -s gpt \
 	    --capacity $imgsize \
 	    -b "$BASEBITSDIR/boot/pmbr" \
 	    -p freebsd-boot:="$BASEBITSDIR/boot/isoboot" \
 	    $espparam \
-	    -o hybrid.img
+	    -o $hybridfilename
 
 	# Drop the PMBR, GPT, and boot code into the System Area of the ISO.
-	dd if=hybrid.img of="$NAME" bs=32k count=1 conv=notrunc
-	rm -f hybrid.img
+	dd if=$hybridfilename of="$NAME" bs=32k count=1 conv=notrunc
+	rm -f $hybridfilename
 fi
diff --git a/release/arm64/mkisoimages.sh b/release/arm64/mkisoimages.sh
index 5556336840cd..8d260883c294 100644
--- a/release/arm64/mkisoimages.sh
+++ b/release/arm64/mkisoimages.sh
@@ -81,13 +81,14 @@ if [ "$bootable" != "" ]; then
 	done
 
 	# Create a GPT image containing the EFI partition.
+	efifilename=$(mktemp /tmp/efi.img.XXXXXX)
 	imgsize=`stat -f %z "$NAME"`
 	$MKIMG -s gpt \
 	    --capacity $imgsize \
 	    $espparam \
-	    -o efi.img
+	    -o $efifilename
 
 	# Drop the GPT into the System Area of the ISO.
-	dd if=efi.img of="$NAME" bs=32k count=1 conv=notrunc
-	rm -f efi.img
+	dd if=$efifilename of="$NAME" bs=32k count=1 conv=notrunc
+	rm -f $efifilename
 fi
diff --git a/release/riscv/mkisoimages.sh b/release/riscv/mkisoimages.sh
index 5556336840cd..8d260883c294 100644
--- a/release/riscv/mkisoimages.sh
+++ b/release/riscv/mkisoimages.sh
@@ -81,13 +81,14 @@ if [ "$bootable" != "" ]; then
 	done
 
 	# Create a GPT image containing the EFI partition.
+	efifilename=$(mktemp /tmp/efi.img.XXXXXX)
 	imgsize=`stat -f %z "$NAME"`
 	$MKIMG -s gpt \
 	    --capacity $imgsize \
 	    $espparam \
-	    -o efi.img
+	    -o $efifilename
 
 	# Drop the GPT into the System Area of the ISO.
-	dd if=efi.img of="$NAME" bs=32k count=1 conv=notrunc
-	rm -f efi.img
+	dd if=$efifilename of="$NAME" bs=32k count=1 conv=notrunc
+	rm -f $efifilename
 fi