File vnfs-On-SUSE-don-t-copy-repository-information-into-chroot.patch of Package warewulf

From: Egbert Eich <eich@suse.com>
Date: Thu Feb 10 12:03:44 2022 +0100
Subject: vnfs: On SUSE don't copy repository information into chroot
Patch-mainline: Not yet
Git-commit: 6211ac13212607aab2f38276403e202df3610193
References: 

If neither ZYP_MIRROR nor INSTALL_ISO is set use repository
information and credentials on host system without copying
these into the chroot by using --installroot instead of
--root.

Signed-off-by: Egbert Eich <eich@suse.com>
---
 vnfs/libexec/wwmkchroot/include-suse | 45 +++++++++++++++++++++---------------
 1 file changed, 26 insertions(+), 19 deletions(-)
diff --git a/vnfs/libexec/wwmkchroot/include-suse b/vnfs/libexec/wwmkchroot/include-suse
index e6cad4c..3e5dcf4 100644
--- a/vnfs/libexec/wwmkchroot/include-suse
+++ b/vnfs/libexec/wwmkchroot/include-suse
@@ -1,4 +1,4 @@
-ZYP_CMD="zypper --root $CHROOTDIR -n --gpg-auto-import-keys"
+ZYP_CMD="zypper -n --gpg-auto-import-keys"
 
 distro_check() {
     if ! rpm -q zypper >/dev/null 2>&1 ; then
@@ -22,11 +22,20 @@ set_overlay() {
     elif [  -f "$CHROOTDIR/etc/SuSE-release" ]; then
         suse=1
     fi
-    if [ $no_suse -eq 1 ]; then
-        echo "ERROR: This must be a SuSE compatible chroot!"
-        return 1
+    if [ $suse -eq 0 ]; then
+        echo "ERROR: This must be a SUSE compatible chroot!"
+       return 1
+    fi
+    # If no repos are available in the chroot assume they've been taken from
+    # the host.
+    chrootarg="--root $CHROOTDIR"
+    if [ -z "$ZYP_MIRROR" -a -z "$INSTALL_ISO" ]; then
+        echo "INFO: Taking repository information from running system"
+	chrootarg="--installroot $CHROOTDIR"
     fi
-    PKGR_CMD="$ZYP_CMD install --no-recommends --auto-agree-with-licenses $PKGLIST"
+    [ -n "$VERBOSE" ] && echo "Executing zypper with $chrootarg"
+    PKGR_CMD="$ZYP_CMD $chrootarg install --auto-agree-with-licenses $PKGLIST"
+
     return 0
 }
 
@@ -46,14 +55,13 @@ prechroot() {
     mkdir -p -m 755 $CHROOTDIR/dev
     rm -f $CHROOTDIR/dev/zero && mknod -m 666 $CHROOTDIR/dev/zero c 1 5
 
-    cp -rap /etc/zypp/zypper.conf $CHROOTDIR/etc
-    # Use repos of installed system
+     chrootarg="--root $CHROOTDIR"
+     # Use repos of installed system
     if [[ -z "$ZYP_MIRROR" && -z "$INSTALL_ISO" ]]; then
-        cp -rap /etc/zypp/repos.d $CHROOTDIR/etc/zypp
-        [ -d /etc/zypp/services.d ] && cp -rap /etc/zypp/services.d $CHROOTDIR/etc/zypp
-        [ -d /etc/zypp/credentials.d ] && cp -rap /etc/zypp/credentials.d $CHROOTDIR/etc/zypp
+         chrootarg="--installroot $CHROOTDIR"
     elif [ -n "$INSTALL_ISO" ]; then
-        # Use ISO
+       cp -rap /etc/zypp/zypper.conf $CHROOTDIR/etc
+       # Use ISO
         for mountpath in `ls -d $MEDIA_MOUNTPATH.*`; do
             if [ -z "$INSTALLDIRS" ]; then
                 if [ -d ${mountpath}/repodata ]; then
@@ -68,31 +76,30 @@ prechroot() {
             fi
         done
         ZYP_MIRROR=$INSTALLDIRS
+    else
+        cp -rap /etc/zypp/zypper.conf $CHROOTDIR/etc
     fi
-
+    [ -n "$VERBOSE" ] && echo "Executing zypper with $chrootarg"
     if [ -n "${ZYP_MIRROR}" ]; then
         declare -i i=0 cnt
-        cnt=$($ZYP_CMD lr | grep '|' | wc -l)
+        cnt=$($ZYP_CMD $chrootarg lr | grep '|' | wc -l)
         while [ $i -lt $cnt ]; do
-            $ZYP_CMD rr $i
+            $ZYP_CMD $chrootarg rr $i
             let i++
         done
 
         cnt=0
         for repourl in `echo $ZYP_MIRROR | sed -e 's/,/ /'`; do
-            $ZYP_CMD ar $repourl repo-$((cnt++))
+            $ZYP_CMD $chrootarg ar $repourl repo-$((cnt++))
         done
     fi
 
-    PKGR_CMD="$ZYP_CMD install --no-recommends --auto-agree-with-licenses $PKGLIST"
+    PKGR_CMD="$ZYP_CMD $chrootarg install --auto-agree-with-licenses $PKGLIST"
 
     return 0
 }
 
 postchroot() {
-    for mirror in `echo $ZYP_MIRROR | sed -e 's/,/ /'`; do
-        $ZYP_CMD rr $mirror
-    done
     touch $CHROOTDIR/fastboot
     return 0
 }
openSUSE Build Service is sponsored by