[CentOS-devel] [PATCH] updated into_srpm.sh with cleaner logic

Tue Nov 11 22:42:52 UTC 2014
Pat Riehecky <riehecky at fnal.gov>

From: Pat Riehecky <riehecky at fnal.gov>

---
 into_srpm.sh |   33 ++++++++++++++++++++++-----------
 1 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/into_srpm.sh b/into_srpm.sh
index 922d899..5399dc9 100755
--- a/into_srpm.sh
+++ b/into_srpm.sh
@@ -174,35 +174,46 @@ fi
 
 SPECFILE=$(cd SPECS; ls *.spec)
 
+# determine automatically unless we've got one set
+if [[ "x${DIST}" == 'x' ]]; then
+    if [[ ${QUIET} -eq 1 ]]; then
+        DIST=$(return_disttag.sh -q)
+    else
+        DIST=$(return_disttag.sh)
+    fi
+fi
+
 # Determine if we are an SCL
 ISSCL=0
 if [[ ${ALLOWSCL} -eq 1 ]]; then
     mytestsclname='DA39A3EE5E6B4B0D3255BFEF95601890AFD80709'
-    mysclcheck=$(rpm --define "dist el" --define "scl ${mytestsclname}" -q --specfile "SPECS/${SPECFILE}" --qf '%{n}-%{v}-%{r}\n' 2>/dev/null | head -n 1)
+    mysclcheck=$(rpm --define "dist ${DIST}" --define "scl ${mytestsclname}" -q --specfile "SPECS/${SPECFILE}" --qf '%{n}-%{v}-%{r}\n' 2>/dev/null | head -n 1)
     echo ${mysclcheck} | grep -q ${mytestsclname}
     if [[ $? -eq 0 ]]; then
         ISSCL=1
-        SCLNAME=$(show_possible_srpms.sh | cut -d'-' -f1 | sort -u)
+        BASENAME=$(echo ${mysclcheck} | sed -e 's/DA39A3EE5E6B4B0D3255BFEF95601890AFD80709//')
+        RPMNAME=$(show_possible_srpms.sh | head -1)
+        SCLNAME=$(echo ${RPMNAME} | sed -e "s/${BASENAME}.src.rpm//")
         if [[ $(echo ${SCLNAME} | wc -l) -ne 1 ]]; then
             echo "$0 failed to determine unique SCL name" >&2
             echo "Found:"                                 >&2
             echo "${SCLNAME}"                             >&2
         fi
+
+        scl_check=$(rpm --define "dist ${DIST}" --define "scl ${SCLNAME}" -q --specfile "SPECS/${SPECFILE}" --qf '%{n}-%{v}-%{r}.src.rpm\n' 2>/dev/null | head -n 1)
+        if [[ "${RPMNAME}" != "${scl_check}" ]]; then
+            echo "$0 failed to verify SCL name" >&2
+            echo "Found:"                       >&2
+            echo "${SCLNAME}"                   >&2
+            echo "made:     ${scl_check}"       >&2
+            echo "expected: ${RPMNAME}"         >&2
+        fi
     fi
 fi
 
 # build our rpmopts list
 RPMOPTS="-bs --nodeps"
 
-# determine automatically unless we've got one set
-if [[ "x${DIST}" == 'x' ]]; then
-    if [[ ${QUIET} -eq 1 ]]; then
-        DIST=$(return_disttag.sh -q)
-    else
-        DIST=$(return_disttag.sh)
-    fi
-fi
-
 # put it all together
 if [[ ${ISSCL} -eq 1 ]]; then
     rpmbuild --define "%_topdir `pwd`" ${RPMOPTS} --define "%dist ${DIST}" --define "%scl ${SCLNAME}" SPECS/${SPECFILE}
-- 
1.7.1