diff mbox series

[3/5] guestfs: bringup: fix unbound variable when debug

Message ID 20241015-bringup-guestfs-debug-v1-3-bd74c0c31412@samsung.com (mailing list archive)
State New
Headers show
Series guestfs: bringup: add debug mode | expand

Commit Message

Daniel Gomez via B4 Relay Oct. 15, 2024, 11:34 a.m. UTC
From: Daniel Gomez <da.gomez@samsung.com>

Fix unbound variable errors. This is a silent error only found while
debugging. A variable may not be set, so check if set before comparing
the value to avoid 'unbound variable' error.

++ mktemp
+ cmdfile=/tmp/tmp.cn0hNYMZbt
+ '[' '!' -f /var/lib/libvirt/images/kdevops/guestfs/base_images/debian-12.raw ']'
.//scripts/bringup_guestfs.sh: line 289: CONFIG_GUESTFS_HAS_CUSTOM_RAW_IMAGE: unbound variable
make: *** [scripts/guestfs.Makefile:77: bringup_guestfs] Error 1

Signed-off-by: Daniel Gomez <da.gomez@samsung.com>
---
 scripts/bringup_guestfs.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/scripts/bringup_guestfs.sh b/scripts/bringup_guestfs.sh
index 5786975e48647321ecbc71ca9be6fb09c8aa63ff..19117e9a6ab55cfbe7c79f17e4a9b736edeb2607 100755
--- a/scripts/bringup_guestfs.sh
+++ b/scripts/bringup_guestfs.sh
@@ -242,7 +242,7 @@  _EOT
 	# For the life of me I can't get the following line to work with
 	# the virt-builder command and so we do a full edit of the file for now
 	# edit /etc/nsswitch.conf:'s/\[!UNAVAIL=return\]//'
-	if [[ "$CONFIG_GUESTFS_DEBIAN_TRIXIE" == "y" ]]; then
+	if [[ "${CONFIG_GUESTFS_DEBIAN_TRIXIE+x}" && "$CONFIG_GUESTFS_DEBIAN_TRIXIE" == "y" ]]; then
 		cat <<_EOT >>$cmdfile
 write /etc/nsswitch.conf: # kdevops generated /etc/nsswitch.conf
 append-line /etc/nsswitch.conf:passwd:         files
@@ -266,7 +266,7 @@  firstboot-command DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=tru
 firstboot-command systemctl stop ssh
 firstboot-command systemctl start ssh
 _EOT
-		if [[ "$CONFIG_GUESTFS_COPY_SOURCES_FROM_HOST_TO_GUEST" == "y" ]]; then
+		if [[ "${CONFIG_GUESTFS_COPY_SOURCES_FROM_HOST_TO_GUEST+x}" && "$CONFIG_GUESTFS_COPY_SOURCES_FROM_HOST_TO_GUEST" == "y" ]]; then
 		cat <<_EOT >>$cmdfile
 delete /etc/apt/sources.list.d/debian.sources
 _EOT
@@ -292,7 +292,7 @@  fi
 cmdfile=$(mktemp)
 
 if [ ! -f $BASE_IMAGE ]; then
-	if [[ "$CONFIG_GUESTFS_HAS_CUSTOM_RAW_IMAGE" == "y" ]]; then
+	if [[ "${CONFIG_GUESTFS_HAS_CUSTOM_RAW_IMAGE+x}" && "$CONFIG_GUESTFS_HAS_CUSTOM_RAW_IMAGE" == "y" ]]; then
 		build_custom_image
 	fi
 
@@ -305,7 +305,7 @@  if [ ! -f $BASE_IMAGE ]; then
 		copy_yum_repo
 	fi
 
-	if [[ "$CONFIG_GUESTFS_COPY_SOURCES_FROM_HOST_TO_GUEST" == "y" ]]; then
+	if [[ "${CONFIG_GUESTFS_COPY_SOURCES_FROM_HOST_TO_GUEST+x}" && "$CONFIG_GUESTFS_COPY_SOURCES_FROM_HOST_TO_GUEST" == "y" ]]; then
 		copy_host_sources
 	fi
 
@@ -360,7 +360,7 @@  do
 	TZ="$(timedatectl show -p Timezone --value)"
 	$USE_SUDO virt-sysprep -a $ROOTIMG --hostname $name --ssh-inject "kdevops:file:$SSH_KEY.pub" --timezone $TZ
 
-	if [[ "$CONFIG_LIBVIRT_ENABLE_LARGEIO" == "y" ]]; then
+	if [[ "${CONFIG_LIBVIRT_ENABLE_LARGEIO+x}" && "$CONFIG_LIBVIRT_ENABLE_LARGEIO" == "y" ]]; then
 		lbs_idx=0
 		for i in $(seq 1 $(($CONFIG_QEMU_LARGEIO_MAX_POW_LIMIT+1))); do
 			for x in $(seq 0 $CONFIG_QEMU_EXTRA_DRIVE_LARGEIO_NUM_DRIVES_PER_SPACE); do