RPM Build

Install the 'rpm-build' package via RPM command or via YUM

In my example I installed via YUM

[root@server1 ~]# yum install rpm-build* -y

Make a collaborative directory ‘SOURCES’ & ‘SPECS’ in rpmbuild in the home directory and make a directory ‘test-0.1’.

[root@server1 ~]# mkdir -p rpmbuild/SOURCES
[root@server1 ~]# mkdir -p rpmbuild/SPECS
[root@server1 ~]# mkdir test-0.1

Write the simple scripts in three different files like ‘test1’, ‘test2’, ‘test3’.
[root@server1 ~]# vim test-0.1/test1
                             echo “Hi this is the RPM”
[root@server1 ~]# vim test-0.1/test2
                             echo “developed by”

[root@server1 ~]# vim test-0.1/test3
                             echo “BOLT India”

Create the gzip for the directory test-0.1
[root@server1 ~]# tar -cjvf test-0.1.tar.gz test-0.1/

Copy the test-0.1.tar.gz to ‘SOURCES’ directory.
[root@server1~]# cp test-0.1.tar.gz rpmbuild/SOURCES/

Now the ‘somefile.spec’ file automatically created in ‘SPECS’ directory.

[root@server1~]# vim rpmbuild/SPECS/test.spec
Name: test
Version: 0.1
Release: 1%{?dist}
Summary: Good
Group: System Environment/Base
License: GPLv2
Source0: test-0.1.tar.gz
#BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildRoot: %{_temppath}/%{name}-%{version}-x86_64
                                                                                                “Remember to comment the above
BuildRoot line and write your own line”

This is Awesome
%setup -q

echo "Ok"

mkdir -p $RPM_BUILD_ROOT/root/bin
cp test1 $RPM_BUILD_ROOT/root/bin
cp test2 $RPM_BUILD_ROOT/root/bin
cp test3 $RPM_BUILD_ROOT/root/bin



* Thu Feb 16 2012 root<root@server1.example.com>-0.1
This RPM is built by BOLT India.

Now run the ‘RPMBUILD’ command to create the RPM.
[root@server1~]# rpmbuild -ba rpmbuild/SPECS/test.spec

This command will create and ‘RPMS/SRPMS’ directories which will store your ‘rpms/srpms’ file.

Note: Now you can install this rpm stored in '~/rpmbuild/RPMS/test-0.1-1.el6.x86_64.rpm' and after installation it will create some files and directories according to 'test.spec' file.

Now if you want to sign the RPM.

[root@server1~]# gpg --gen-key
It will create public and private keys.

[root@server1~]# gpg --list-key
It will show you all public keys information.

[root@server1~]# gpg --list-secret-key
It will show you all secret keys information.
[root@server1~]# vim ~/.rpmmacros
%_gpg_name 8FA01F02
Copy your public Key ID.

[root@server1~]# rpm --addsign rpmbuild/RPMS/x86_64/test-0.1-1.el6.x86_64.rpm
To sign your RPM.

To verify the signature.
[root@server1~]# cp rpmbuild/RPMS/x86_64/test-0.1-1.el6.x86_64.rpm /home/philip
[root@server1~]# gpg --export --armor public_key_id > /tmp/rpm.pub.key
[root@server1~]# su - philip
[philip@server1~]$ rpm --import /tmp/rpm.pub.key
[philip@server1~]$ rpm --checksig test-0.1-1.el6.x86_64.rpm
To VERIFY the Signature.

To know about the courses CLICK HERE..!!

Contact US CLICK HERE..!!

No comments:

Post a Comment