Prerequisite
Install package that contain the rpmbuild tool that create the rpm package.
$ yum install rpm-build
Install also a convenient development tool for setting up environment.
$ yum install rpmdevtools
When building rpm package you should do that with a noon root user. To create a new user.
$ useradd rpmuser
Setup
Change to rpm user and from it's home directory run:
$ rpmdev-setuptree
This will create a new empty catalogue structure for your rpm package development.
Creating the Program
$ vi ~/rpmbuild/SOURCES/hello.sh
#!/bin/bash
echo "Good morning, world."
We can test run to see that it actually runs.
$ chmod +x ~/rpmbuild/SOURCES/hello.sh
$ ~/rpmbuild/SOURCES/hello.sh
Good morning, world.
Creating the RPM Spec File
Now with help of wim, that will create a template spec file, we will create a rpm spec file for our hello rpm package.
$ vim ~/rpmbuild/SPECS/hello.spec
Name: hello
Version: 1.0
Release: 1%{?dist}
Summary: A simple hello world application.
Group: Applications/File
License: GPLv2+
URL: http://magnus-k-karlsson.blogspot.se/
Source0: hello.sh
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
#BuildRequires:
Requires: bash
%description
# Prep is used to set up the environment for building the rpm package
# Expansion of source tar balls are done in this section
#%prep
#%setup -q
# Used to compile and to build the source
#%build
#%configure
#make %{?_smp_mflags}
# The installation.
%install
rm -rf %{buildroot}
#make install DESTDIR=%{buildroot}
mkdir -p %{buildroot}/usr/bin
cp %{SOURCE0} $RPM_BUILD_ROOT/usr/bin/.
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root,-)
/usr/bin/hello.sh
%doc
%changelog
Build the RPM
$ rpmbuild -ba ~/rpmbuild/SPECS/hello.spec
Test the RPM
Query (q) the local package (p) for all it's files (l).
$ rpm -qpl rpmbuild/RPMS/x86_64/hello-1.0-1.el6.x86_64.rpm
/usr/bin/hello.sh
Now switch to root and install the package.
$ rpm -pi /home/rpmuser/rpmbuild/RPMS/x86_64/hello-1.0-1.el6.x86_64.rpm
And test it.
$ hello.sh
Good morning, world.
And to uninstall it.
$ yum erase hello
...
No comments:
Post a Comment