RPM help

OK, I must be doing something wrong here, so if you are familiar with building rpms and can help me out, please do!

I am trying to build an rpm which has (for the sake of discussion) a script file in it that I want to install. The first thing I did was to install the rpm-build package so I had the correct tools. Afterwards I made an rpm directory to contain my rpm build trials, and under that dir, other dirs of BUILD, RPMS, SOURCES, SPECS and SRPMS to house my code, etc., as required by the “rpmbuild” program.

I go to ~/rpm/SOURCES and make a dir myscript-1 and in that dir I place my script “myscript”. Back in ~/rpm/SOURCES I create the requisite tar file “tar czvf myfile-1.tar.gz myfile-1”.

Now, I flip over to ~/rpm/SPECS to create the spec file myscript.spec, which looks like so:

Summary: Lincs Myscript
Name: myscript
Version: 1
Release: 1
Source0: myscript-1.tar.gz
License: GPL
Group: LINC
%description
This script does things.
%prep
%setup -q
%build
%install
install -m 0755 myscript /usr/local/bin/myscript
%post
echo "HA, yur dun!"
%files
/usr/local/bin/myscript

Now I can go to ~/rpm and actually create the rpm by doing:
sudo rpmbuild -ba –target noarch SPECS/myscript.spec
and this will indeed make an installable rpm file of myscript-1-1.noarch.rpm in the ~/rpm/RPMS/noarch/ directory. All this is fine and what I want EXCEPT:

While building the rpm, the process seems to BUILD/INSTALL everything on the local system as well. This means that after the build, I end up with an /usr/local/bin/myscript even though the package has not been installed on my system. Now for my purposes now, it’s not that big of a deal, however, I am sure there are times that I will NOT want to have the package I am building installed on the same machine. There just has to be a way around this that I cannot find so far and it’s annoying me to no end. HELP! 🙂

4 Comments

  • vpv says:

    You haven’t defined an RPM buildroot, which means the build and installation will happen on the actual directories you reference.

    You didn’t mention which RHEL/Fedora system you’re on. My recommendation is to install the rpmdevtools package, if it’s not provided by the RHEL repositories, it might be in http://fedoraproject.org/wiki/EPEL

    After installing that, you can set up an RPM build tree automatically by running rpmdev-setuptree, You’ll also get a bare bones spec file by running rpmdev-newspec.

    I’ll copy-paste the minimal spec file produced by that command here:

    Name:
    Version:
    Release: 1%{?dist}
    Summary:

    Group:
    License:
    URL:
    Source0:
    BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

    BuildRequires:
    Requires:

    %description

    %prep
    %setup -q

    %build
    %configure
    make %{?_smp_mflags}

    %install
    rm -rf $RPM_BUILD_ROOT
    make install DESTDIR=$RPM_BUILD_ROOT

    %clean
    rm -rf $RPM_BUILD_ROOT

    %files
    %defattr(-,root,root,-)
    %doc

    %changelog

    BTW, could you please consider installing the OpenID plugin for your blog, it’d be easier to leave comments. And thanks for TLLTS 🙂

  • linc says:

    Using rhel 5.3 and/or CentOS 5.2..
    Unfortunately when I add in a buildroot, the build fails every time.

  • vpv says:

    Are you using the buildroot when installing the file, for example something like:

    install -m 0755 myscript $RPM_BUILD_ROOT/usr/local/bin/myscript

  • linc says:

    YAY! That worked! I added that to my install lines and added a BuildRoot into the spec file. I also added a %_tmppath to the .rpmmacros file and it started behaving as it should. Thanks for all the help!

Leave a Reply

You must be logged in to post a comment.