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.
%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.