[Yum] Removable media support in yum

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In attachment a patch what help users work with repositories on 
removable media
(i test it on RH9 disks).
Steps to get it work:
1) Make yum package with this patch.
   (Also you can get my customized package from
   http://stuphead.asplinux.ru/lj/yum-2.0.3cvs-5asp.src.rpm, rebuild and 
install
   it and then remove files from /etc/yum.d, cause it's prepared for my 
distro).

2.0) mount your RH9 CD1 and execute
     yum-arch -Rredhat9cd1 /mnt/cdrom
2.1) mount your RH9 CD2 and execute
     yum-arch -Rredhat9cd2 /mnt/cdrom
2.2) mount your RH9 CD3 and execute
     yum-arch -Rredhat9cd3 /mnt/cdrom

3) add this to your yum config file
   (in your case is /etc/yum.conf, in my - just new file in /etc/yum.d 
directory)
[redhat9cd1]
baseurl=removable:///mnt/cdrom
name=RedHat9 disk 1
[redhat9cd2]
baseurl=removable:///mnt/cdrom
name=RedHat9 disk 2
[redhat9cd3]
baseurl=removable:///mnt/cdrom
name=RedHat9 disk 3

4) it's all. now  try to install something.
-------------------------------------------------
Additional functionality:
    new variables in yum.conf [main]:
        mountcommand - command what you use to mount directory (default: 
mount)
        umountcommand - command what you use to unmount directory 
(default: eject)
    new variables in yum.conf [repositories]:
        mountpoint - mount point for this repository if its use 
'removable' scheme (default: /mnt/cdrom)
------------------------------------------------
Thanks Seth for great piece of code - this patch is only 9kb long!


-- 
..............................................................
IRC: irc.freenode.net #asplinux                Grigory Bakunov
ICQ: 51369901                        ASPLinux Development Team
Life would be so much easier if
                        we could just look at the source code.

-------------- next part --------------
diff -BurN yum-2.0.3cvs.old/clientStuff.py yum-2.0.3cvs/clientStuff.py
--- yum-2.0.3cvs.old/clientStuff.py	2003-10-14 12:54:54.000000000 +0400
+++ yum-2.0.3cvs/clientStuff.py	2003-10-14 15:02:10.000000000 +0400
@@ -27,6 +27,7 @@
 import rpmUtils
 import time
 import urlparse
+import commands
 
 import urlgrabber
 from urlgrabber import close_all, urlgrab, URLGrabError, retrygrab
@@ -618,8 +619,23 @@
             return 1
         else:
             return 0
-        
 
+def userDiskAsk(diskname, mountpoint, filename):
+    """Ask user to insert disk with file"""
+    if os.path.isfile(filename):
+        return 1
+    choice = raw_input('Insert disk "%s" and press enter\n' % diskname)
+    if not os.path.ismount(mountpoint):
+        output = commands.getstatusoutput(conf.mountcommand + ' ' + mountpoint)
+        if output[0] != 0:
+            errorlog(2, 'Mount error: %s' % output[1])
+            return userDiskAsk(diskname, mountpoint, filename)
+    if os.path.isfile(filename):
+        return 1
+    else:
+        log(2, 'Wrong disk!')
+        output = commands.getstatusoutput(conf.umountcommand + ' ' + mountpoint)        
+        return userDiskAsk(diskname, mountpoint, filename)
 
 def nasort((n1, a1), (n2, a2)):
     if n1 > n2:
@@ -1141,6 +1157,11 @@
         try:
             (scheme, host, path, parm, query, frag) = urlparse.urlparse(base)
             path = os.path.normpath(path + '/' + filepath)
+            if scheme == 'removable':
+                if os.path.isfile(filename):
+                    return filename
+                userDiskAsk(conf.servername[serverID], conf.servermountpoint[serverID], os.path.join(host, path))
+                scheme = 'file'
             finalurl = urlparse.urlunparse((scheme, host, path, parm, query, frag))
             return retrygrab(finalurl, filename, copy_local,
                              close_connection, progress_obj, throttle,
diff -BurN yum-2.0.3cvs.old/config.py yum-2.0.3cvs/config.py
--- yum-2.0.3cvs.old/config.py	2003-10-14 12:54:54.000000000 +0400
+++ yum-2.0.3cvs/config.py	2003-10-14 15:23:20.000000000 +0400
@@ -62,6 +62,7 @@
         self.servername = {}
         self.serverurl = {}
         self.serverpkgdir = {}
+        self.servermountpoint = {}
         self.serverhdrdir = {}
         self.servercache = {}
         self.servergpgcheck={}
@@ -98,6 +99,8 @@
                            'kernel-smp', 'kernel-debug', 'kernel-unsupported']
         self.kernelpkgnames = ['kernel','kernel-smp','kernel-enterprise',
                            'kernel-bigmem','kernel-BOOT']
+        self.mountcommand  = '/bin/mount'
+        self.umountcommand = '/usr/bin/eject'
       
         if self._getoption('main','cachedir') != None:
             self.cachedir = self._getoption('main','cachedir')
@@ -129,6 +132,10 @@
             self.retries = self.cfg.getint('main','retries')
         if self._getoption('main', 'installroot') != None:
             self.installroot = self._getoption('main','installroot')
+        if self._getoption('main', 'mountcommand') != None:
+            self.mountcommand = self.cfg._getoption('main','mountcommand')
+        if self._getoption('main', 'umountcommand') != None:
+            self.umountcommand = self.cfg._getoption('main','umountcommand')
 
             
         # figure out what the releasever really is from the distroverpkg
@@ -187,6 +194,10 @@
                             self.servergpgcheck[section]=self.cfg.getboolean(section,'gpgcheck')
                         else:
                             self.servergpgcheck[section]=0
+                        if self._getoption(section,'mountpoint') != None:
+                            self.servermountpoint[section] = self._getoption(section,'mountpoint')
+                        else:
+                            self.servermountpoint[section] = '/mnt/cdrom'
                         if self._getoption(section, 'exclude') != None:
                             srvexcludelist = self._getoption(section, 'exclude')
                             srvexcludelist = self._doreplace(srvexcludelist)
@@ -197,9 +208,9 @@
                         
                         for url in self.serverurl[section]:
                             (s,b,p,q,f,o) = urlparse.urlparse(url)
-                            # currently only allowing http and ftp servers 
-                            if s not in ['http', 'ftp', 'file', 'https']:
-                                print _('using ftp, http[s], or file for servers, Aborting - %s') % (url)
+                            # currently only allowing http and ftp servers
+                            if s not in ['http', 'ftp', 'file', 'https', 'removable']:
+                                print _('using ftp, http[s], removable or file for servers, Aborting - %s') % (url)
                                 sys.exit(1)
 
                         cache = os.path.join(self.cachedir,section)
diff -BurN yum-2.0.3cvs.old/docs/yum-arch.8 yum-2.0.3cvs/docs/yum-arch.8
--- yum-2.0.3cvs.old/docs/yum-arch.8	2003-10-14 12:43:58.000000000 +0400
+++ yum-2.0.3cvs/docs/yum-arch.8	2003-10-14 15:04:01.000000000 +0400
@@ -20,6 +20,8 @@
 don't generate headers.
 .IP "\fB\-s\fP"
 generate headers for source packages too.
+.IP "\fB\-Rname\fP"
+generate header for removable repository "name".
 .IP "\fB\-q\fP"
 make output more quiet.
 .IP "\fB\-c\fP"
diff -BurN yum-2.0.3cvs.old/docs/yum.conf.5 yum-2.0.3cvs/docs/yum.conf.5
--- yum-2.0.3cvs.old/docs/yum.conf.5	2003-10-14 12:43:58.000000000 +0400
+++ yum-2.0.3cvs/docs/yum.conf.5	2003-10-14 15:19:09.000000000 +0400
@@ -84,6 +84,13 @@
 in particular fall into this category. Defaults to kernel, kernel-smp,
 kernel-bigmem, kernel-enterprise, kernel-debug, kernel-unsupported.
 
+.IP \fBmountcommand \fR
+command what yum execute when need to mount removable media. default is /bin/mount
+
+.IP \fBumountcommand \fR
+command what yum execute when need to unmount removable media. default is /bin/umount
+
+
 .SH "[server] options"
 .LP 
 The server section(s) take the following form:
@@ -102,7 +109,8 @@
 
 .IP \fBbaseurl\fR
 must be a url to the directory where the yum repository's 'headers' directory lives.
-Can be an http://, ftp:// or file:// url.
+Can be an http://, ftp://, removable:// or file:// url.
+Repositories with scheme 'removable:' must be created by 'yum-arch -R' command.
 You can specify multiple urls in one baseurl statement. The best way to do
 this is like this:
 .br
@@ -141,6 +150,11 @@
 same as the [main] exclude but this is only for this server
 variables, listed below, are honored here.
 
+.IP \fBmountpoint\fR
+mounted directory with removable media.
+Warning, this directory will be mounted with "mount mountpoint" command
+so you need to add it to fstab
+
 .SH "VARIABLES"
 .LP
 There are a number of variables you can use to ease maintenance of the
diff -BurN yum-2.0.3cvs.old/pullheaders.py yum-2.0.3cvs/pullheaders.py
--- yum-2.0.3cvs.old/pullheaders.py	2003-10-14 12:54:54.000000000 +0400
+++ yum-2.0.3cvs/pullheaders.py	2003-10-14 14:29:37.000000000 +0400
@@ -33,15 +33,6 @@
 serverStuff.ts = ts
 
 def main():
-    tempheaderdir = '.newheaders'
-    tempheaderinfo = tempheaderdir + '/' + 'header.info'
-    tempsrcheaderinfo = tempheaderdir + '/' + 'header.src.info'
-    oldheaderdir = '.oldheaders'
-    oldheaderinfo = oldheaderdir + '/' + 'header.info'
-    oldsrcheaderinfo = oldheaderdir + '/' + 'header.src.info'
-    headerdir = 'headers'
-    headerinfo = headerdir + '/' + 'header.info'
-    srcheaderinfo = headerdir + '/' + 'header.src.info'
     if  len(sys.argv) < 2:
         serverStuff.Usage()
     cmds = {}
@@ -51,6 +42,7 @@
     cmds['compress'] = 1
     cmds['usesymlinks'] = 0
     cmds['dosrpms'] = 0
+    cmds['removable'] = None
     cmds['quiet'] = 0
     cmds['loud'] = 0
     args = sys.argv[1:]
@@ -71,6 +63,8 @@
             cmds['usesymlinks'] = 1
         elif arg == "-s":
             cmds['dosrpms'] = 1
+        elif arg[:2] == "-R":
+            cmds['removable'] = arg[2:]
         elif arg == "-q":
             cmds['quiet'] = 1
             log.threshold = 1
@@ -79,6 +73,27 @@
             log.threshold = 4
         if arg in ['-h','--help']:
             serverStuff.Usage()
+
+    if cmds['removable'] != None:
+        cachedir = '/var/cache/yum/' + cmds['removable']
+        tmp = '/var/tmp/'
+        tempheaderdir = tmp + '.newheaders'
+        oldheaderdir = tmp + '.oldheaders'
+        checkandMakeDir(cachedir)
+        headerdir = cachedir + '/headers'
+    else:
+        tempheaderdir = '.newheaders'
+        oldheaderdir = '.oldheaders'
+        headerdir = 'headers'
+
+    tempheaderinfo = tempheaderdir + '/' + 'header.info'
+    tempsrcheaderinfo = tempheaderdir + '/' + 'header.src.info'
+    oldheaderinfo = oldheaderdir + '/' + 'header.info'
+    oldsrcheaderinfo = oldheaderdir + '/' + 'header.src.info'
+    headerinfo = headerdir + '/' + 'header.info'
+    srcheaderinfo = headerdir + '/' + 'header.src.info'
+
+        
     # save where we are right now
     curdir = os.getcwd()
     # start the sanity/stupidity checks
@@ -186,6 +201,12 @@
         removeHeaderInfo(oldsrcheaderinfo)
         os.rmdir(oldheaderdir)
 
+    if cmds['removable'] != None:
+        try:
+            os.rename(headerinfo, cachedir + '/header.info')
+        except OSError, e:
+            print _("Error moving header.info file to cache directory")
+            sys.exit(1)
     # take us home mr. data
     os.chdir(curdir)
 

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux