Find the answer to your Linux question:
Results 1 to 2 of 2
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2013
    Posts
    3

    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 file.sh
    OR
    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

    #BuildRequires:
    #Requires:

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

    %description
    Description of Test package

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

    %build
    #%%configure
    #make %{?_smp_mflags}


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

    %clean
    rm -rf $RPM_BUILD_ROOT
    %files
    %defattr(-,root,users,-)
    %doc
    %changelog
    ---

    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 syallabus.it's a ******* lottery.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,380
    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:
    Code:
    #!/bin/bash
    
    if [ $# -ne 2 ]
    then
        echo "Usage: $0 component version" 1>&2
        echo "  e.g: $0 stalker 1.0.1" 1>&2
        exit 1
    fi
    
    if [ "$1" != "componentname" ]
    then
        echo "Invalid component" 1>&2
        exit 2
    fi
    
    rpmtopdir=`rpm --eval '%_topdir'`
    dist=`rpm --eval '%dist'`
    release=1$dist
    arch=`rpm --eval '%_arch'`
    
    name="$1"
    srcdir="source_directory"
    version="$2"
    srctgz="${name}-${version}.tgz"
    rpmspecfilename="${name}_${version}.spec"
    
    
    # set up sources
    rpmsrcdir="$rpmtopdir/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
    fi
    popd
    
    # set up rpm spec
    rpmspecdir="$rpmtopdir/SPECS"
    [ -d "$rpmspecdir" ] || mkdir -p "$rpmspecdir"
    rpmspec=$rpmspecdir/$rpmspecfilename
    echo "SPEC [$rpmspec]"
    sed 's/X.Y.Z/'"$version"'/g' $name.spec > $rpmspec
    
    pushd $rpmspecdir
    rpmbuild -ba $rpmspec
    popd
    
    # move rpm file to PWD
    rpmrpmdir="$rpmtopdir/RPMS"
    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
  •