RPM build No such file or directory
Asked Answered
T

2

9

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.

Toxic answered 26/7, 2015 at 16:34 Comment(6)
It looks like rpmbuild has some problems with changing directory to unpacked some_agent directory, check paths. Maybe your sources weren't compressed properly - without 'some_agent-1.0' directory, just files? Try to uncompress it manually and see what is the result.Pyelonephritis
No, manually uncompressing files is not solving the problem.Toxic
When you unpack the some_agent-1.0.tar.gz tarball, do you end up with a directory called some_agent-1.0? Or something else?Hessenassau
yes, which directory I have to unzip it? SOURCES?Toxic
Now the generated RPM is empty. Looks like again I'm missing something.Toxic
I reverted back to the original since there was an answer that (at least partly) answered that question already by the time you modified the question and invalidated their answer.Period
M
3
%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.

Mod answered 30/7, 2015 at 10:12 Comment(3)
I don't understand what I have to insert for your_milion_files/*? Maybe each file or specific directory?Toxic
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.Mod
Should use ${SourceX} instead of %{buildroot}Grisly
H
10

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
Hessenassau answered 26/7, 2015 at 20:45 Comment(9)
@Toxic 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 ?Ding
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?Toxic
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.Ding
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?Toxic
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/Ding
I get cp: cannot stat `agent/*': No such file or directoryToxic
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/ .Ding
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?Toxic
Thanks %setup -q -n an-unexpected-name was what I was searching for.Intelligence
M
3
%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.

Mod answered 30/7, 2015 at 10:12 Comment(3)
I don't understand what I have to insert for your_milion_files/*? Maybe each file or specific directory?Toxic
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.Mod
Should use ${SourceX} instead of %{buildroot}Grisly

© 2022 - 2024 — McMap. All rights reserved.