Quickly create custom software RPM packages in Linux Raiders

  

In order to manage software on Linux systems, various versions of Linux use packages. The advantage of the package is that the system keeps track of those installation files during the installation process, which makes management easier in the future. It is a good idea to bundle custom software into an RPM package before adding it to your Linux server. In this article, you will learn how to create your own RPM package.

RPM is the default package format for Red Hat Enterprise Linux and SUSE Linux Enterprise Server and their derivatives. Creating an RPM package is useful if you want to install custom software on multiple Linux servers. Put this RPM package in the database, and it will be more convenient for all servers that can connect to this database to update the software later.

The RPM package contains two files: a shell script and a README file. The README file describes how to use the shell script. If you can create a package with two files, you can also create a larger package.

The process of creating a simple RPM package

Note that there is a clear distinction between user accounts for specific tasks. If an error occurs, use a normal user account. If you use the root user account, you may accidentally erase many files on the disk. Please follow the procedure below to create your own RPM package:

1. Create a directory structure and include the files needed for the RPM package. The name of this structure is usually named after the RPM package, including its version number. It doesn't matter where this directory is placed. In this example, it is in the home directory of the current user account. We named this directory test-1.0. The following command tells you how to create and name this directory, how to put the required files inside:

$ mkdir ~/test-1.0

$ cd ~/test-1.0

$ echo echo this is a test > test.sh

$ chmod +x test.sh

$ echo just launch The script > README

2. Now, all the files needed for the RPM package are here. The next step is to create an RPM file. Tar.gz file. This directory also makes it easier to create archive files. That. The tar.gz file needs to be located in a directory called rpmbuild/SOURCES -- this folder is usually located in the current user's home directory. You still need one. The specs file, which contains specifications for all RPM packages. That. The specs file is the core component of the RPM package, which includes instructions for all files. The files in the RPM package are installed according to these instructions. That. The specs file should be placed in a SPECS directory.

The first cd command ensures that the rpmbuild directory is located in the current user's home directory. Please execute the following command as a normal user:

$ cd

$ mkdir -p ~/rpmbuild/SOURCES

$ mkdir -p ~/rpmbuild/SPECS

$ tar -cvzf ~/rpmbuild/SOURCES/test-1.0.tar.gz test-1.0

3. Now that the files are in place, please create a description file as a normal user. The Rpmbuild command will find all the required instructions to create the file. In recent Red Hat and derivative versions, it's easy to create a description file: just use the vim editor to create a file with all the content, with the extension set to . Spec can be. Here is the look of the file in the test-1.0rpm package (where the template changes have been marked in bold):

Name: test test

Version Version: 1.0

Release Release: 1%{?dist}

Summary Summary: A test package a test package

Group Category: Test Packages Test Package

License License: GPL

URL: http://test.example.com

Source0: %{name}-%{version}.tar.gz

BuildRoot: %(mktemp - Ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)

BuildRequires: /bin/rm, /bin/mkdir, /bin/cp

Requires: /bin/bash, /bin/date

%description

Demo for deploying a single package

%prerp

%setup –q

%build

#configure

#make %{? _smp_mflags}

%install

rm -rf $RPM_BUILD_ROOT

#make install DESTDIR=$RPM_BUILD_ROOT

mkdir -p $RPM_BUILD_ROOT/usr/local/bin

Cp myscript $RPM_BUILD_ROOT/usr/local/bin

%clean

rm -rf $RPM_BUILD_ROOT

%files

%defattr(-root,root ,-)

#%doc

%attr(0755,root,root)/usr/local/bin/myscript

%changelog

* Today

- Creation of initial RPM

There are a few things you need to remember. All entries prefixed with a% are internal macros. Some of these macros have been disabled for a simple demonstration. The most important of these entries are the %configure and %make macros, which must be preceded by a # and their % removed to disable these macros.

The starting macro is very clear and does not require any explanation. The most important macro is the Source0 definition. It is defined as %{name}-%{version}.tar.gz and must be exactly the same as the tar ball name you created earlier.

Another element is BUILD_ROOT. This is an automatically generated environment, and the rpmbuild command will use this environment to do its own work. Remember that BUILD_ROOT is automatically disappearing. This is why the root user is not used when creating an RPM package. The %build section can also be used for work such as software compilation.

In the %install section, the script you created earlier was copied. In this case, you only need a simple cp command, but for more complex packages, these tasks will be very complicated.

The last part of the spec file is the %attr macro, which sets the permission mode to 0755 and makes the root user and root the master of the installation file.

Now. Once the spec file is created, it's time to complete the final work. Please use the root user to install the rpmbuild command. In Red Hat, use yum install rpm-build to do the job. Next, make sure all the files are in the right place. The tar archive must be located in the ~/rpmbuild/SOURCES directory of the current user account that created the package. The demo.spec file must be located in the ~/rpmbuild/SPECS directory. Now you can create a package with the rpmbuild -ba test.spec command. This will create your RPM file in the ~/rpmbuild/RPMS directory.

Author: Sander van Vugt Translator: Dan

Copyright © Windows knowledge All Rights Reserved