--- pilgrim.py.prepatch-yumcache	2007-08-05 18:42:47.000000000 +0200
+++ pilgrim.py	2007-08-05 18:51:59.000000000 +0200
@@ -188,10 +188,10 @@
         # being left and an inability to clean up after ourself
         pass
 
-    def _writeConf(self, datadir, installroot):
+    def _writeConf(self, datadir, installroot, cachedir):
         conf  = "[main]\n"
         conf += "installroot=%s\n" % installroot
-        conf += "cachedir=/var/cache/yum\n"
+        conf += "cachedir=%s\n" % cachedir
         conf += "plugins=0\n"
         conf += "reposdir=\n"
 
@@ -205,8 +205,8 @@
 
         return path
 
-    def setup(self, datadir, installroot):
-        self.doConfigSetup(fn = self._writeConf(datadir, installroot),
+    def setup(self, datadir, installroot, cachedir):
+        self.doConfigSetup(fn = self._writeConf(datadir, installroot, cachedir),
                            root = installroot)
         self.conf.cache = 0
         self.doTsSetup()
@@ -395,7 +395,7 @@
         fstab.write("sysfs                   /sys                    sysfs   defaults        0 0\n")
         fstab.close()
 
-    def setup(self, image_size, base_on = None, build_dir = None, yum_installroot = None):
+    def setup(self, image_size, base_on = None, build_dir = None, yum_installroot = None, yum_cachedir=None):
         """setup target ext3 file system in preparation for an install"""
 
         # setup temporary build dirs
@@ -419,7 +419,12 @@
         else:
             os.symlink(yum_installroot,self.build_dir + "/install_root")
 
-        os.makedirs(self.build_dir + "/yum-cache")
+        # Create a yum cache directory only if needed, or set it to the correct directory
+        if not yum_cachedir:
+            os.makedirs(self.build_dir + "/yum-cache")
+# Don't know if this is usefull for others, revisor doesn't need it
+#        else:
+#            os.symlink(yum_cachedir, self.build_dir + "/yum-cache")
 
         if base_on:
             # get backing ext3 image if we're based this build on an existing live CD ISO
@@ -451,10 +456,15 @@
 
         # bind mount system directories into install_root/
         for (f, dest) in [("/sys", None), ("/proc", None), ("/dev", None),
-                          ("/dev/pts", None), ("/selinux", None),
-                          (self.build_dir + "/yum-cache", "/var/cache/yum")]:
+                          ("/dev/pts", None), ("/selinux", None)]:
             self.bindmounts.append(BindChrootMount(f, self.build_dir + "/install_root", dest))
 
+        if not yum_cachedir:
+            self.bindmounts.append(BindChrootMount(self.build_dir + "/yum-cache", self.build_dir + "/install_root", "/var/cache/yum"))
+            cachedir = "/var/cache/yum"
+        else:
+            cachedir = yum_cachedir
+
         for b in self.bindmounts:
             b.mount()
 
@@ -465,7 +475,9 @@
 
         self.ayum = LiveCDYum()
         self.ayum.setup(self.build_dir + "/data",
-                        self.build_dir + "/install_root")
+                        self.build_dir + "/install_root",
+                        cachedir
+                        )
 
     def unmount(self):
         """detaches system bind mounts and install_root for the file system and tears down loop devices used"""
@@ -1049,6 +1061,7 @@
                       [--shell]
                       [--builddir]
                       [--installroot]
+                      [--yumcache]
                       [--tmpdir=<tmpdir>]
 
  --help              : Print usage and exit
@@ -1064,6 +1077,7 @@
  --ignore-deleted    : Don't run resize2fs to clean up wasted blocks
  --builddir          : Use this build directory
  --installroot       : Use this directory as installroot
+ --yumcache          : Use this yum cache directory
  --shell             : Start a shell in the chroot for post-configuration
  --tmpdir            : Temporary directory to use (default: /var/tmp)
 
@@ -1098,16 +1112,17 @@
         self.give_shell = False
         self.build_dir = None
         self.install_root = None
+        self.yum_cache = None
         self.tmpdir = "/var/tmp"
 
 def parse_options(args):
     try:
-        opts, args = getopt.getopt(args, "hr:b:p:e:f:c:su:lt:bd:i",
+        opts, args = getopt.getopt(args, "hr:b:p:e:f:c:su:lt:bd:i:y:",
                                    ["help", "repo=", "base-on=", "package=",
                                     "exclude-package=", "fslabel=", "config=",
                                     "skip-compression", "uncompressed-size=",
                                     "ignore-deleted", "shell", "no-prelink",
-                                    "build_dir=", "install_root=",
+                                    "build_dir=", "install_root=", "yum_cache",
                                     "prelink", "tmpdir="])
 
     except getopt.GetoptError, msg:
@@ -1176,6 +1191,9 @@
         if o in ("-i", "--installroot"):
             options.install_root = a
             continue
+        if o in ("-y", "--yumcache"):
+            options.yum_cache = a
+            continue
         raise Usage("Unknown option %s" % o)
 
     if not options.kscfg and not (options.packages or options.groups):
@@ -1217,7 +1235,7 @@
     try:
         target.parse(options.kscfg)
 
-        target.setup(options.uncompressed_size, options.base_on, build_dir=options.build_dir, yum_installroot=options.install_root)
+        target.setup(options.uncompressed_size, options.base_on, build_dir=options.build_dir, yum_installroot=options.install_root, yum_cachedir=options.yum_cache)
 
         target.install()
 
