RPM build No such file or directory

21,670

Solution 1

%install 
install -m 0755 -d %{buildroot}/opt/agent
cp -a your_milion_files/* %{buildroot}/opt/agent

%files 
/opt/agent

When you specify %dir, it will include just that directory and nothing else. Without %dir pragma, it will include that directory and EVERYTHING within it. So you just to copy those files in that directory in %install section.

Edit:

Let say that some-agent-1.0.tar.gz contains:

agent/binary/agent.sh
agent/data/data1.dat
agent/data/data2.dat
....
agent/data/data1000.dat
agent/LICENSE

then your sections should be:

%install
install -m 0755 -d %{buildroot}/%{_bindir}/some-agent
install -m 0755 -d %{buildroot}/%{_datadir}/
cp -a binary/agent.sh %{buildroot}/%{_bindir}/some-agent
cp -a data/* %{buildroot}/%{_datadir}/

%files
%doc LICENSE
%{_bindir}/some-agent
%{_datadir}/some-agent

Instead of the last line you can either use:

%dir %{_datadir}/some-agent
%{_datadir}/some-agent/*

but obviously

 %{_datadir}/some-agent

is shorter and have the same meaning.

In that %install section you can use any bash command. So do there what would you normally do on command line. Any shell expansion works so use that to your advance.

I used some macros - you should use them rather then hardcoded path. You can get full list of available macros by

rpm --showrc

And evaluate them by

rpm --eval '%{_datadir}'

which on recent RHEL and Fedoras evaluato to

/usr/share

I also presented little trick with LICENSE file. When it is present in topmost directory of tarfile, then you just pass the name to %doc macro and rpm will place it to correct %docdir automatically.

Solution 2

Look at the log from the build process. First, rpmbuild changes into the BUILD directory:

+ cd /home/rcbandit/rpm/BUILD

Then it untars your source tarball:

+ /usr/bin/gzip -dc /home/rcbandit/rpm/SOURCES/some_agent-1.0.tar.gz
+ /bin/tar -xf -

Then it attempts to cd into the some_agent-1.0 directory, which is presumably created by untarring the source archive:

+ cd some_agent-1.0
/var/tmp/rpm-tmp.RUwFW5: line 38: cd: some_agent-1.0: No such file or directory

This is failing. This suggests that unpacking the archive is not creating the directory RPM is looking for. You would typically solve this using an argument to the %setup macro. For example, if I have an archive named some_agent-1.0.tar.gz, and it contains:

an-unexpected-name/
an-unexpected-name/README

I would need to indicate that with the -n argument to the %setup macro:

%prep
%setup -q -n an-unexpected-name
Share:
21,670
user1285928
Author by

user1285928

Updated on August 01, 2020

Comments

  • user1285928
    user1285928 over 3 years

    I want to create simple RPM file with many small files.

    [root@laptop rpm]# tree
    .
    ├── BUILD
    ├── BUILDROOT
    ├── RPMS
    ├── SOURCES
    │   └── some_agent-1.0.tar.gz
    ├── SPECS
    │   ├── kernel.spec
    │   └── kernel.spec~
    └── SRPMS
    
    6 directories, 3 files
    [root@laptop rpm]# 
    

    I have this spec file:

    Summary: some_agent
    Name: some_agent
    Version: 1.0
    Release: 1
    License: Apache
    Group: application
    Source0: %{name}-%{version}.tar.gz
    BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
    %description
    Test 
    
    %prep
    %setup -q
    
    %build
    
    
    %install
    rm -rf $RPM_BUILD_ROOT
    make root=$RPM_BUILD_ROOT install
    
    %clean
    rm -rf $RPM_BUILD_ROOT
    
    %files
    %defattr(-,root,root,-)
    %doc
    agent/*
    

    But when I try to build the RPM package I get this error:

    [root@laptop ~]$ rpmbuild -bb -v ~/rpm/SPECS/kernel.spec
    Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.RUwFW5
    + umask 022
    + cd /home/rcbandit/rpm/BUILD
    + LANG=C
    + export LANG
    + unset DISPLAY
    + cd /home/rcbandit/rpm/BUILD
    + rm -rf some_agent-1.0
    + /usr/bin/gzip -dc /home/rcbandit/rpm/SOURCES/some_agent-1.0.tar.gz
    + /bin/tar -xf -
    + STATUS=0
    + '[' 0 -ne 0 ']'
    + cd some_agent-1.0
    /var/tmp/rpm-tmp.RUwFW5: line 38: cd: some_agent-1.0: No such file or directory
    error: Bad exit status from /var/tmp/rpm-tmp.RUwFW5 (%prep)
    
    
    RPM build errors:
        Bad exit status from /var/tmp/rpm-tmp.RUwFW5 (%prep)
    [root@laptop ~]$ ^C
    

    Do you have any idea where is my mistake?

    I copied the source file but for some reason it's not found.

  • nos
    nos over 8 years
    @user1285928 If you unpack your some_agent-1.0.tar.gz, what do you get ? rpmbuild will assume it unpacks to a directory named some_agent-1.0, but from the output you show us, that is not the case. So, what's inside your tarball ?
  • user1285928
    user1285928 over 8 years
    I have a small progress. I have a directory agent into the tar.gz file which is a parent to many small files. I managed to build the RPM but it's empty. any idea what I'm missing?
  • nos
    nos over 8 years
    Your .spec files only create an empty directory in $RPM_BUILD_ROOT/opt/agent , you would need to copy the files you want to be installed into there as well, and you probably need to remove the %dir in your %install section too.
  • user1285928
    user1285928 over 8 years
    Yes but I have 1000+ files into the package. I can't write every file name. Can you give me detailed information what I need to edit?
  • nos
    nos over 8 years
    Perhaps just do cp -ap agent/* $RPM_BUILD_ROOT/opt/agent/ Or instead of doing install -m 0755 -d $RPM_BUILD_ROOT/opt/agent , just copy the whole directory tree: install -m 0755 -d $RPM_BUILD_ROOT/opt/ and cp -R agent $RPM_BUILD_ROOT/opt/
  • user1285928
    user1285928 over 8 years
    I get cp: cannot stat `agent/*': No such file or directory
  • nos
    nos over 8 years
    Run pwd in your spec file, then you will learn what the current working directory is in the %install section and discover that I made a mistake, and it should just be cp -ap * $RPM_BUILD_ROOT/opt/agent/ .
  • user1285928
    user1285928 over 8 years
    I tried to copy whole directory tree using cp -ap * $RPM_BUILD_ROOT/opt/agent/ but I get + /usr/lib/rpm/redhat/brp-java-repack-jars and the computer hangs. How I can run pwd into the spec file to see the location?
  • user1285928
    user1285928 over 8 years
    I don't understand what I have to insert for your_milion_files/*? Maybe each file or specific directory?
  • msuchy
    msuchy over 8 years
    In %prep section you correctly unpacked some-agent-1.0.tar.gz and at the beginning of %install section you are changed into ./agent/ directory, which should be topmost dirctory of your tar. So you basically copy those files to correct location in %{buildroot}. I will try to edit my answer and give specific example.
  • Veda
    Veda almost 6 years
    Thanks %setup -q -n an-unexpected-name was what I was searching for.
  • itsazzad
    itsazzad over 2 years
    Should use ${SourceX} instead of %{buildroot}