Guide to writing spec files for rpm package production scripts

The spec file is used to make rpm packages and contains a lot of information about the software package, such as the name, version, category, description summary of the software package, what instructions to execute when creating, what operations to perform when installing, and the files to be included in the software package. Lists and more. Examples are as follows:

Name: myprogram
Version: 1.0
Release: 1
Vendor: Jaun
Summary: My program 

License: GPL
URL: http://myprogram.com
Source0: myprogram-1.0.tar.gz
Group: Development/Tools
BuildRequires: gcc

%description
My program is a simple example program.

%prep
%setup -q

%build
./configure
make

%install
make install DESTDIR=%{
    
    buildroot}

%clean
rm -rf %{
    
    buildroot}

%files
%defattr(-,root,root)
/sbin/myprogram

%post
/sbin/ldconfig /sbin/myprogram

%preun
/sbin/ldconfig /sbin/myprogram

%postun
/sbin/ldconfig

%changelog

The following is an introduction to each parameter classification

1. Software package description

1.1、Name:

The name of the software package can be referenced later %{name}. The final RPM software package uses this name, version number, release number and system number to name the software package.

1.2、Version

The version number of the software package can %{version}be referenced in the future. The version number will only be increased when the software package has changed significantly from before.

1.3、Release

The actual issuance serial number indicates the packaging time, number of times and other information, which can be referenced later %{release}.

1.4、Vendor

The name of the software developer.

1.5、Summary

Summarize as much information as possible about the package in one sentence

1.6、License/Copyright

The distribution license of the software package, that is, the software authorization method, is usually GPL. Other common ones are: GPL (free software), BSD, MIT, Public Domain (public domain), Distributable (contribution), commercial (commercial), Share, etc.

1.7、URL

The publisher’s website, blog, email and other information can be placed here

1.8、Source

Source code packages are usually referenced using Source0, Source1..., and can also be %{source0}referenced later %{source1}.

1.9、Group

For software grouping, it is recommended to use standard grouping. Common groupings are as follows:

Group explain
Amusements/Games (Entertainment/Games)
Amusements/Graphics (Entertainment/Graphics)
Applications/Archiving (Application/Documentation)
Applications/Communications (Applications/Communications)
Applications/Databases (application/database)
Applications/Editors (Application/Editor)
Applications/Emulators (Application/Emulator)
Applications/Engineering (Application/Engineering)
Applications/File (Application/File)
Applications/Internet (Applications/Internet)
Applications/Multimedia (Applications/Multimedia)
Applications/Productivity (Application/Product)
Applications/Publishing (Application/Print)
Applications/System (operating system)
Applications/Text (app/text)
Development/Debuggers (Development/Debugger)
Development/Languages (Development language)
Development/Libraries (Development/Function Library)
Development/System (development system)
Development/Tools (development tools)
Documentation (documentation)
System Environment/Base (System environment/basis)
System Environment/Daemons (System Environment/Guardian)
System Environment/Kernel (System environment/kernel)
System Environment/Libraries (System environment/function library)
System Environment/Shells (System environment/interface)
User Interface/Desktops (UI/Desktop)
User Interface/X (User Interface/X Window)
User Interface/X Hardware Support (User Interface/X Hardware Support)

1.10、Patch

Patch source package path, you can use Patch0, Patch1..., and you can also use it later %{patch0}to %{patch1}reference

1.11、BuildRoot

The root directory when installing or compiling. When the package is generated, if this directory is not specified as the virtual root directory, the system root directory will be used as the installation root directory during the installation phase.

1.12、Requires

The currently generated RPM package needs to depend on the name of the software package. Use >= or <= to indicate that it is greater than or equal to or less than or equal to the specified version. The symbols are separated by spaces on both sides, and different software packages are also separated by spaces.

1.13、Packager

Packager information

1.14、%description

Detailed description of the software, can be written on multiple lines

1.15、BuildArch

Refers to the target processor architecture for compilation. The noarch flag is not specified, but the content in /usr/lib/rpm/marcros is usually used as the default value.

2. Operations at each stage of software package generation

2.1、%prep

In the pre-compilation stage, you can use scripts to decompress the source code package, process the patches if there are patches, and then generate compilation configuration information (most software will execute the configure script at this stage to perform compilation checks); In addition to executing the macro commands (starting with %) defined by RPM, you can also execute SHELL commands. The commands can have many lines, such as the tar unpacking command we often write.

2.2、%build

In the compilation stage, the command to be executed is to generate software package services. Most software will perform the make operation at this stage.

2.3、%install

During the installation phase, most software will perform the make install operation at this stage.

2.4、%clean

In the cleanup phase, after the installation is completed, the temporary files generated by the above stages will be cleaned up.

2.5、%check

rpm package testing.

3. Package application scripts

3.1、%pre

Pre-installation execution script, that is, before the RPM package is installed, execute this part of the script first, such as creating a specified account, etc.

3.2、%post

After the installation is executed, the script, that is, after the RPM package is successfully installed, it will continue to execute this part of the script, such as setting the boot, starting the service, etc.

3.3、%preun

Uninstall pre-execution script, that is, before the RPM package is uninstalled, execute this part of the script first, such as stopping the service, canceling the startup, etc.

3.4、%postun

Script after uninstallation execution, that is, after the RPM package is successfully uninstalled, it will continue to execute this part of the script, such as deleting the specified account, etc.

4. Package configuration information

4.1、%files

Package file list, the files that need to be put into the RPM package are listed here, which can be a directory

4.2、%changelog

Change diary, which can indicate the information that needs to be prompted for this packaging

4.3、%doc

Indicates that this is a documentation file, so if installed with --excludedocs will not install such files.

4.4、%dir

Indicates that the content under the dir directory path is entered into the rpm package.

4.5、%config(noreplace)

This configuration file will not overwrite existing files (the files in the RPM package will exist in the system as .rpmnew. When uninstalling, the configuration file in the system will be saved as .rpmsave. Without this option, the files in the RPM package will be saved as .rpmsave during installation. .rpmorig exists in the system) overwrites the existing file (not modified) and creates a new file with the extension suffix .rpmnew (modified).

4.6、%attr

Control file permissions

reference documents

1、https://betheme.net/a/12582767.html?action=onClick

2、http://www.someapp.cn/article/14.html

3、http://blog.chinaunix.net/uid-30242191-id-5777389.html

Guess you like

Origin blog.csdn.net/yuelai_217/article/details/130722081