[customize_image] Override infra mirror only if set

Follow up of [1], in local setup it's not needed
as mirrors not set.

[1] https://review.opendev.org/c/openstack/neutron-tempest-plugin/+/954240
Related-Bug: #2110191

Change-Id: Id73d1a2f66a6376dcd4c91ea01524ebd133c44c3
Signed-off-by: yatinkarel <ykarel@redhat.com>
diff --git a/tools/customize_ubuntu_image b/tools/customize_ubuntu_image
index 1ded664..438d97e 100755
--- a/tools/customize_ubuntu_image
+++ b/tools/customize_ubuntu_image
@@ -69,17 +69,19 @@
     bind_dir "/sys" "${mount_dir}/sys"
     if [ -f /etc/apt/sources.list ]; then
       mirror=$(grep -oP 'https?://\K[^/ ]+' /etc/apt/sources.list|head -1)
-      if sudo test -f ${mount_dir}/etc/apt/sources.list.d/ubuntu.sources; then
-          sudo sed -Ei "s|(http[s]?://)([^/]+)|\1${mirror}|g" ${mount_dir}/etc/apt/sources.list.d/ubuntu.sources
-          sudo sed -i "/URIs:/a Trusted: yes" ${mount_dir}/etc/apt/sources.list.d/ubuntu.sources
-      elif sudo test -f ${mount_dir}/etc/apt/sources.list; then
-          source <(sudo cat ${mount_dir}/etc/os-release)
-          sudo tee ${mount_dir}/etc/apt/sources.list <<EOF
-          deb [ trusted=yes ] https://${mirror}/ubuntu ${UBUNTU_CODENAME} main universe
-          deb [ trusted=yes ] https://${mirror}/ubuntu ${UBUNTU_CODENAME}-updates main universe
-          deb [ trusted=yes ] https://${mirror}/ubuntu ${UBUNTU_CODENAME}-backports main universe
-          deb [ trusted=yes ] https://${mirror}/ubuntu ${UBUNTU_CODENAME}-security main universe
+      if [ -n "${mirror}" ]; then
+          if sudo test -f ${mount_dir}/etc/apt/sources.list.d/ubuntu.sources; then
+              sudo sed -Ei "s|(http[s]?://)([^/]+)|\1${mirror}|g" ${mount_dir}/etc/apt/sources.list.d/ubuntu.sources
+              sudo sed -i "/URIs:/a Trusted: yes" ${mount_dir}/etc/apt/sources.list.d/ubuntu.sources
+          elif sudo test -f ${mount_dir}/etc/apt/sources.list; then
+              source <(sudo cat ${mount_dir}/etc/os-release)
+              sudo tee ${mount_dir}/etc/apt/sources.list <<EOF
+              deb [ trusted=yes ] https://${mirror}/ubuntu ${UBUNTU_CODENAME} main universe
+              deb [ trusted=yes ] https://${mirror}/ubuntu ${UBUNTU_CODENAME}-updates main universe
+              deb [ trusted=yes ] https://${mirror}/ubuntu ${UBUNTU_CODENAME}-backports main universe
+              deb [ trusted=yes ] https://${mirror}/ubuntu ${UBUNTU_CODENAME}-security main universe
 EOF
+          fi
       fi
     fi