RPM build No such file or directory

user1285928 picture user1285928 · Jul 26, 2015 · Viewed 19.1k times · Source

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.

Answer

larsks picture larsks · Jul 26, 2015

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