Let take a simple example, you have a binary and a configuration file which you want to install on a Linux machine using a RPM. The binary file “ExampleBin” should be copy on /usr/bin and the configuration file “ExampleBin.conf” should be copy on /etc.
First of all, to be able to create a RPM you need to have installed the rpm-build tool.
Any RPM is created based on a “spec file”. This file basically explains to rpm-build tool how to create and configure the RPM pack.
So let create the “spec file” name “ExampleBin.spec”:
Summary: ExampleBinName: ExampleBinVersion: 0.1Release: 1Group: ExampleBinLicense: ExampleBinSource: %{expand:%%(pwd)}BuildRoot: %{_topdir}/BUILD/%{name}-%{version}-%{release}
%description%{summary}
%preprm -rf $RPM_BUILD_ROOTmkdir -p $RPM_BUILD_ROOT/usr/binmkdir -p $RPM_BUILD_ROOT/etccd $RPM_BUILD_ROOTcp %{SOURCEURL0}/iButtonServer ./usr/bin/cp %{SOURCEURL0}/iButtonServer.cfg ./etc/
%cleanrm -r -f "$RPM_BUILD_ROOT"
%files%defattr(644,root,root)%config(noreplace) %{_sysconfdir}/ ExampleBin.cfg%defattr(755,root,root)%{_bindir}/ ExampleBin
%postExampleBin start
%preunExampleBin stop
On this example, the binary and configuration file are placed on the current directory (pwd).
In the %prep section, the build process is prepared. In our example the required files are copied to $RPM_BUILD_ROOT (build directory).
The %post section executes after the package has been installed.
The %preun section executes before the user uninstall the package.
The %post section executes after the package has been installed.
The %preun section executes before the user uninstall the package.
This script need _topdir environment variable. It should be set inside .rpmmacros file, placed on your home directory.
The next bash script set the _topdir enviroment variable and create the RPM calling using rpm-build tool:
#!/bin/bash
echo '%_topdir '$(pwd) > ~/.rpmmacrosrpmbuild -bb ExampleBin.spec
Running this script placed on the same level like “spec file” the RPM should be generated.
No comments:
Post a Comment