You are herePackaging your software. Simple spec file creation

Packaging your software. Simple spec file creation


By cabezon - Posted on 22 December 2011

In order to install hosts via network (pxe), our center developed a python based tool called kickgen. I did a complete re-develop of that project because of the complexity it had and my non-knowledge of python. Anyway, I did develop a Perl based kickgen, added some confgi files and created some man pages for it. All looked like:

/etc/kickgen/kickgen.conf
/usr/bin/kickgen
/usr/share/kickgen/defaults/defaults
/usr/share/kickgen/discs.yaml
/usr/share/kickgen/partitions.yaml
/usr/share/kickgen/templates/OVS
/usr/share/kickgen/templates/index
/usr/share/kickgen/templates/rescue
/usr/share/kickgen/templates/rh5X
/usr/share/kickgen/templates/rh6X
/usr/share/kickgen/vlans.yaml
/usr/share/man/man1/kickgen.1.gz
/usr/share/man/man5/kickgen.conf.5.gz

I have packed it as a tar-ball, but I wanted to created a valid rpm which also install its dependencies. Lucky me, my code does not need compilation as it only has few conf/templates/man/executable files. So, for packaging it, my spec file only had to copy those files to its correct location.

The spec file has several sections and it can be as complex as you want. I've read a couple of links, but the best one is this one from CentOS wiki.

So, what did I need?
First of all, the header which describes my package:

Name:           kickgen
Version:        0.0.1
Release:        1
Summary:        Kickstart file generator
Group:          Administration Tools
License:        GPL
URL:            <a href="http://blog.emergetux.net<br />
Source0:" title="http://blog.emergetux.net<br />
Source0:">http://blog.emergetux.net<br />
Source0:</a>        %{name}-%{version}.tar.gz
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

Quite simple. The only important thing is the Source name. It will be kickgen-0.0.1.tar.gz, and rpmbuild will look for that file.

Then, we have to specify dependencies. In my case tftboot server, dhcp server, http server and some perl modules. You don't specify dependencies as package names, we must specify what "feature" provides the package. We can find it easy (taking perl-YAML-0.66-2.el5 rpm as example):

# rpm -q --provides perl-YAML
perl(YAML) = 0.66
perl(YAML::Base)  
[...]

So, next part of spec file looks like:

Requires:       perl(YAML)
Requires:       perl(Config::General)
Requires:       tftp-server
Requires:       webserver
Requires:       dhcp

Now you plac package description

%description
Kickgen is a Perl scripts designed to generate Kickstart files, configure
dhcpd and tftp to install (via network) a host.
See my blog to know how to configure it, or see man pages.

And now comes the important part: prep, build, check, install... If you have to compile your code, you should add all those parts of the spec file and describe what's needed for each section. But, as I only hvae to copy few files from the tarball, I only need prep, which untar the source, install, which will copy files to destination path, clea and files, that identifies what files and directories were added by the package.

%prep
%setup -q
 
%install
rm -rf %{buildroot}
echo %{buildroot}/usr/share/man/man1/
mkdir -p %{buildroot}/{%{_sysconfdir},%{_bindir},%{_datadir}}
mkdir -p %{buildroot}/usr/share/man/man1/
mkdir -p %{buildroot}/usr/share/man/man5/
cp -rp etc/kickgen  %{buildroot}%{_sysconfdir}/
cp -p usr/local/bin/kickgen  %{buildroot}%{_bindir}/
cp -rp usr/share/kickgen  %{buildroot}%{_datadir}/
cp -p usr/share/man/man1/kickgen.1.gz  %{buildroot}/usr/share/man/man1/
cp -p usr/share/man/man5/kickgen.conf.5.gz  %{buildroot}/usr/share/man/man5/
 
 
%clean
rm -rf %{buildroot}
 
%files
%defattr(-,root,root,-)
%{_sysconfdir}/kickgen/kickgen.conf
%{_bindir}/kickgen
%{_datadir}/kickgen/discs.yaml
%{_datadir}/kickgen/partitions.yaml
%{_datadir}/kickgen/vlans.yaml
%{_datadir}/kickgen/templates/index
%{_datadir}/kickgen/templates/OVS
%{_datadir}/kickgen/templates/rescue
%{_datadir}/kickgen/templates/rh5X
%{_datadir}/kickgen/templates/rh6X
%{_datadir}/kickgen/defaults/defaults
/usr/share/man/man1/kickgen.1.gz
/usr/share/man/man5/kickgen.conf.5.gz

Last, the Changelog section:

%changelog
* Wed Dec 21 2011 Arnau Bria <arnaubria@pic.es> 0.1
- First release

And the spec is finished.

Now we have to check if the spec is correct or not:

# rpmlint kickgen.spec 
kickgen.spec:5: W: non-standard-group Administration Tools
kickgen.spec: W: no-%build-section
kickgen.spec: W: invalid-url Source0: kickgen-0.0.1.tar.gz
0 packages and 1 specfiles checked; 0 errors, 3 warnings.

It's ok for me. I have not uplodaded the source and its address is incorrect, I have no build section (I only copy few files).

So, we're ready to build our rpm packages. We need rpmbuild and the options -ba(-ba Build binary and source packages (after doing the %prep, %build, and %install stages):

# rpmbuild -ba kickgen.spec 
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.94823
+ umask 022
+ cd /usr/src/redhat/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /usr/src/redhat/BUILD
+ rm -rf kickgen-0.0.1
+ /bin/gzip -dc /usr/src/redhat/SOURCES/kickgen-0.0.1.tar.gz
+ tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd kickgen-0.0.1
++ /usr/bin/id -u
+ '[' 0 = 0 ']'
+ /bin/chown -Rhf root .
++ /usr/bin/id -u
+ '[' 0 = 0 ']'
+ /bin/chgrp -Rhf root .
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.94823
+ umask 022
+ cd /usr/src/redhat/BUILD
+ cd kickgen-0.0.1
+ LANG=C
+ export LANG
+ unset DISPLAY
+ rm -rf /var/tmp/kickgen-0.0.1-1-root-root
+ echo /var/tmp/kickgen-0.0.1-1-root-root/usr/share/man/man1/
/var/tmp/kickgen-0.0.1-1-root-root/usr/share/man/man1/
+ mkdir -p /var/tmp/kickgen-0.0.1-1-root-root//etc /var/tmp/kickgen-0.0.1-1-root-root//usr/bin /var/tmp/kickgen-0.0.1-1-root-root//usr/share
+ mkdir -p /var/tmp/kickgen-0.0.1-1-root-root/usr/share/man/man1/
+ mkdir -p /var/tmp/kickgen-0.0.1-1-root-root/usr/share/man/man5/
+ cp -rp etc/kickgen /var/tmp/kickgen-0.0.1-1-root-root/etc/
+ cp -p usr/local/bin/kickgen /var/tmp/kickgen-0.0.1-1-root-root/usr/bin/
+ cp -rp usr/share/kickgen /var/tmp/kickgen-0.0.1-1-root-root/usr/share/
+ cp -p usr/share/man/man1/kickgen.1.gz /var/tmp/kickgen-0.0.1-1-root-root/usr/share/man/man1/
+ cp -p usr/share/man/man5/kickgen.conf.5.gz /var/tmp/kickgen-0.0.1-1-root-root/usr/share/man/man5/
+ /usr/lib/rpm/redhat/brp-compress
+ /usr/lib/rpm/redhat/brp-strip /usr/bin/strip
+ /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
+ /usr/lib/rpm/redhat/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
+ /usr/lib/rpm/brp-python-bytecompile
+ /usr/lib/rpm/redhat/brp-java-repack-jars
Processing files: kickgen-0.0.1-1
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires: /usr/bin/perl dhcp perl(Config::General) perl(Config::General) perl(Data::Dumper) perl(File::Copy) perl(Getopt::Std) perl(Net::Netmask) perl(Socket) perl(Tie::File) perl(YAML) perl(YAML) perl(constant) perl(strict) tftp-server webserver
Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/kickgen-0.0.1-1-root-root
Wrote: /usr/src/redhat/SRPMS/kickgen-0.0.1-1.src.rpm
Wrote: /usr/src/redhat/RPMS/x86_64/kickgen-0.0.1-1.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.94823
+ umask 022
+ cd /usr/src/redhat/BUILD
+ cd kickgen-0.0.1
+ rm -rf /var/tmp/kickgen-0.0.1-1-root-root
+ exit 0

and the rpms are under:

# ls -lsa /usr/src/redhat/RPMS/x86_64/kickgen-0.0.1-1.x86_64.rpm /usr/src/redhat/SRPMS/kickgen-0.0.1-1.src.rpm 
16 -rw-r--r-- 1 root root 15419 Dec 21 17:27 /usr/src/redhat/RPMS/x86_64/kickgen-0.0.1-1.x86_64.rpm
16 -rw-r--r-- 1 root root 14916 Dec 21 17:27 /usr/src/redhat/SRPMS/kickgen-0.0.1-1.src.rpm

Finally, we do install the package in a new box:

# yum localinstall kickgen-0.0.1-1.x86_64.rpm 
Loaded plugins: kernel-module
Setting up Local Package Process
Examining kickgen-0.0.1-1.x86_64.rpm: kickgen-0.0.1-1.x86_64
Marking kickgen-0.0.1-1.x86_64.rpm to be installed
epel                                                                                                                                                     | 3.7 kB     00:00     
epel/primary_db                                                                                                                                          | 3.9 MB     00:00     
Resolving Dependencies
--> Running transaction check
---> Package kickgen.x86_64 0:0.0.1-1 set to be updated
--> Processing Dependency: dhcp for package: kickgen
--> Processing Dependency: perl(Config::General) for package: kickgen
--> Processing Dependency: perl(Config::General) for package: kickgen
--> Processing Dependency: perl(Net::Netmask) for package: kickgen
--> Processing Dependency: perl(YAML) for package: kickgen
--> Processing Dependency: perl(YAML) for package: kickgen
--> Processing Dependency: tftp-server for package: kickgen
--> Processing Dependency: webserver for package: kickgen
--> Running transaction check
---> Package dhcp.x86_64 12:3.0.5-29.el5_7.1 set to be updated
---> Package nginx.x86_64 0:0.8.55-1.el5 set to be updated
--> Processing Dependency: libgd.so.2()(64bit) for package: nginx
--> Processing Dependency: libGeoIP.so.1()(64bit) for package: nginx
---> Package perl-Config-General.noarch 0:2.40-1.el5 set to be updated
---> Package perl-Net-Netmask.noarch 0:1.9012-3.el5 set to be updated
---> Package perl-YAML.noarch 0:0.66-2.el5 set to be updated
---> Package tftp-server.x86_64 0:0.42-3.1 set to be updated
--> Processing Dependency: xinetd for package: tftp-server
--> Running transaction check
---> Package GeoIP.x86_64 0:1.4.8-1.el5 set to be updated
---> Package gd.x86_64 0:2.0.33-9.4.el5_4.2 set to be updated
---> Package xinetd.x86_64 2:2.3.14-10.el5 set to be updated
--> Finished Dependency Resolution
Beginning Kernel Module Plugin
Finished Kernel Module Plugin
 
Dependencies Resolved
 
================================================================================================================================================================================
 Package                                     Arch                           Version                                       Repository                                       Size
================================================================================================================================================================================
Installing:
 kickgen                                     x86_64                         0.0.1-1                                       /kickgen-0.0.1-1.x86_64                          27 k
Installing for dependencies:
 GeoIP                                       x86_64                         1.4.8-1.el5                                   epel                                            783 k
 dhcp                                        x86_64                         12:3.0.5-29.el5_7.1                           sl-security                                     889 k
 gd                                          x86_64                         2.0.33-9.4.el5_4.2                            sl-security                                     155 k
 nginx                                       x86_64                         0.8.55-1.el5                                  epel                                            389 k
 perl-Config-General                         noarch                         2.40-1.el5                                    sl-security                                      68 k
 perl-Net-Netmask                            noarch                         1.9012-3.el5                                  epel                                             22 k
 perl-YAML                                   noarch                         0.66-2.el5                                    epel                                             81 k
 tftp-server                                 x86_64                         0.42-3.1                                      sl-base                                          28 k
 xinetd                                      x86_64                         2:2.3.14-10.el5                               sl-base                                         124 k
 
Transaction Summary
================================================================================================================================================================================
Install     10 Package(s)         
Update       0 Package(s)         
Remove       0 Package(s)         
[...]
Complete!
 
# rpm -qa|grep kickgen
kickgen-0.0.1-1
 
# rpm -ql kickgen-0.0.1-1
/etc/kickgen/kickgen.conf
/usr/bin/kickgen
/usr/share/kickgen/defaults/defaults
/usr/share/kickgen/discs.yaml
/usr/share/kickgen/partitions.yaml
/usr/share/kickgen/templates/OVS
/usr/share/kickgen/templates/index
/usr/share/kickgen/templates/rescue
/usr/share/kickgen/templates/rh5X
/usr/share/kickgen/templates/rh6X
/usr/share/kickgen/vlans.yaml
/usr/share/man/man1/kickgen.1.gz
/usr/share/man/man5/kickgen.conf.5.gz
 
# rpm -qi kickgen-0.0.1-1
Name        : kickgen                      Relocations: (not relocatable)
Version     : 0.0.1                             Vendor: (none)
Release     : 1                             Build Date: Wed 21 Dec 2011 05:27:01 PM CET
Install Date: Wed 21 Dec 2011 05:34:23 PM CET      Build Host: cobbler.pic.es
Group       : Administration Tools          Source RPM: kickgen-0.0.1-1.src.rpm
Size        : 27785                            License: GPL
Signature   : (none)
URL         : <a href="http://blog.emergetux.net<br />
Summary" title="http://blog.emergetux.net<br />
Summary">http://blog.emergetux.net<br />
Summary</a>     : Kickstart file generator
Description :
Kickgen is a Perl scripts designed to generate Kickstart files, configure
dhcpd and tftp to install (via network) a host.
See my blog to know how to configure it, or see man pages.

Nice!

Tags