Tony's Diary

Tue, 27 May 2008

Experiments in Fedora 0x01

Running your own local yum repo isn't all that hard as it turns out.

  1. Allow building as a non-root user.
    1. Make some important directories. I only care about powerpc packages, so I make the ppc and ppc64 directories, clearly if you use another architecture you should change that ;P
      mkdir -p /home/user/rpmbuild/fedora/{BUILD,SOURCES,SPECS,SRPMS,tmp,RPMS/{noarch,ppc,ppc64}}
      
    2. Now create a ~/.rpmmacros file. To use those directories you just created.
      %_topdir        /home/user/rpmbuild/fedora/
      %_builddir      %{_topdir}/BUILD
      %_rpmdir        %{_topdir}/RPMS
      %_specdir       %{_topdir}/SPECS
      %_srcrpmdir     %{_topdir}/SRPMS
      %_sourcedir     %{_topdir}/SOURCES/%{name}-%{version}-%{release}
      %_tmppath       %{_topdir}/tmp
      %_buildroot     %{_topdir}/%{_tmppath}/%{name}-%{version}-root
      %packager       user@example.com
      
      With this there you can rpm -i src.rpm files, and run rpmbuild commands to generate RPMS (binary and source). I intend to have a bunch of packages on the go at any time so I use the %_sourcedir macro, have one directory per %{name}-%{version}-%{release}. You could just as easily do:
      %_sourcedir     %{_topdir}/SOURCES
      
      It's easiest to decide upfront as changing will be a little cumbersome.
  2. Make some RPMS. True this can be a little challenging at times but fortunately the packages I'm interested presented little challenge ... woot!
  3. Fedora has a util for rummaging through RPMs and makeing the repodata files. It's called createrepo. So install that: yum install -y createrepo
  4. I then moved all my locally built RPMS into a separate directory structure. I tried to make this look at least a little like real Fedora repos. Again I only care about powerpc, hence setting $basearch. You don't need to :). In case it isn't obvious I ran this script from the root directory of the repo (in my case /opt/yum).
    #!/bin/sh
    
    basearch=ppc
    releasever=9
    rpmbuild_base=/home/user/rpmbuild/fedora
    
    for i in local local-debuginfo local-source ; do
            d="$i/$releasever/$basearch"
            [ ! -d $d ] && mkdir -p $d
    done
    
    find $rpmbuild_base/RPMS/  -type f \
    	-exec /bin/cp {} ./local/$releasever/$basearch/. \;
    find $rpmbuild_base/SRPMS/ -type f \
    	-exec /bin/cp {} ./local-source/$releasever/$basearch/. \;
    find ./local/$releasever/$basearch/. -type f -name '*debug*' \
    	-exec /bin/mv {} ./local-debuginfo/$releasever/$basearch/. \;
    
    for i in local local-debuginfo local-source ; do
            cd "$i/$releasever/$basearch"
            /usr/bin/createrepo .
            cd -
    done
    
  5. Setup apache to serve up that directory. This machine shouldn't need any other web services, so I just make / point at my /opt/yum directory
    NameVirtualHost *
    <VirtualHost *>
        ServerAdmin user@example.com
        DocumentRoot /opt/yum/
        ServerAlias host
        ServerName host.example.com
        ErrorLog /var/log/httpd/yum.repo-error_log
        CustomLog /var/log/httpd/yum.repo-access_log combined
    
        <Directory /opt/yum>
            Options Indexes
        </Directory>
    </VirtualHost>
    
  6. Now create a yum config you use this new goodness.
    [local]
    name=local $releasever - $basearch
    baseurl=http://host.example.com/local/$releasever/$basearch/
    enabled=1
    gpgcheck=0
    
    [local-debuginfo]
    name=local $releasever - $basearch - Debug
    baseurl=http://host.example.com/local-debuginfo/$releasever/$basearch/
    enabled=1
    gpgcheck=0
    
    [local-source]
    name=local $releasever - $basearch - Source
    baseurl=http://host.example.com/local-source/$releasever/$basearch/
    enabled=1
    gpgcheck=0
    
  7. If that all went well then:
    [user@host ~]$ yum repolist
    Loaded plugins: refresh-packagekit
    repo id              repo name                                 status
    fedora               Fedora 9 - ppc                            enabled
    fedora-debuginfo     Fedora 9 - ppc - Debug                    enabled
    fedora-source        Fedora 9 - Source                         enabled
    local                local 9 - ppc                             enabled
    local-debuginfo      local 9 - ppc - Debug                     enabled
    local-source         local 9 - ppc - Source                    enabled
    updates              Fedora 9 - ppc - Updates                  enabled
    updates-debuginfo    Fedora 9 - ppc - Updates - Debug          enabled
    updates-source       Fedora 9 - Updates Source                 enabled
    

    and debuginfo-install and yumdownloader should do the right things woot!

There are probabluy all sorts of other cool things you can do here but this is enought to keep a few local machines in sync :)

Update: Type fixes, and add note about installign createrepo

[/geek] permanent link

Tue, 20 May 2008

Experiments in Fedora 0x00

So it's been a long time since I used RPM based distro "in anger", so I'm trying Fedora 9. First tips

Note: These may not be the best ways to get the job done but they worked for me

Update: fix typos

[/geek] permanent link