From 164d584731037190ee5d2e2fc4eb6af1efc2f3ee Mon Sep 17 00:00:00 2001
From: et7f3 <cadeaudeelie@gmail.com>
Date: Apr 15 2023 19:26:30 +0000
Subject: [PATCH 1/3] shellcheck: Apply lint for 2 files


---

diff --git a/rpmdev-newspec.in b/rpmdev-newspec.in
index 27af10f..b832fc2 100644
--- a/rpmdev-newspec.in
+++ b/rpmdev-newspec.in
@@ -61,8 +61,8 @@ usage() {
     types=
     if [[ -z $RPM_BUILD_ROOT ]] ; then
         indent="                     "
-        types=$(ls $SPECDIR/spectemplate-*.spec 2>/dev/null | \
-            sed 's,.*spectemplate-,,;s,\.spec$,,' | tr '\n' ' ' | \
+        types=$(find "${SPECDIR}" -maxdepth 1 -name 'spectemplate-*.spec' 2>/dev/null | \
+            sed 's,.*spectemplate-,,;s,\.spec$,,' | \
             fmt -w 60 | sed "s/^/$indent/")
         [[ -z $types ]] && types="${indent}None ($SPECDIR/spectemplate-*.spec)"
     fi
@@ -117,7 +117,7 @@ while [[ $1 ]] ; do
             specfile="$1"
             specfile_set=1
             case $specfile in
-                *.spec) [[ -z $appname ]] && appname="$(basename $1 .spec)" ;;
+                *.spec) [[ -z $appname ]] && appname="$(basename "${1}" .spec)" ;;
             esac
             ;;
         -m|--macros)
@@ -140,7 +140,7 @@ while [[ $1 ]] ; do
             ;;
         *.spec)
             [[ -z $specfile ]] && specfile="$1"
-            appname="$(basename $1 .spec)"
+            appname="$(basename "${1}" .spec)"
             ;;
         *)
             appname="$1"
@@ -162,7 +162,7 @@ else
         > /dev/stderr
 fi
 # major * 10000 + minor * 100 ( + micro perhaps later )
-rpmver=$(( $rpmmaj * 10000 + $rpmmin * 100 ))
+rpmver=$(( rpmmaj * 10000 + rpmmin * 100 ))
 
 specfilter=
 if [[ -z $spectype ]] ; then
@@ -299,7 +299,7 @@ else
     chlog="s|^%changelog\\s*|%changelog\\n* $(LC_ALL=C date --utc +'%a %b %d %Y') $(rpmdev-packager)\\n- |Mg"
 fi
 
-cat "$tempspec" | sed -rne "
+sed < "${tempspec}" -rne "
 1h
 1!H
 $ {
diff --git a/rpmdev-setuptree b/rpmdev-setuptree
index acd08d9..1e6ad17 100755
--- a/rpmdev-setuptree
+++ b/rpmdev-setuptree
@@ -16,18 +16,18 @@
 #       copyright (c) 2002 Owl River Company - Columbus OH
 #       info@owlriver.com -- GPL v.2
 #
-[ "x$1" = "x-d" ] && {
+[ "$1" = "-d" ] && {
     DEBUG="y"
     export DEBUG
     shift 1
 }
 #
-IAM=`id -un`
+IAM=$(id -un)
 #       returns bare username
 #
-PASSWDDIR=`grep ^$IAM: /etc/passwd | awk -F":" '{print $6}'`
+PASSWDDIR=$(grep ^"${IAM}": /etc/passwd | awk -F':' '{print $6}')
 HOMEDIR=${HOME:=$PASSWDDIR}
-[ ! -d $HOMEDIR ] && {
+[ ! -d "${HOMEDIR}" ] && {
     echo "ERROR: Home directory for user $IAM not found in /etc/passwd."
     exit 1
 }
@@ -36,12 +36,12 @@ HOMEDIR=${HOME:=$PASSWDDIR}
 #
 #
 RPMMACROS="$HOMEDIR/.rpmmacros"
-touch $RPMMACROS
+touch "${RPMMACROS}"
 #
 TOPDIR="%_topdir"
-ISTOP=`grep -c ^$TOPDIR $RPMMACROS`
-[ $ISTOP -lt 1 ] && {
-    cat <<\EOF >> $RPMMACROS
+ISTOP=$(grep -c ^"${TOPDIR}" "${RPMMACROS}")
+[ "${ISTOP}" -lt 1 ] && {
+    cat <<\EOF >> "${RPMMACROS}"
 
 %_topdir %(echo $HOME)/rpmbuild
 EOF
@@ -53,9 +53,9 @@ EOF
 #       echo "$MAKE  make" >> $RPMMACROS
 #       }
 #
-ISTOP=`grep -c ^%__arch_install_post $RPMMACROS`
-[ $ISTOP -lt 1 ] && {
-    cat <<\EOF >> $RPMMACROS
+ISTOP=$(grep -c ^%__arch_install_post "${RPMMACROS}")
+[ "${ISTOP}" -lt 1 ] && {
+    cat <<\EOF >> "${RPMMACROS}"
 
 %__arch_install_post \
     [ "%{buildarch}" = "noarch" ] || QA_CHECK_RPATHS=1 ; \
@@ -63,11 +63,11 @@ ISTOP=`grep -c ^%__arch_install_post $RPMMACROS`
     /usr/lib/rpm/check-buildroot
 EOF
 }
-RPMDIR=`rpm --eval "%{_rpmdir}"`
-SRCDIR=`rpm --eval "%{_sourcedir}"`
-SPECDIR=`rpm --eval "%{_specdir}"`
-SRPMDIR=`rpm --eval "%{_srcrpmdir}"`
-BUILDDIR=`rpm --eval "%{_builddir}"`
+RPMDIR=$(rpm --eval "%{_rpmdir}")
+SRCDIR=$(rpm --eval "%{_sourcedir}")
+SPECDIR=$(rpm --eval "%{_specdir}")
+SRPMDIR=$(rpm --eval "%{_srcrpmdir}")
+BUILDDIR=$(rpm --eval "%{_builddir}")
 [ "x$DEBUG" != "x" ] && {
     echo "$IAM       $HOMEDIR    $RPMMACROS"
     echo "$RPMDIR    $SRCDIR     $SPECDIR"
@@ -75,7 +75,7 @@ BUILDDIR=`rpm --eval "%{_builddir}"`
 }
 #
 for i in $RPMDIR $SRCDIR $SPECDIR $SRPMDIR $BUILDDIR ; do
-    [ ! -d $i ] && mkdir -p $i
+    [ ! -d "${i}" ] && mkdir -p "${i}"
 done
 #
 exit 0

From aa1bc4b0ac7eeb313a2ff0cb6b2a94af5b16ea60 Mon Sep 17 00:00:00 2001
From: et7f3 <cadeaudeelie@gmail.com>
Date: Apr 28 2023 22:51:07 +0000
Subject: [PATCH 2/3] rpmdev-setuptree: Reduce hardcoded path


---

diff --git a/rpmdev-setuptree b/rpmdev-setuptree
index 1e6ad17..6637aee 100755
--- a/rpmdev-setuptree
+++ b/rpmdev-setuptree
@@ -59,8 +59,8 @@ ISTOP=$(grep -c ^%__arch_install_post "${RPMMACROS}")
 
 %__arch_install_post \
     [ "%{buildarch}" = "noarch" ] || QA_CHECK_RPATHS=1 ; \
-    case "${QA_CHECK_RPATHS:-}" in [1yY]*) /usr/lib/rpm/check-rpaths ;; esac \
-    /usr/lib/rpm/check-buildroot
+    case "${QA_CHECK_RPATHS:-}" in [1yY]*) %{_rpmconfigdir}/check-rpaths ;; esac \
+    %{_rpmconfigdir}/check-buildroot
 EOF
 }
 RPMDIR=$(rpm --eval "%{_rpmdir}")

From 930a2776ba0d2e31f508d796d217fb27bcbbb169 Mon Sep 17 00:00:00 2001
From: et7f3 <cadeaudeelie@gmail.com>
Date: Apr 28 2023 22:51:27 +0000
Subject: [PATCH 3/3] rpmdev-setuptree: Don't repeat already existent macro


%{_topdir} is already defined at least by latest rpm so no need to redefine it
Also avoiding shell is faster so we choose the version of rpm %{getenv:HOME}/rpmbuild
https://access.redhat.com/documentation/fr-fr/red_hat_enterprise_linux/8/html/packaging_and_distributing_software/advanced-topics#using-the-custom-macros_more-on-macros

---

diff --git a/rpmdev-setuptree b/rpmdev-setuptree
index 6637aee..56f51f0 100755
--- a/rpmdev-setuptree
+++ b/rpmdev-setuptree
@@ -38,14 +38,14 @@ HOMEDIR=${HOME:=$PASSWDDIR}
 RPMMACROS="$HOMEDIR/.rpmmacros"
 touch "${RPMMACROS}"
 #
-TOPDIR="%_topdir"
-ISTOP=$(grep -c ^"${TOPDIR}" "${RPMMACROS}")
-[ "${ISTOP}" -lt 1 ] && {
+case $(rpm --eval '%{_topdir}') in
+  '%{_topdir}')
     cat <<\EOF >> "${RPMMACROS}"
 
-%_topdir %(echo $HOME)/rpmbuild
+%_topdir %{getenv:HOME}/rpmbuild
 EOF
-}
+  ;;
+esac
 #
 #MAKE="%make "
 #ISTOP=`grep -c ^$MAKE $RPMMACROS`

