Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Exclamation Creating the simpliest RPM in the world doesn't work

    I'm really struggling to create a simple RPM.

    I have as study guide, and used the fedora rpm pages - but still I'm thrown cryptic and ridiculous erros. Of course the formatted templates for the SPEC files are totally inconsistent across versions and distributions - I'm using CentOS which should be identical to Red Hat (which the study guide is based on), yet the spec files are full of differeing options. Fedora even more so but I guess that's understandable.

    Can anyone, please help create an RPM that will install 2 files - a binary and a conf file to a directory of their choosing. I don't care where. Or the 2 files can be text documents (I've tried this also).
    I've used other package managers and never known anything so impossbile and retarded.

    I can post in my spec file as an example but I think it would be far easier to just have a simple example with some basic questions answered:

    I have specified the $RPM_BUILD_ROOT yet all the errors are referring to the build being /var/tmp. What? why?

    Is it correct to gz a directory of files OR the individual files?
    eg. tar -czvf test-package.tar.gz file.conf
    tar -zcvf test-package.tar.gz test-package (directory containing files)

    Here's my spec file:

    Name: test-package
    Version: 1.0
    Release: 1%{?dist}
    Summary: Summary of Test package

    Group: Company Package Group 1
    License: GPL
    URL: a url here
    Source0: %{name}.tar.gz


    BuildRoot: ~/rpmbuild/tmp/%{name}-%{version}

    Description of Test package

    #rm -rf $RPM_BUILD_ROOT/%{name}
    %setup -q -n %{name}

    #make %{?_smp_mflags}

    rm -rf $RPM_BUILD_ROOT
    mkdir -p $RPM_BUILD_ROOT
    #make install DESTDIR=$RPM_BUILD_ROOT

    rm -rf $RPM_BUILD_ROOT

    ERRORS with tar.gz file containing files directly (no dir):
    /var/tmp/rpm-tmp.sSz5T8: line 39: cd: test-package: No such file or directory
    error: Bad exit status from /var/tmp/rpm-tmp.sSz5T8 (%prep)

    No error on build when a directory but the rpm contains no files - WTF!

    rpm -qlp test-package-1.0-1.el6.x86_64.rpm
    (contains no files)

    You would think this would be a lot easier for an rpm to contain a single file and be built. No wonder it's in the RHCE's a ******* lottery.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Use %{buildroot} instead of $RPM_BUILD_ROOT. Also, you should use a bash script to prepare the tarball and then call rpm build. Here is an example of one that I use to build RPMs:
    if [ $# -ne 2 ]
        echo "Usage: $0 component version" 1>&2
        echo "  e.g: $0 stalker 1.0.1" 1>&2
        exit 1
    if [ "$1" != "componentname" ]
        echo "Invalid component" 1>&2
        exit 2
    rpmtopdir=`rpm --eval '%_topdir'`
    dist=`rpm --eval '%dist'`
    arch=`rpm --eval '%_arch'`
    # set up sources
    echo "srcdir $rpmsrcdir"
    [ -d "$rpmsrcdir" ] || mkdir -p "$rpmsrcdir"
    pushd $srcdir
    make clean
    tar cvvzf $rpmsrcdir/$srctgz * --exclude=test
    if [ "$?" -ne "0" ]; then
     echo "Failed to tar $srcdir to $rpmsrcdir/$srctgz"
     exit 1
    # set up rpm spec
    [ -d "$rpmspecdir" ] || mkdir -p "$rpmspecdir"
    echo "SPEC [$rpmspec]"
    sed 's/X.Y.Z/'"$version"'/g' $name.spec > $rpmspec
    pushd $rpmspecdir
    rpmbuild -ba $rpmspec
    # move rpm file to PWD
    cp $rpmrpmdir/${arch}/${name}-${version}-${release}.${arch}.rpm .
    You call it like this: ./scriptname application_name X.Y.Z
    in the directory where the .spec file exists and where X.Y.Z is the version, such as 1.0.1.

    This will set up your build environment so that rpmbuild has a hope of doing the right thing. Part of your problem is in the tarball - it seems you created in the source directory directly, which won't work. This script will take care of that for you, though you will have to do a bit of minor editing of this script to do stuff like specify the actual source directory, application name, etc.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts