[Libguestfs] [p2v PATCH 1/4] Makefile.am: factor out "make-physical-machine.sh"

Laszlo Ersek lersek at redhat.com
Fri Aug 26 11:39:05 UTC 2022


Extract and somewhat generalize the recipe for the $(PHYSICAL_MACHINE)
target to a separate shell script. In preparation for the multiple steps
we're going to introduce later, redirect virt-builder to a temp file at
first (placed in the same directory as the finally expected disk image),
and rename that file upon success.

Signed-off-by: Laszlo Ersek <lersek at redhat.com>
---
 Makefile.am              |  5 ++-
 .gitignore               |  1 +
 make-physical-machine.sh | 37 ++++++++++++++++++++
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index d94ac6fdaf94..f25de74b8690 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -41,6 +41,7 @@ EXTRA_DIST = \
 	kiwi-config.xml.in \
 	launch-virt-p2v \
 	libguestfs/README \
+	make-physical-machine.sh \
 	miniexpect/README \
 	p2v.ks.in \
 	p2v.service \
@@ -66,6 +67,7 @@ CLEANFILES += \
 	$(generated_sources) \
 	$(PHYSICAL_MACHINE) $(BLANK_DISK) \
 	about-authors.c \
+	physical-machine.tmp.* \
 	stamp-test-virt-p2v-pxe-data-files \
 	stamp-test-virt-p2v-pxe-kernel \
 	test-virt-p2v-pxe.authorized_keys \
@@ -255,6 +257,7 @@ if HAVE_LIBGUESTFS
 check_DATA += \
 	$(PHYSICAL_MACHINE) \
 	$(BLANK_DISK)
+check_SCRIPTS = make-physical-machine.sh
 endif HAVE_LIBGUESTFS
 
 run-virt-p2v-directly: $(PHYSICAL_MACHINE)
@@ -317,7 +320,7 @@ run-virt-p2v-non-gui-conversion: $(PHYSICAL_MACHINE) stamp-test-virt-p2v-pxe-dat
 	SLOW=1 $(top_builddir)/run ./test-virt-p2v-pxe.sh
 
 $(PHYSICAL_MACHINE):
-	$(top_builddir)/run virt-builder --format raw -o $@ fedora-35
+	$(top_builddir)/run ./make-physical-machine.sh $@
 
 $(BLANK_DISK):
 	$(top_builddir)/run guestfish -N $@=part exit
diff --git a/.gitignore b/.gitignore
index a870e2b6186b..eea5128411c2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -41,6 +41,7 @@ Makefile.in
 /m4/ltsugar.m4
 /m4/ltversion.m4
 /p2v-config.h
+/physical-machine.tmp.*
 /podwrapper.pl
 /run
 /stamp-h1
diff --git a/make-physical-machine.sh b/make-physical-machine.sh
new file mode 100755
index 000000000000..fb42cda34fca
--- /dev/null
+++ b/make-physical-machine.sh
@@ -0,0 +1,37 @@
+#!/bin/bash -
+# Copyright (C) 2022 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+set -e -u -C
+
+disk=
+
+cleanup()
+{
+  set +e
+  if test -n "$disk"; then
+    rm -f -- "$disk"
+    disk=
+  fi
+}
+
+trap cleanup EXIT
+
+output=$1
+outdir=$(dirname -- "$output")
+disk=$(mktemp -p "$outdir" physical-machine.tmp.XXXXXXXXXX)
+virt-builder --format raw -o "$disk" fedora-35
+mv -- "$disk" "$output"
+disk=



More information about the Libguestfs mailing list