From a38ac762f12e2e7fde431c7091cc33371aa53cc4 Mon Sep 17 00:00:00 2001
From: Manuel Torrinha <manuel.torrinha@tecnico.ulisboa.pt>
Date: Thu, 8 Aug 2019 12:12:19 +0100
Subject: [PATCH] Fixes DIB_DISTRIBUTION_MIRROR_UBUNTU_IGNORE matching when
 empty

 - DIB_DISTRIBUTION_MIRROR_UBUNTU_IGNORE matches when it is empty or not
 set and DIB_DISTRIBUTION_MIRROR is being used. Checking for it being
 set and not empty solves this.
 - Normalizing bash conditionals for readability

Closes-Bug: #1808359
Change-Id: I87853fcda4c8b29a3f1720a2778debeb3acc3a53
Signed-off-by: Manuel Torrinha <manuel.torrinha@tecnico.ulisboa.pt>
---
 .../elements/ubuntu/pre-install.d/01-set-ubuntu-mirror      | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/diskimage_builder/elements/ubuntu/pre-install.d/01-set-ubuntu-mirror b/diskimage_builder/elements/ubuntu/pre-install.d/01-set-ubuntu-mirror
index efde2784d..5b4bb18b8 100755
--- a/diskimage_builder/elements/ubuntu/pre-install.d/01-set-ubuntu-mirror
+++ b/diskimage_builder/elements/ubuntu/pre-install.d/01-set-ubuntu-mirror
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-if [ ${DIB_DEBUG_TRACE:-0} -gt 1 ]; then
+if [[ ${DIB_DEBUG_TRACE:-0} -gt 1 ]]; then
     set -x
 fi
 set -eu
@@ -8,11 +8,11 @@ set -o pipefail
 
 DIB_DISTRIBUTION_MIRROR=${DIB_DISTRIBUTION_MIRROR:-}
 
-[ -n "$DIB_DISTRIBUTION_MIRROR" ] || exit 0
+[[ -n "$DIB_DISTRIBUTION_MIRROR" ]] || exit 0
 
 while IFS= read line
 do
-    if [[ "$line" =~ ${DIB_DISTRIBUTION_MIRROR_UBUNTU_IGNORE:-} ]]; then
+    if [[ -n "${DIB_DISTRIBUTION_MIRROR_UBUNTU_IGNORE:-}" && "$line" =~ ${DIB_DISTRIBUTION_MIRROR_UBUNTU_IGNORE:-} ]]; then
         # append line unmodified
         echo "$line" | tee --append /etc/apt/sources.list.new
     else