From dc67e9a6a35579ddde2363ae649a7d19a081a1aa Mon Sep 17 00:00:00 2001
From: aviau <alexandre@alexandreviau.net>
Date: Fri, 29 Jul 2016 10:44:37 -0400
Subject: [PATCH] deploy-packages: Don't fail when adding the same deb

When adding the same deb twice to the repository, deploy-packages fails.
This is due to reprepro complaining about adding two times the same deb
to the same architecture. This happens because we generate arch all
packages on both i386 and amd64. This patch tries to remove the package
before adding it. This is safer than ignoring the error as there is no
option to only ignore this type of error.

Change-Id: I397148f9e8efe6ca1a089644abbd86395fa5eaf4
Tuleap: #872
---
 scripts/deploy-packages.sh | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/scripts/deploy-packages.sh b/scripts/deploy-packages.sh
index bb2fa827..1c96d451 100755
--- a/scripts/deploy-packages.sh
+++ b/scripts/deploy-packages.sh
@@ -83,26 +83,30 @@ EOF
 ## Add packages to the repository ##
 ####################################
 
-# Sign the debs
-echo "##################"
-echo "## signing debs ##"
-echo "##################"
-
 for package in packages/${DISTRIBUTION}*/*.deb; do
+
+    # Sign the deb
+    echo "## signing: ${package} ##"
     dpkg-sig -k ${KEYID} --sign builder ${package}
-done
 
-# Include the debs
-echo "####################"
-echo "## including debs ##"
-echo "####################"
-for package in packages/${DISTRIBUTION}*/*.deb; do
+    # Include the deb
+    echo "## including ${package} ##"
+    package_name=$(dpkg -I ${package} | grep -m 1 Package: | awk '{print $2}')
+    package_arch=$(dpkg -I ${package} | grep -m 1 Architecture: | awk '{print $2}')
+    if [ ${package_arch} = "all" ]; then
+        # Removing to avoid the error of adding the same deb twice.
+        # This happens with arch all packages, which are generated in amd64 and i386.
+        reprepro --verbose --basedir ${DISTRIBUTION_REPOSITOIRY_FOLDER} remove ring ${package_name}
+    fi
     reprepro --verbose --basedir ${DISTRIBUTION_REPOSITOIRY_FOLDER} includedeb ring ${package}
 done
 
 # Rebuild the index
 reprepro --verbose --basedir ${DISTRIBUTION_REPOSITOIRY_FOLDER} export ring
 
+# Show the contents
+reprepro --verbose --basedir ${DISTRIBUTION_REPOSITOIRY_FOLDER} list ring
+
 #######################################
 ## create the manual download folder ##
 #######################################
-- 
GitLab