Creating RPM Package

Agenda

An Overview

  Preparing to build RPMs(只会做rpm包)

  Planning for RPMs(规划)

  Explaining the build process(制作过程)

  Using build files(使用build files)

  Seeing the results

  Verifying your RPMs

Writing Spec Files

  Writing spec files(写spec files)

  Defining package information(定义软件包信息)

  Controlling the build(控制编译)

  Listing the files in the package(列出包中包含的文件)

  Defining spec file macros(在spec文件使用宏)

Preparing to build RPMs(制作rpm准备)

The main tasks in building RPMs are:

  Planning what you want to build(规划制作的rpm包是什么东西)

  Gathering the software to package(收集软件包)

  Patching the software as needed(收集补丁,打补丁)

  Creating a reproducible build of the software

  Planning for upgrades(能否用于升级旧的软件包)

  Outlining any dependencies(依赖关系)

  Building the RPMs(必须规划大纲)

  Testing the RPMs(测试)

 

RPM

  Rpm capability能力

Planning what you want to build

An application

  Customized or patched?(定制或修补)

A programming library(存崔的库文件)

A set of system configuration files(是不是一堆的系统配置文件)

Or a doceumentation package(文档包)

Creating a binary RPM or a source RPM or both?(制作的是二进制rpm包还是源码rpm包)

  src.rpm

    tar.gz spec

Building RPMs(制作rpm包相关过程)

1.Set up the directory structure(设定好目录结构)

2.Place the sources in the right directory(将源码放置所规划好的目录当中)

3.Create a spec file that tells the rpmbuild command what to do(创建spec文件,指挥着如何使用这些源材料给它制作成rpm包)

4.Build the source and binary RPMs(编译源代码生成rpm包)

 

Setting up the directory structure

BUILD: 让源代码解压以后放的位置;

RPMS: 放rpm包的,制作完成以后的rpm包放这个目录;

SOURCES: 放spec文件的;

SRPMS: src格式的rpm放置位置;

By default,Red Hat Linux systems expect RPMs to be built in the /usr/src/redhat(制作车间) directory

# rpmbuild --showrc | grep macros

Inside the spec file,format the information on the package using a special syntax

  This syntax defines how to build the package,version numbers,dependency information,and everything else you can query about a package(语法主要定义了如何编译rpm包)

  This syntax differs slightly depending on the sections in the spec file

  The following slides describe these spec file sections and the necessary syntax in each section

 

Creating the spec file(创建spec文件)

The spec file,short for specification file,defines all the actions the rpmbuild command should take to build your application, as well as all the actions necessary for the

rpm command to install and remove the application

The spec file is a text file.The normal naming conventing is to name the file with the package name and a .spec filename extension

The introduction section(介绍段)

  The introduction section contains information about the package,the type of information shown with the rpm -qi command

Summary: 汇总活埋

Name: 名字

Version: 版本,务必使用.隔开,中间不能使用横线,-横线有特殊意义;

Release: 跟版本号没关系,是制作者第几次制作rpm包,1%{?dist} 宏,用于引用,具有判断能力,?问号表示如果有就带上,如果没有就不带;

License: 声明版权信息

Group: 这个软件包属于那个组,

URL:这个软件包可以从那里下载到;

Packager: 软件包制作者;

Vendor: 制作者所属的公司,或提供商;

Source: 制作这个rpm包使用的源文件;

BuildRoot: 软件包安装目录

BuildRequires: 定义依赖关系;

%description: 描述

The prep section(准备阶段)

  The prep section, short for prepare, defines the commands necessary to prepare for the build

  If you are starting with a compressed tar archive(a tarball) of the sources,the prep section needs to extract the sources

  The prep section starts with a %prep statement

    This example uses the %setup RPM macro,which knows about tar archives,to extract the files

%prep:准备阶段

%setup: 解压设定环境切换进去;

The build section(编译阶段)

  The spec file build section contains the commands to build the software

  Usually,this will include just a few commands,since most of the real instructions appear in the Makefile

  The build section starts with a %build statement

The install section(安装阶段)

  The spec file install section holds the commands necessary to install the newly built application or library

  In most cases,your install section should clean out the Buildroot directory and run the make install command

  The install section starts with a %install statement

The clean section(清理段)

  The clean section cleans up the files that the commands in the other sections create

  The clean section starts with a %clean statement

The files section

  Finally, the files section lists the files to go into the binary RPM,along with the defined file attributes(文件段,rpm包应该包含那些文件)

  The files section starts with a %files statement

  The %doc macro marks certain files as documentation

脚本段:

  httpd

  %pre 安装前

  %post 安装后

  %preun 卸载之前

  %postun 卸载完成之后

BUILDROOT/

The files section

  Finally, the files section lists the files to go into the binary RPM, along with the defined file attributes

  The files section starts with a %files statement

  The %doc macro marks certain files as documentation

    This allows the RPM to distinguish the files holding documentating from the other files in the RPM

%chagelog(修改日志段)

Vyukdubg RONs with the rpmbuild command

Don't build packages when you are logged in as the root user

-bp: 只执行到%prep阶段

-bi: 只执行到install阶段;

-bc: 只执行到%build阶段;

-bb: 制作二进制格式rpm包;

-bs: 制作源码格式rpm包;

-ba: 即制作二进制格式又制作源码格式rpm包;

-bl: 能帮助检测有那些文件在buildroot路径下存在安装生成了,但是却在制作rpm那个files段中没有包含到任何一个rpm包中去;

[root@localhost ~]# tree /usr/src/redhat/(显示/usr/src/redhat目录树)
/usr/src/redhat/
|-- BUILD
|-- RPMS
|   |-- athlon
|   |-- geode
|   |-- i386
|   |-- i486
|   |-- i586
|   |-- i686
|   `-- noarch
|-- SOURCES
|-- SPECS
`-- SRPMS

12 directories, 0 files
[root@localhost ~]# ll -d /usr/src/redhat/(查看/usr/src/redhat目录本身详细信息)
drwxr-xr-x 7 root root 4096 Nov 22  2014 /usr/src/redhat/
[root@localhost ~]# rpmbuild --showrc(查看所有相关宏的定义)
ARCHITECTURE AND OS:
build arch            : i386
compatible build archs: i686 i586 i486 i386 noarch fat
build os              : Linux
compatible build os's : linux
install arch          : i686
install os            : Linux
compatible archs      : i686 i586 i486 i386 noarch fat
compatible os's       : linux

RPMRC VALUES:
macrofiles            : /usr/lib/rpm/macros:/usr/lib/rpm/i686-linux/macros:/usr/lib/rpm/redhat/macros:/etc/rpm/macros.*:/etc/rpm/macr
os:/etc/rpm/i686-linux/macros:~/.rpmmacros
optflags              : %{__global_cflags} -m32 -march=i686 -mtune=generic -fasynchronous-unwind-tables

Features supported by rpmlib:
    rpmlib(VersionedDependencies) = 3.0.3-1
	PreReq:, Provides:, and Obsoletes: dependencies support versions.
    rpmlib(CompressedFileNames) = 3.0.4-1
	file name(s) stored as (dirName,baseName,dirIndex) tuple, not as path.
    rpmlib(PayloadIsBzip2) = 3.0.5-1
	package payload can be compressed using bzip2.
    rpmlib(PayloadFilesHavePrefix) = 4.0-1
	package payload file(s) have "./" prefix.
    rpmlib(ExplicitPackageProvide) = 4.0-1
	package name-version-release is not implicitly provided.
    rpmlib(HeaderLoadSortsTags) = 4.0.1-1
	header tags are always sorted after being loaded.
    rpmlib(ScriptletInterpreterArgs) = 4.0.3-1
	the scriptlet interpreter can use arguments from header.
    rpmlib(PartialHardlinkSets) = 4.0.4-1
	a hardlink file set may be installed without being complete.
    rpmlib(ConcurrentAccess) = 4.1-1
	package scriptlets may access the rpm database while installing.
    rpmlib(BuiltinLuaScripts) = 4.2.2-1
	internal support for lua scripts.

========================
-14: GNUconfigure(MCs:)	
  CFLAGS="${CFLAGS:-%optflags}" ; export CFLAGS; 
  LDFLAGS="${LDFLAGS:-%{-s:-s}}"  ; export LDFLAGS; 
  %{-C:_mydir="`pwd`"; %{-M: %{__mkdir} -p %{-C*};} cd %{-C*}} 
  dirs="`find ${_mydir} -name configure.in -print`"; export dirs; 
    for coin in `echo ${dirs}` 
do 
  dr=`dirname ${coin}`; 
if test -f ${dr}/NO-AUTO-GEN; then 
 : 
else 
     macrodirs=`sed -n -e 's,AM_ACLOCAL_INCLUDE((.*)),1,gp' < ${coin}`; 
    ( cd ${dr}; 
      aclocalinclude="${ACLOCAL_FLAGS}"; 
      for k in ${macrodirs}; do 
        if test -d ${k}; then 
          aclocalinclude="${aclocalinclude} -I ${k}"; 
        ##else 
        ##  echo "**Warning**: No such directory `${k}'.  Ignored." 
        fi 
      done 
      if grep "^AM_GNU_GETTEXT" configure.in >/dev/null; then 
        if grep "sed.*POTFILES" configure.in >/dev/null; then 
          : do nothing -- we still have an old unmodified configure.in 
        else 
          test -r ${dr}/aclocal.m4 || touch ${dr}/aclocal.m4; 
          echo "no" | gettextize --force --copy; 
          test -r ${dr}/aclocal.m4 && %{__chmod} u+w ${dr}/aclocal.m4; 
        fi 
      fi 
      if grep "^AM_PROG_LIBTOOL" configure.in >/dev/null; then 
        %{__libtoolize} --force --copy; 
      fi 
      aclocal ${aclocalinclude}; 
      if grep "^AM_CONFIG_HEADER" configure.in >/dev/null; then 
        %{__autoheader}; 
      fi 
      echo "Running automake --gnu ${am_opt} ..."; 
      %{__automake} --add-missing --gnu ${am_opt}; 
      %{__autoconf}; 
    ); 
  fi 
done 
  %{-C:${_mydir}}%{!-C:.}/configure %{_target_platform} --prefix=%{_prefix} --exec-prefix=%{_exec_prefix} --bindir=%{_bindir} --sbin
dir=%{_sbindir} --sysconfdir=%{_sysconfdir} --datadir=%{_datadir} --includedir=%{_includedir} --libdir=%{_libdir} --libexecdir=%{_li
bexecdir} --localstatedir=%{_localstatedir} --sharedstatedir=%{_sharedstatedir} --mandir=%{_mandir} --infodir=%{_infodir} %* ; 
  %{-C:cd ${_mydir}; unset _mydir}
-14: ___build_args	-e
-14: ___build_cmd	%{?_sudo:%{_sudo} }%{?_remsh:%{_remsh} %{_remhost} }%{?_remsudo:%{_remsudo} }%{?_remchroot:%{_remchroot} %
{_remroot} }%{___build_shell} %{___build_args}
-14: ___build_post	exit 0
-14: ___build_pre	
RPM_SOURCE_DIR="%{u2p:%{_sourcedir}}"
RPM_BUILD_DIR="%{u2p:%{_builddir}}"
RPM_OPT_FLAGS="%{optflags}"
RPM_ARCH="%{_arch}"
RPM_OS="%{_os}"
export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS
RPM_DOC_DIR="%{_docdir}"
export RPM_DOC_DIR
RPM_PACKAGE_NAME="%{name}"
RPM_PACKAGE_VERSION="%{version}"
RPM_PACKAGE_RELEASE="%{release}"
export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE
%{?buildroot:RPM_BUILD_ROOT="%{u2p:%{buildroot}}"
export RPM_BUILD_ROOT}
%{?_javaclasspath:CLASSPATH="%{_javaclasspath}"
export CLASSPATH}
PKG_CONFIG_PATH="%{_libdir}/pkgconfig:%{_datadir}/pkgconfig"
export PKG_CONFIG_PATH

%{verbose:set -x}%{!verbose:exec > /dev/null}
umask 022
cd %{u2p:%{_builddir}}
%{nil}
-14: ___build_shell	%{?_buildshell:%{_buildshell}}%{!?_buildshell:/bin/sh}
-14: ___build_template	#!%{___build_shell}
%{___build_pre}
%{nil}
-14: __aclocal	aclocal
-14: __ar	ar
-14: __arch_install_post	%{nil}
-14: __as	as
-14: __autoconf	autoconf
-14: __autoheader	autoheader
-14: __automake	automake
-14: __awk	gawk
-14: __bzip2	/usr/bin/bzip2
-14: __cat	/bin/cat
-14: __cc	gcc
-14: __check_files	/usr/lib/rpm/check-files %{buildroot}
-14: __chgrp	/bin/chgrp
-14: __chgrp_Rhf	%{__chgrp} -Rhf
-14: __chmod	/bin/chmod
-14: __chown	/bin/chown
-14: __chown_Rhf	%{__chown} -Rhf
-14: __cp	/bin/cp
-14: __cpio	/bin/cpio
-14: __cpp	gcc -E
-14: __cxx	g++
-14: __dbi_btconfig	
  btree		
  %{__dbi_other}
  %{__dbi_perms}
%{nil}
-14: __dbi_btconfig_current	%{__dbi_btconfig}
-14: __dbi_btconfig_rebuild	%{__dbi_btconfig} %{__dbi_rebuild}
-14: __dbi_cdb	create cdb mpool mp_mmapsize=16Mb mp_size=1Mb
-14: __dbi_htconfig	
  hash		
  %{__dbi_other}
  %{__dbi_perms}
%{nil}
-14: __dbi_htconfig_current	%{__dbi_htconfig}
-14: __dbi_htconfig_rebuild	%{__dbi_htconfig} %{__dbi_rebuild}
-14: __dbi_other	%{?_tmppath:tmpdir=%{_tmppath}} %{?__dbi_cdb}
-14: __dbi_perms	perms=0644
-14: __dbi_rebuild	nofsync !log !txn !cdb
-14: __dbi_transient	%{__dbi_rebuild} temporary private
-14: __debug_install_post	
   /usr/lib/rpm/find-debuginfo.sh %{?_missing_build_ids_terminate_build:--strict-build-id} %{?_find_debuginfo_opts} "%{_builddir}/%{?
buildsubdir}"
%{nil}
-14: __file	/usr/bin/file
-14: __file_context_path	/etc/selinux/%{__policy_tree}/contexts/files/file_contexts
-14: __find_provides	/usr/lib/rpm/redhat/find-provides
-14: __find_requires	/usr/lib/rpm/redhat/find-requires
-14: __global_cflags	-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4
-14: __gpg	/usr/bin/gpg
-14: __gpg_check_password_cmd	%{__gpg} 
	gpg --batch --no-verbose --passphrase-fd 3 -u "%{_gpg_name}" -so -
-14: __gpg_sign_cmd	%{__gpg} 
	gpg --batch --no-verbose --no-armor --passphrase-fd 3 --no-secmem-warning 
	-u "%{_gpg_name}" -sbo %{__signature_filename} %{__plaintext_filename}
-14: __grep	/bin/grep
-14: __gzip	/usr/bin/gzip
-14: __id	/usr/bin/id
-14: __id_u	%{__id} -u
-14: __install	/usr/bin/install
-14: __ld	/usr/bin/ld
-14: __libtoolize	libtoolize
-14: __ln_s	ln -s
-14: __lzma	%{__xz} --format=lzma
-14: __make	/usr/bin/make
-14: __mkdir	/bin/mkdir
-14: __mkdir_p	/bin/mkdir -p
-14: __mono_provides	/usr/lib/rpm/mono-find-provides %{_builddir}/%{?buildsubdir} %{buildroot} %{_libdir}
-14: __mono_requires	/usr/lib/rpm/mono-find-requires %{_builddir}/%{?buildsubdir} %{buildroot} %{_libdir}
-14: __mv	/bin/mv
-14: __nm	/usr/bin/nm
-14: __objcopy	/usr/bin/objcopy
-14: __objdump	/usr/bin/objdump
-14: __os_install_post	
    /usr/lib/rpm/redhat/brp-compress 
    %{!?__debug_package:/usr/lib/rpm/redhat/brp-strip %{__strip}} 
    /usr/lib/rpm/redhat/brp-strip-static-archive %{__strip} 
    /usr/lib/rpm/redhat/brp-strip-comment-note %{__strip} %{__objdump} 
    /usr/lib/rpm/brp-python-bytecompile 
    /usr/lib/rpm/redhat/brp-java-repack-jars 
%{nil}
-14: __patch	/usr/bin/patch
-14: __perl	/usr/bin/perl
-14: __perl_provides	/usr/lib/rpm/perl.prov
-14: __perl_requires	/usr/lib/rpm/perl.req
-14: __pgp	/usr/bin/pgp
-14: __pgp5_check_password_cmd	%{__pgp} 
	pgps +batchmode=on +verbose=0 +armor=off "%{_pgp_name}" -f
-14: __pgp5_sign_cmd	%{__pgp} 
	pgps +batchmode=on +verbose=0 +armor=off 
	"+myname=%{_pgp_name}" -b %{__plaintext_filename} -o %{__signature_filename}
-14: __pgp_check_password_cmd	%{__pgp} 
	pgp +batchmode=on +verbose=0 "%{_pgp_name}" -sf
-14: __pgp_sign_cmd	%{__pgp} 
	pgp +batchmode=on +verbose=0 +armor=off 
	"+myname=%{_pgp_name}" -sb %{__plaintext_filename} %{__signature_filename}
-14: __policy_tree	%{expand:%%global __policy_tree %{lua:
t="targeted"
f = io.open("/etc/selinux/config")
if f then
  for l in f:lines() do
    if "SELINUXTYPE=" == string.sub(l,0,12) then t=string.sub(l,13); end
  end
  f:close()
end
print (t)
}}%{__policy_tree}
-14: __prelink_undo_cmd	/usr/sbin/prelink prelink -y library
-14: __python	/usr/bin/python
-14: __python_provides	/usr/lib/rpm/pythondeps.sh --provides
-14: __python_requires	/usr/lib/rpm/pythondeps.sh --requires
-14: __ranlib	ranlib
-14: __remsh	%{__rsh}
-14: __rm	/bin/rm
-14: __rsh	/usr/bin/rsh
-14: __sed	/bin/sed
-14: __spec_build_args	%{___build_args}
-14: __spec_build_body	%{___build_body}
-14: __spec_build_cmd	%{___build_cmd}
-14: __spec_build_post	%{___build_post}
-14: __spec_build_pre	%{___build_pre}
-14: __spec_build_shell	%{___build_shell}
-14: __spec_build_template	#!%{__spec_build_shell}
%{__spec_build_pre}
%{nil}
-14: __spec_check_args	%{___build_args}
-14: __spec_check_body	%{___build_body}
-14: __spec_check_cmd	%{___build_cmd}
-14: __spec_check_post	%{___build_post}
-14: __spec_check_pre	%{___build_pre}
-14: __spec_check_shell	%{___build_shell}
-14: __spec_check_template	#!%{__spec_check_shell}
%{__spec_check_pre}
%{nil}
-14: __spec_clean_args	%{___build_args}
-14: __spec_clean_body	%{___build_body}
-14: __spec_clean_cmd	%{___build_cmd}
-14: __spec_clean_post	%{___build_post}
-14: __spec_clean_pre	%{___build_pre}
-14: __spec_clean_shell	%{___build_shell}
-14: __spec_clean_template	#!%{__spec_clean_shell}
%{__spec_clean_pre}
%{nil}
-14: __spec_install_args	%{___build_args}
-14: __spec_install_body	%{___build_body}
-14: __spec_install_cmd	%{___build_cmd}
-14: __spec_install_post	
    %{?__debug_package:%{__debug_install_post}}
    %{__arch_install_post}
    %{__os_install_post}
%{nil}
-14: __spec_install_pre	%{___build_pre}
-14: __spec_install_shell	%{___build_shell}
-14: __spec_install_template	#!%{__spec_install_shell}
%{__spec_install_pre}
%{nil}
-14: __spec_prep_args	%{___build_args}
-14: __spec_prep_body	%{___build_body}
-14: __spec_prep_cmd	%{___build_cmd}
-14: __spec_prep_post	%{___build_post}
-14: __spec_prep_pre	%{___build_pre}
-14: __spec_prep_shell	%{___build_shell}
-14: __spec_prep_template	#!%{__spec_prep_shell}
%{__spec_prep_pre}
%{nil}
-14: __spec_rmbuild_args	%{___build_args}
-14: __spec_rmbuild_body	%{___build_body}
-14: __spec_rmbuild_cmd	%{___build_cmd}
-14: __spec_rmbuild_post	%{___build_post}
-14: __spec_rmbuild_pre	%{___build_pre}
-14: __spec_rmbuild_shell	%{___build_shell}
-14: __spec_rmbuild_template	#!%{__spec_rmbuild_shell}
%{__spec_rmbuild_pre}
%{nil}
-14: __ssh	/usr/bin/ssh
-14: __strip	/usr/bin/strip
-14: __tar	/bin/tar
-14: __unzip	/usr/bin/unzip
-14: __vsflags	0xf0000
-14: __xz	%{_bindir}/xz
-14: _arch	i386
-14: _autorelocate_dcolor	0
-14: _autorelocate_path	%{nil}
-14: _bhA	RPMS
-14: _bhN	@(SRPMS|i386|alpha|sparc|s390|ia64)
-14: _bhVR	RedHat
-14: _bhcoll	@(7.3|7.2|7.1|7.1sbe|7.1k|7.0|7.01j|7.0j|7.0sbe|7.0tc|6.2|6.2ha|6.2ee|6.1|6.0|5.2|5.1|5.0)
-14: _bhpath	file://localhost/mnt/dist
-14: _bindir	%{_exec_prefix}/bin
-14: _build	%{_host}
-14: _build_alias	%{_host_alias}
-14: _build_arch	i386
-14: _build_cpu	%{_host_cpu}
-14: _build_file_context_path	%{nil}
-14: _build_name_fmt	%%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm
-14: _build_os	%{_host_os}
-14: _build_vendor	%{_host_vendor}
-14: _builddir	%{_topdir}/BUILD
-14: _buildshell	/bin/sh
-14: _bzip2bin	%{__bzip2}
-14: _cache_dbpath	/var/spool/up2date/cache
-14: _datadir	%{_prefix}/share
-14: _dbapi	3
-14: _dbapi_rebuild	3
-14: _dbi_btconfig	
  %{?_rpmdb_rebuild:%{__dbi_btconfig_rebuild}}
  %{!?_rpmdb_rebuild:%{__dbi_btconfig_current}}
%{nil}
-14: _dbi_config	%{_dbi_htconfig}
-14: _dbi_config_Depends	%{_dbi_htconfig} temporary private
-14: _dbi_config_Dirnames	%{_dbi_btconfig}
-14: _dbi_config_Installtid	%{_dbi_btconfig}
-14: _dbi_config_Packages	%{_dbi_htconfig} lockdbfd
-14: _dbi_config_Provideversion	%{_dbi_btconfig}
-14: _dbi_config_Removetid	%{_dbi_btconfig}
-14: _dbi_config_Requireversion	%{_dbi_btconfig}
-14: _dbi_htconfig	
  %{?_rpmdb_rebuild:%{__dbi_htconfig_rebuild}}
  %{!?_rpmdb_rebuild:%{__dbi_htconfig_current}}
%{nil}
-14: _dbi_tags	Packages:Name:Basenames:Group:Requirename:Providename:Conflictname:Triggername:Dirnames:Requireversion:Provideversion:
Installtid:Sigmd5:Sha1header:Filemd5s:Depends:Pubkeys
-14: _dbpath	%{_var}/lib/rpm
-14: _dbpath_rebuild	%{_dbpath}
-14: _default_patch_fuzz	-1
-14: _defaultdocdir	%{_usr}/share/doc
-14: _dependency_whiteout	
	%{nil}
-14: _desktopdir	%{_datadir}/applications
-14: _enable_debug_packages	1
-14: _exec_prefix	%{_prefix}
-14: _filter_GLIBC_PRIVATE	0
-14: _fixgroup	[ `%{__id_u}` = '0' ] && %{__chgrp_Rhf} root
-14: _fixowner	[ `%{__id_u}` = '0' ] && %{__chown_Rhf} root
-14: _fixperms	%{__chmod} -Rf a+rX,u+w,g-w,o-w
-14: _gcj_support	1
-14: _gnu	-gnu
-14: _gzipbin	%{__gzip}
-14: _hkp_keyserver	%{nil}
-14: _host	i686-redhat-linux-gnu
-14: _host_alias	%{nil}
-14: _host_cpu	i686
-14: _host_os	linux-gnu
-14: _host_vendor	redhat
-14: _i18ndomains	redhat-dist
-14: _icons16dir	%{_iconsbasedir}/16x16/apps
-14: _icons192dir	%{_iconsbasedir}/192x192/apps
-14: _icons22dir	%{_iconsbasedir}/22x22/apps
-14: _icons48dir	%{_iconsbasedir}/48x48/apps
-14: _icons64dir	%{_iconsbasedir}/64x64/apps
-14: _icons96dir	%{_iconsbasedir}/96x96/apps
-14: _iconsbasedir	%{_datadir}/icons/%{_iconstheme}
-14: _iconsdir	%{_datadir}/icons
-14: _iconsscaldir	%{_iconsbasedir}/scalable/apps
-14: _iconstheme	hicolor
-14: _includedir	%{_prefix}/include
-14: _infodir	/usr/share/info
-14: _initrddir	%{_sysconfdir}/rc.d/init.d
-14: _install_file_context_path	%{__file_context_path}
-14: _install_langs	all
-14: _install_script_path	/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin
-14: _instchangelog	5
-14: _javadir	%{_datadir}/java
-14: _javadocdir	%{_datadir}/javadoc
-14: _jnidir	%{_prefix}/lib/java
-14: _jvmcommondatadir	%{_datadir}/jvm-commmon
-14: _jvmcommonlibdir	%{_prefix}/lib/jvm-commmon
-14: _jvmcommonsysconfdir	%{_sysconfdir}/jvm-commmon
-14: _jvmdatadir	%{_datadir}/jvm
-14: _jvmdir	%{_prefix}/lib/jvm
-14: _jvmjardir	%{_prefix}/lib/jvm-exports
-14: _jvmlibdir	%{_prefix}/lib/jvm
-14: _jvmprivdir	%{_prefix}/lib/jvm-private
-14: _jvmsysconfdir	%{_sysconfdir}/jvm
-14: _lib	lib
-14: _libdir	%{_exec_prefix}/%{_lib}
-14: _libexecdir	%{_exec_prefix}/libexec
-14: _liconsdir	%{_datadir}/icons/large
-14: _localstatedir	/var
-14: _mandir	/usr/share/man
-14: _mavendepmapdir	/etc/maven
-14: _mavendepmapfragdir	/etc/maven/fragments
-14: _menudir	%{_prefix}/lib/menu
-14: _miconsdir	%{_datadir}/icons/mini
-14: _missing_doc_files_terminate_build	1
-14: _multilibno	1
-14: _multilibpatt	(/%{_lib}|/usr/%{_lib}(|/gconv)|/usr/local/%{_lib}|/usr/X11R6/%{_lib}|/opt/%{_lib})/[^/]*\.([oa]|la|so[0-9.]*)$
-14: _oldincludedir	/usr/include
-14: _os	linux
-14: _package_version	30005
-14: _pgpbin	%{__pgp}
-15: _preScriptEnvironment	
RPM_SOURCE_DIR="%{_sourcedir}"
RPM_BUILD_DIR="%{_builddir}"
RPM_OPT_FLAGS="%{optflags}"
RPM_ARCH="%{_arch}"
RPM_OS="%{_os}"
export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS
RPM_DOC_DIR="%{_docdir}"
export RPM_DOC_DIR
RPM_PACKAGE_NAME="%{name}"
RPM_PACKAGE_VERSION="%{version}"
RPM_PACKAGE_RELEASE="%{release}"
export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE
%{?buildroot:RPM_BUILD_ROOT="%{buildroot}"
export RPM_BUILD_ROOT
}
-14: _prefix	/usr
-14: _query_all_fmt	%%{name}-%%{version}-%%{release}
-14: _query_selector_match	default
-14: _repackage_all_erasures	0
-14: _repackage_dir	/var/spool/repackage
-14: _repackage_name_fmt	%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm
-14: _repackage_root	%{nil}
-14: _rollback_transaction_on_failure	0
-14: _rpmdir	%{_topdir}/RPMS
-14: _rpmfilename	%{_build_name_fmt}
-14: _rpmlock_path	%{_dbpath}/__db.000
-14: _sbindir	%{_exec_prefix}/sbin
-14: _sharedstatedir	%{_prefix}/com
-14: _signature	gpg
-14: _smp_mflags	%([ -z "$RPM_BUILD_NCPUS" ] \
	&& RPM_BUILD_NCPUS="`/usr/bin/getconf _NPROCESSORS_ONLN`"; \
	[ "$RPM_BUILD_NCPUS" -gt 1 ] && echo "-j$RPM_BUILD_NCPUS")
-14: _sourcedir	%{_topdir}/SOURCES
-14: _specdir	%{_topdir}/SPECS
-14: _srcrpmdir	%{_topdir}/SRPMS
-14: _sysconfdir	/etc
-11: _target	i386-linux
-14: _target_alias	%{_host_alias}
-11= _target_cpu	i386
-11= _target_os	linux
-14: _target_platform	%{_target_cpu}-%{_vendor}-%{_target_os}%{?_gnu}
-14: _target_vendor	%{_host_vendor}
-14: _tmppath	%{_var}/tmp
-14: _topdir	%{_usrsrc}/redhat
-14: _transaction_color	0
-14: _unpackaged_files_terminate_build	1
-14: _unzipbin	%{__unzip}
-14: _use_internal_dependency_generator	1
-14: _usr	/usr
-14: _usrsrc	%{_usr}/src
-14: _var	/var
-14: _vendor	redhat
-14: _verify_file_context_path	%{__file_context_path}
-14: _vsflags_build	%{__vsflags}
-14: _vsflags_erase	%{__vsflags}
-14: _vsflags_install	%{__vsflags}
-14: _vsflags_query	%{__vsflags}
-14: _vsflags_rebuilddb	%{__vsflags}
-14: _vsflags_up2date	%{__vsflags}
-14: _vsflags_verify	%{__vsflags}
-14: add_jvm_extension	JAVA_LIBDIR=%{buildroot}/%{_javadir}	%{_bindir}/jvmjar -l
-14: add_to_maven_depmap	
install -dm 755 $RPM_BUILD_ROOT/%{_mavendepmapfragdir}
cat >>$RPM_BUILD_ROOT/%{_mavendepmapfragdir}/%{name}<< EOF
<dependency>
    <maven>
        <groupId>%1</groupId>
        <artifactId>%2</artifactId>
        <version>%3</version>
    </maven>
    <jpp>
        <groupId>%4</groupId>
        <artifactId>%5</artifactId>
        <version>%3</version>
    </jpp>
</dependency>

EOF
%{nil}
-14: alpha	alpha alphaev56 alphaev6 alphaev67
-14: ant	JAVA_HOME=%{java_home} ant
-14: arm	armv3l armv4b armv4l armv4tl armv5tel armv5tejl armv6l
-14: bcond_with	%{expand:%%{?_with_%{1}:%%global with_%{1} 1}}
-14: bcond_without	%{expand:%%{!?_without_%{1}:%%global with_%{1} 1}}
-14: build	%%build
LANG=C
export LANG
unset DISPLAY
%{nil}
-14: configure	
  CFLAGS="${CFLAGS:-%optflags}" ; export CFLAGS ; 
  CXXFLAGS="${CXXFLAGS:-%optflags}" ; export CXXFLAGS ; 
  FFLAGS="${FFLAGS:-%optflags}" ; export FFLAGS ; 
  for i in $(find . -name config.guess -o -name config.sub) ; do 
           [ -f /usr/lib/rpm/redhat/$(basename $i) ] && %{__rm} -f $i && %{__cp} -fv /usr/lib/rpm/redhat/$(basename $i) $i ; 
  done ; 
  ./configure --build=%{_build} --host=%{_host} \
	--target=%{_target_platform} \
	--program-prefix=%{?_program_prefix} \
	--prefix=%{_prefix} \
	--exec-prefix=%{_exec_prefix} \
	--bindir=%{_bindir} \
	--sbindir=%{_sbindir} \
	--sysconfdir=%{_sysconfdir} \
	--datadir=%{_datadir} \
	--includedir=%{_includedir} \
	--libdir=%{_libdir} \
	--libexecdir=%{_libexecdir} \
	--localstatedir=%{_localstatedir} \
	--sharedstatedir=%{_sharedstatedir} \
	--mandir=%{_mandir} \
	--infodir=%{_infodir}
-14: debug_package	
%ifnarch noarch
%global __debug_package 1
%package debuginfo 
Summary: Debug information for package %{name}
Group: Development/Debug
%description debuginfo
This package provides debug information for package %{name}.
Debug information is useful when developing applications that use this
package or when debugging this package.
%files debuginfo -f debugfiles.list
%defattr(-,root,root)
%endif
%{nil}
-14: defined	%{expand:%%{?%{1}:1}%%{!?%{1}:0}}
-14: find_lang	/usr/lib/rpm/redhat/find-lang.sh %{buildroot}
-14: install	%{?_enable_debug_packages:%{?buildsubdir:%{debug_package}}}
%%install
LANG=C
export LANG
unset DISPLAY
%{nil}
-14: ix86	i386 i486 i586 i686 pentium3 pentium4 athlon geode
-14: jar	%{java_home}/bin/jar
-14: java	%(. %{_javadir}-utils/java-functions; set_javacmd; echo $JAVACMD)
-14: java_home	%(. %{_javadir}-utils/java-functions; set_jvm; echo $JAVA_HOME)
-14: javac	%{java_home}/bin/javac
-14: javadoc	%{java_home}/bin/javadoc
-14: jpackage_script	
install -d -m 755 $RPM_BUILD_ROOT%{_bindir}
cat > $RPM_BUILD_ROOT%{_bindir}/%5 << EOF 
#!/bin/sh
#
# %{name} script
# JPackage Project <http://www.jpackage.org/>

# Source functions library
. %{_javadir}-utils/java-functions

# Source system prefs
if [ -f %{_sysconfdir}/java/%{name}.conf ] ; then
  . %{_sysconfdir}/java/%{name}.conf
fi

# Source user prefs
if [ -f \$HOME/.%{name}rc ] ; then
  . \$HOME/.%{name}rc
fi

# Configuration
MAIN_CLASS=%1
BASE_FLAGS=%2
BASE_OPTIONS=%3
BASE_JARS="%(echo %4 | sed -e 's,:, ,g')"

# Set parameters
set_jvm
set_classpath \$BASE_JARS
set_flags \$BASE_FLAGS
set_options \$BASE_OPTIONS

# Let's start
run "\$@"
EOF
-14: kernel_module_package(n:v:r:s:f:xp:)	%{expand:%( 
	%define kmodtool %{-s*}%{!-s:/usr/lib/rpm/redhat/kmodtool} 
	%define kmp_version %{-v*}%{!-v:%{version}} 
	%define kmp_release %{-r*}%{!-r:%{release}} 
	%define latest_kernel %(rpm -q --qf '%{VERSION}-%{RELEASE}\\n' `rpm -q kernel-devel | /usr/lib/rpm/redhat/rpmsort -r | head -n
 1` | head -n 1) 
	%{!?kernel_version:%{expand:%%global kernel_version %{latest_kernel}}} 
	%global kverrel %(%{kmodtool} verrel %{?kernel_version} 2>/dev/null) 
	flavors="default" 
	if [ "i686" == "%{_target_cpu}" ] 
	then 
		xenver=$(rpm -q kernel-xen-devel-%{kverrel}|head -n 1)
		kdver=$(rpm -q kernel-kdump-devel-%{kverrel}|head -n 1)
		paever=$(rpm -q kernel-PAE-devel-%{kverrel}|head -n 1)
		if [ "kernel-xen-devel-%{kverrel}" == "$xenver" ] 
		then 
			flavors="$flavors xen" 
		fi 
		if [ "kernel-kdump-devel-%{kverrel}" == "$kdver" ] 
		then 
			flavors="$flavors kdump" 
		fi 
		if [ "kernel-PAE-devel-%{kverrel}" == "$paever" ] 
		then
			flavors="$flavors PAE" 
		fi 
	fi 
	if [ "x86_64" == "%{_target_cpu}" ] 
	then 
		xenver=$(rpm -q kernel-xen-devel-%{kverrel}|head -n 1)
		if [ "kernel-xen-devel-%{kverrel}" == "$xenver" ] 
		then 
			flavors="$flavors xen" 
		fi 
	fi 
	if [ "ppc64" == "%{_target_cpu}" ] || [ "ppc64iseries" == "%{_target_cpu}" ] 
	then 
		kdver=$(rpm -q kernel-kdump-devel-%{kverrel}|head -n 1)
		if [ "kernel-kdump-devel-%{kverrel}" == "$kdver" ] 
		then 
			flavors="$flavors kdump" 
		fi 
	fi 
	if [ "ia64" == "%{_target_cpu}" ] 
	then 
		xenver=$(rpm -q kernel-xen-devel-%{kverrel}|head -n 1)
		if [ "kernel-xen-devel-%{kverrel}" == "$xenver" ] 
		then 
			flavors="$flavors xen" 
		fi 
	fi 
	if [ -z "%*" ]; then 
		flavors_to_build=$flavors 
	elif [ -z "%{-x}" ]; then 
		flavors_to_build="%*" 
	else 
		flavors_to_build=" $flavors "
		echo "[$flavors_to_build]" >/tmp/tmp.txt
		for i in %* 
		do 
			flavors_to_build=${flavors_to_build//$i /}
		done 
	fi 
	echo "%%global flavors_to_build ${flavors_to_build:-%%nil}" 
	echo "%%global kernel_source() /usr/src/kernels/%kverrel-\$([ %%%%{1} = default ] || echo "%%%%{1}-")%_target_cpu" 
	if [ ! -z "%{-f*}" ] 
	then 
		filelist="%{-f*}" 
	fi 
	if [ ! -z "%{-p*}" ] 
	then 
		preamble="%{-p*}" 
	fi 
	if [ -z "%{kmodtool_generate_buildreqs}" ] 
	then 
		nobuildreqs="yes" 
	fi 
	if [ ! -z "%{-v*}" ] 
	then 
		kmp_version="%{kmp_version}" 
	fi 
	if [ ! -z "%{-r*}" ] 
	then 
		kmp_release="%{kmp_release} " 
	fi 
	kmp_override_filelist="$filelist" kmp_override_preamble="$preamble" kmp_nobuildreqs="$buildreqs" kmp_version="$kmp_version"
 kmp_release="$kmp_release" %{kmodtool} rpmtemplate_kmp %{-n*}%{!-n:%name} %{kverrel} $flavors_to_build 2>/dev/null 
)}
-14: kernel_module_package_buildreqs	%global kmodtool_generate_buildreqs 1 
					kernel-devel
-14: makeinstall	
  %{__make} \
	prefix=%{?buildroot:%{buildroot}}%{_prefix} \
	exec_prefix=%{?buildroot:%{buildroot}}%{_exec_prefix} \
	bindir=%{?buildroot:%{buildroot}}%{_bindir} \
	sbindir=%{?buildroot:%{buildroot}}%{_sbindir} \
	sysconfdir=%{?buildroot:%{buildroot}}%{_sysconfdir} \
	datadir=%{?buildroot:%{buildroot}}%{_datadir} \
	includedir=%{?buildroot:%{buildroot}}%{_includedir} \
	libdir=%{?buildroot:%{buildroot}}%{_libdir} \
	libexecdir=%{?buildroot:%{buildroot}}%{_libexecdir} \
	localstatedir=%{?buildroot:%{buildroot}}%{_localstatedir} \
	sharedstatedir=%{?buildroot:%{buildroot}}%{_sharedstatedir} \
	mandir=%{?buildroot:%{buildroot}}%{_mandir} \
	infodir=%{?buildroot:%{buildroot}}%{_infodir} \
  install
-14: mdkicons	
install -D -m 644 %1-48.png $RPM_BUILD_ROOT%{_liconsdir}/%1.png
install -D -m 644 %1-32.png $RPM_BUILD_ROOT%{_iconsdir}/%1.png
install -D -m 644 %1-16.png $RPM_BUILD_ROOT%{_miconsdir}/%1.png
-14: mdkmenu	
install -d -m 755 $RPM_BUILD_ROOT%{_menudir}
cat >$RPM_BUILD_ROOT%{_menudir}/%1 <<EOF
?package(%1):\
-14: nil	%{!?nil}
-11: optflags	%{__global_cflags} -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables
-14: perl_archlib	%(eval "`%{__perl} -V:installarchlib`"; echo $installarchlib)
-14: perl_privlib	%(eval "`%{__perl} -V:installprivlib`"; echo $installprivlib)
-14: perl_sitearch	%(eval "`%{__perl} -V:installsitearch`"; echo $installsitearch)
-14: perl_sitelib	%(eval "`%{__perl} -V:installsitelib`"; echo $installsitelib)
-14: perl_vendorarch	%(eval "`%{__perl} -V:installvendorarch`"; echo $installvendorarch)
-14: perl_vendorlib	%(eval "`%{__perl} -V:installvendorlib`"; echo $installvendorlib)
-14: post_mdkmenu	
%post mdkmenu
%{update_menus}
-14: postun_mdkmenu	
%postun mdkmenu
%{clean_menus}
-14: prep	
%%prep
LANG=C
export LANG
unset DISPLAY
%{nil}
-14: requires_eq	%(LC_ALL="C" echo '%*' | xargs -r rpm -q --qf 'Requires: %%{name} = %%{epoch}:%%{version}\n' | sed -e 's/ 
(none):/ /' -e 's/ 0:/ /' | grep -v "is not")
-14: rhicons	
install -D -m 644 %1-48.png $RPM_BUILD_ROOT%{_datadir}/icons/hicolor/48x48/apps/%{name}.png
install -D -m 644 %1-32.png $RPM_BUILD_ROOT%{_datadir}/icons/hicolor/32x32/apps/%{name}.png
install -D -m 644 %1-16.png $RPM_BUILD_ROOT%{_datadir}/icons/hicolor/16x16/apps/%{name}.png
-14: rhmenu	
install -d -m 755 $RPM_BUILD_ROOT%{_sysconfdir}/X11/applnk/%4
cat >$RPM_BUILD_ROOT%{_sysconfdir}/X11/applnk/%4/%1.desktop <<EOF
[Desktop Entry]
Name=%6
Comment=%7
Exec=%2
Terminal=%3
Type=%9
Icon=%8
EOF
-15: sigtype	none
-14: undefined	%{expand:%%{?%{1}:0}%%{!?%{1}:1}}
-14: update_maven_depmap	
echo -e "<dependencies>\n" > %{_mavendepmapdir}/maven2-depmap.xml
if [ -d %{_mavendepmapfragdir} ] && [ -n "`find %{_mavendepmapfragdir} -type f`" ]; then
cat %{_mavendepmapfragdir}/* >> %{_mavendepmapdir}/maven2-depmap.xml
fi
echo -e "</dependencies>\n" >> %{_mavendepmapdir}/maven2-depmap.xml
-14: with	%{expand:%%{?with_%{1}:1}%%{!?with_%{1}:0}}
-14: without	%{expand:%%{?with_%{1}:0}%%{!?with_%{1}:1}}
======================== active 325 empty 0
[root@localhost ~]# rpmbuild --showrc | grep macrofile(查看rpmbuild所有宏只显示macrofile相关)
macrofiles            : /usr/lib/rpm/macros:/usr/lib/rpm/i686-linux/macros:/usr/lib/rpm/redhat/macros:/etc/rpm/macros.*:/etc/rpm/macr
os:/etc/rpm/i686-linux/macros:~/.rpmmacros(定义了系统定义这些宏到底在什么文件中定义的,读取次序从前到后)
[root@localhost ~]# rpmbuild --showrc | grep _topdir(查看rpmbuild所有宏将结果送给管道只显示_topdir相关)
-14: _builddir	%{_topdir}/BUILD
-14: _rpmdir	%{_topdir}/RPMS
-14: _sourcedir	%{_topdir}/SOURCES
-14: _specdir	%{_topdir}/SPECS
-14: _srcrpmdir	%{_topdir}/SRPMS
-14: _topdir	%{_usrsrc}/redhat
[root@localhost ~]# rpmbuild --showrc | grep _usrsrc(查看rpmbuild所有宏将结果送给管道只显示_usrsrc相关)
-14: _topdir	%{_usrsrc}/redhat
-14: _usrsrc	%{_usr}/src
[root@localhost ~]# rpmbuild --showrc | grep _usr(查看rpmbuild所有宏将结果送给管道只显示_usr相关)   
-14: _defaultdocdir	%{_usr}/share/doc
-14: _topdir	%{_usrsrc}/redhat
-14: _usr	/usr
-14: _usrsrc	%{_usr}/src
[root@localhost ~]# su - Smoke(切换到Smoke用户)
[Smoke@localhost ~]$ rpmbuild --showrc | grep _topdir(显示rpmbuild所有宏将结果送给管道只显示_topdir相关)
-14: _builddir	%{_topdir}/BUILD
-14: _rpmdir	%{_topdir}/RPMS
-14: _sourcedir	%{_topdir}/SOURCES
-14: _specdir	%{_topdir}/SPECS
-14: _srcrpmdir	%{_topdir}/SRPMS
-14: _topdir	%{_usrsrc}/redhat
[Smoke@localhost ~]$ vim .rpmmacros(编辑.rpmmacros文件)

%_topdir        /home/Smoke/rpmbuild(一定要是自己能否访问的目录)

[Smoke@localhost ~]$ mkdir -pv rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}(创建目录,-p递归创建,-v显示创建过程)
mkdir: created directory `rpmbuild'
mkdir: created directory `rpmbuild/BUILD'
mkdir: created directory `rpmbuild/RPMS'
mkdir: created directory `rpmbuild/SOURCES'
mkdir: created directory `rpmbuild/SPECS'
mkdir: created directory `rpmbuild/SRPMS'
[Smoke@localhost ~]$ rpmbuild --showrc | grep _topdir(显示rpmbuild所有宏将结果送给管道只显示_topdir相关)
-14: _builddir	%{_topdir}/BUILD
-14: _rpmdir	%{_topdir}/RPMS
-14: _sourcedir	%{_topdir}/SOURCES
-14: _specdir	%{_topdir}/SPECS
-14: _srcrpmdir	%{_topdir}/SRPMS
-14: _topdir	/home/Smoke/rpmbuild(目录变为/home/Smoke/rpmbuild)
提示:工作车间规划好了;
[Smoke@localhost ~]$ rpm -qi httpd(查看httpd相关信息)
Name        : httpd                        Relocations: (not relocatable)
Version     : 2.2.3                             Vendor: Red Hat, Inc.
Release     : 63.el5                        Build Date: Thu 05 Jan 2012 11:08:25 PM CST
Install Date: Sat 22 Nov 2014 02:07:16 AM CST      Build Host: x86-004.build.bos.redhat.com
Group       : System Environment/Daemons    Source RPM: httpd-2.2.3-63.el5.src.rpm
Size        : 3316537                          License: Apache Software License
Signature   : DSA/SHA1, Tue 10 Jan 2012 05:43:06 PM CST, Key ID 5326810137017186
Packager    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
URL         : http://httpd.apache.org/
Summary     : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible
web server.
[Smoke@localhost ~]$ lftp 172.16.0.1(连接ftp服务器)
cd ok, cwd=/pub
lftp 172.16.0.1:/pub> cd Sources/rrdtool> get rrdtool-1.4.7-1.mage.i386.rpm rrdtool-perl-1.4.7-1.mage.i386.rpm(下载rrdtool和rrdtool-pe
rl软件)
925580 bytes transferred
Total 2 files transferred
lftp 172.16.0.1:/pub/Sources/rrdtool> bye(退出)
[Smoke@localhost ~]$ rpm -qpi rrdtool-1.4.7-1.el5.wrl.i386.rpm(查看rrdtool软件信息) 
Name        : rrdtool(软件包名字)                      Relocations: (not relocatable)(是否可以指定安装目录,notrelocatable表示不能)
Version     : 1.4.7(版本)                             Vendor: http://packages.express.org/(制作者)
Release     : 1.wrl(发行号)                         Build Date: Mon 11 Mar 2013 11:57:32 AM CST(制作日期)
Install Date: (not installed)               Build Host: rhel5-32.express.int(制作主机)
Group       : Applications/Databases        Source RPM: rrdtool-1.4.7-1.wrl.src.rpm
Size        : 2053108                          License: GPL
Signature   : (none)
Packager    : William R. Lorenz <wrl@express.org>(制作人)
URL         : http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/
Summary     : Round Robin Database Tool to store and display time-series data(软件包说明信息)
Description :
RRD is the Acronym for Round Robin Database. RRD is a system to store and
display time-series data (i.e. network bandwidth, machine-room temperature,
server load average). It stores the data in a very compact way that will not
expand over time, and it presents useful graphs by processing the data to
enforce a certain data density. It can be used either via simple wrapper
scripts (from shell or Perl) or via frontends that poll network devices and
put a friendly user interface on it.
[Smoke@localhost ~]$ ls /usr/share/doc/rpm-4.4.2.3/(查看/usr/share/doc/rpm-4.4.2.3目录文件及子目录)
builddependencies  CHANGES            COPYRIGHT-lua  format    LEGAL.NOTICE-file  Makefile     Makefile.in.autoreconf  relocatable
spec               buildroot          conditionalbuilds        CREDITS            GROUPS(说明了当前系统上支持组有那些,你所使用的组一定要是
这里面的组)         LICENSE-bdb        Makefile.am              multiplebuilds     rollbacks    triggers                ChangeLog
COPYING            dependencies       hregions                 macros             Makefile.in  queryformat             signatures
tsort
[Smoke@localhost ~]$ less /usr/share/doc/rpm-4.4.2.3/GROUPS(分页显示GROUPS文件内容) 
Amusements/Games
Amusements/Graphics
Applications/Archiving
Applications/Communications
Applications/Databases
Applications/Editors
Applications/Emulators
Applications/Engineering
Applications/File
Applications/Internet
Applications/Multimedia
Applications/Productivity
Applications/Publishing
Applications/System
Applications/Text
Development/Debuggers
Development/Languages
Development/Libraries
Development/System
Development/Tools
Documentation
System Environment/Base
System Environment/Daemons
System Environment/Kernel
System Environment/Libraries
System Environment/Shells
User Interface/Desktops
User Interface/X
User Interface/X Hardware Support
[Smoke@localhost ~]$ rpmbuild --showrc | grep _tmppath(查看rpmbuild所有宏将结果送给管道只显示_tmppath相关)
-14: __dbi_other	%{?_tmppath:tmpdir=%{_tmppath}} %{?__dbi_cdb}
-14: _tmppath	%{_var}/tmp
[root@localhost ~]# man install(查看install命令的man帮助)

       install [OPTION]... [-T] SOURCE DEST
       install [OPTION]... SOURCE... DIRECTORY(指定源文件,指定目录)
       install [OPTION]... -t DIRECTORY SOURCE...
       install [OPTION]... -d DIRECTORY...

       -d, --directory(创建目录)
              treat all arguments as directory names; create all components of the specified directories

       -D     create all leading components of DEST except the last, then copy SOURCE to DEST(如果安装的目录下对应的子目录缺乏的话,它会帮我
们自动创建这些路径)

[root@localhost ~]# install /etc/fstab /tmp(安装fstab到/tmp目录)
[root@localhost ~]# ls /tmp/(查看/tmp目录文件及子目录)
fstab  mapping-Smoke  scim-panel-socket:0-Smoke
[root@localhost ~]# install -d /tmp/test(创建test目录)
[root@localhost ~]# ll /tmp(查看/tmp目录文件及子目录)
total 16
-rwxr-xr-x 1 root  root  532 Sep 23 13:13 fstab
srwxrwxr-x 1 Smoke Smoke   0 Nov 22  2014 mapping-Smoke
srw------- 1 Smoke Smoke   0 Nov 22  2014 scim-panel-socket:0-Smoke
[root@localhost ~]# ls /tmp/(查看/tmp目录文件及子目录)
fstab  mapping-Smoke  scim-panel-socket:0-Smoke  test
[root@localhost ~]# install /etc/nagios/nagios.cfg /tmp/nagios(安装nagios.cfg到/tmp/nagios目录)
[root@localhost ~]# ls /tmp/(查看/tmp目录文件及子目录)
fstab  mapping-Smoke  nagios  scim-panel-socket:0-Smoke  test
[root@localhost ~]# rm /tmp/nagios(删除/tmp/nagios目录)
rm: remove regular file `/tmp/nagios'? y
[root@localhost ~]# install -D /etc/nagios/nagios.cfg /tmp/nagios/nagios.cfg(安装nagios.cfg到/tmp/nagios/nagios.cfg,-D除了最后文件前面路
径缺什么造什么)
[root@localhost ~]# ls /tmp/(查看/tmp目录文件及子目录)
fstab  mapping-Smoke  nagios  scim-panel-socket:0-Smoke  test
[root@localhost ~]# ls /tmp/nagios/(查看/tmp/nagios目录文件及子目录)
nagios.cfg
[Smoke@localhost ~]$ cd rpmbuild/SOURCES/(切换到rpmbuild/SOURCES目录)
[Smoke@localhost SOURCES]$ lftp 172.16.0.1(连接ftp服务器)
lftp 172.16.0.1:~> cd pub/Sources/nagios(切换到pub/Sources/nagios目录)
lftp 172.16.0.1:/pub/Sources/nagios> get nginx-1.0.14.tar.gz(下载nginx文件)
692465 bytes transferred
lftp 172.16.0.1:/pub/Sources/nagios> bye(退出)
[Smoke@localhost SOURCES]$ ls(查看当前目录文件及子目录)
nginx-1.0.14.tar.gz
[Smoke@localhost SOURCES]$ cd ..(切换到上级目录)
[Smoke@localhost rpmbuild]$ cd SPECS/(切换到SPECS目录)
[Smoke@localhost SPECS]$ ls(查看当前目录文件及子目录)
[Smoke@localhost SPECS]$ vim nginx.spec(编辑nginx.spec文件)

Name:           nginx
Version:        1.0.14(版本跟软件包版本匹配)
Release:        1%{?dist}
Summary:        A free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server.
Group:          System Environment/Daemons
Vendor: http://www.smoke.com(提供者)
Packager: smoke <349817712@qq.com>(制作者)
License:        BSD(授权)
URL:            http://www.nginx.org/
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root

BuildRequires:  pcre-devel,zlib-devel,openssl-devel(制作依赖软件包)
BuildRequires:  libxslt-devel,gd-devel(依赖那些包)
Requires:       pcre,openssl,gd(安装依赖那些包)
# for /usr/sbin/useradd
Requires(pre):  shadow-utils(在执行%pre脚本的时候依赖那些包)
Requires(post): chkconfig(执行%post脚本段依赖那些包)
# for /sbin/service
Requires(preun):        chkconfig, initscripts(卸载前的脚本依赖那些包)
Requires(postun):       initscripts(卸载后依赖那些包)
Provides:               webserver(提供那些能力)

Source:  http://sysoev.ru\/nginx/%{name}-%{version}.tar.gz(源文件在那个地方)

%description
Nginx is a free, open-source, high-performance HTTP server and reverse proxy,
as well as an IMAP/POP3 proxy server. Igor Sysoev started development of Nginx
in 2002, with the first public release in 2004. Nginx now hosts nearly 12.18%
(22.2M) of active sites across all domains. Nginx is known for its high
performance, stability, rich feature set, simple configuration, and low
resource consumption.

%prep(准备阶段)
%setup -q(-q静默模式)

%build(开始制作)
export DESTDIR=%{buildroot}
./configure \
  --sbin-path=/usr/sbin/nginx \
  --conf-path=/etc/nginx/nginx.conf \
  --error-log-path=/var/log/nginx/error.log \
  --http-log-path=/var/log/nginx/access.log \
  --pid-path=/var/run/nginx/nginx.pid \
  --lock-path=/var/lock/nginx.lock \
  --user=nginx \
  --group=nginx \
  --with-http_ssl_module \
  --with-http_flv_module \
  --with-http_stub_status_module \
  --with-http_gzip_static_module \
  --http-client-body-temp-path=/var/tmp/nginx/client/ \
  --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
  --with-pcre
make %{?_smp_mflags}

%install(安装)
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}

%{__install} -p -d -m 0775 %{buildroot}/var/run/nginx
%{__install} -p -d -m 0775 %{buildroot}/var/log/nginx

%clean
rm -rf %{buildroot}

%pre
if [ $1 == 1 ]; then(安装)
     /usr/sbin/useradd -s /bin/false -r nginx 2>/dev/null || :
fi

%post(安装后脚本)
if [ $1 == 1 ]; then
     /sbin/chkconfig --add %{name}
fi

%preun
if [ $1 = 0 ]; then(卸载)
     /sbin/service %{name} stop >/dev/null 2>&1
     /sbin/chkconfig --del %{name}
fi

%files
%defattr(-,root,root,-)
%doc LICENSE CHANGES README
%{_sbindir}/%{name}
%dir /var/run/nginx
%dir /var/log/nginx
%dir /etc/nginx
%config(noreplace} /etc/nginx/win-utf(凡是标明为config的都被理解为配置文件,noreplace不要替换,如果此前有不要替换)
%config(noreplace) /etc/nginx/win-utf
%config(noreplace) /etc/nginx/mime.types.default
%config(noreplace) /etc/nginx/fastcgi.conf
%config(noreplace) /etc/nginx/fastcgi.conf.default
%config(noreplace) /etc/nginx/fastcgi_params
%config(noreplace) /etc/nginx/fastcgi_params.default
%config(noreplace) /etc/nginx/%{name}.conf
%config(noreplace) /etc/nginx/mime.types
%config(noreplace) /etc/nginx/scgi_params
%config(noreplace) /etc/nginx/scgi_params.default
%config(noreplace) /etc/nginx/uwsgi_params
%config(noreplace) /etc/nginx/uwsgi_params.default
%config(noreplace) /etc/nginx/koi-win
%config(noreplace) /etc/nginx/koi-utf
%config(noreplace) /etc/nginx/%{name}.conf.default
/usr/local/nginx/html/50x.html
/usr/local/nginx/html/index.html
%attr(0775, root, root) %{_initrddir}/%{name}

%changelog
* Fri Sep 23 2016 smoke.com <349817712@qq.com> - 1.0.14-1
- Initial version(-横线表示注释)

# End Of nginx.spec

[Smoke@localhost SPECS]$ rpmbuild -bp nginx.spec(制作rpm包,-bp只执行到%pre段) 
error: Failed build dependencies:(缺少依赖包)
	pcre-devel is needed by nginx-1.0.14-1.i386
[root@localhost ~]# yum -y install pcre-devel(安装pcre-devel)
[Smoke@localhost SPECS]$ rpmbuild -bp nginx.spec(制作rpm包,-bp只执行到%pre段) 
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.72820
+ umask 022
+ cd /home/Smoke/rpmbuild/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /home/Smoke/rpmbuild/BUILD
+ rm -rf nginx-1.0.14
+ /usr/bin/gzip -dc /home/Smoke/rpmbuild/SOURCES/nginx-1.0.14.tar.gz
+ tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd nginx-1.0.14
++ /usr/bin/id -u
+ '[' 500 = 0 ']'
++ /usr/bin/id -u
+ '[' 500 = 0 ']'
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
[Smoke@localhost SPECS]$ ls ~/rpmbuild/BUILD/(查看~/rpmbuild/BUILD目录文件及子目录)
nginx-1.0.14
[Smoke@localhost SPECS]$ ls -l ~/rpmbuild/BUILD/(查看~/rpmbuild/BUILD目录文件及子目录详细信息)
total 8
drwxr-xr-x 8 Smoke Smoke 4096 Mar 15  2012 nginx-1.0.14
[Smoke@localhost SPECS]$ ls -l ~/rpmbuild/BUILD/nginx-1.0.14/(查看~/rpmbuild/BUILD/nginx-1.0.14目录文件及子目录详细信息)
total 580
drwxr-xr-x 6 Smoke Smoke   4096 Sep 23 15:01 auto
-rw-r--r-- 1 Smoke Smoke 198200 Mar 15  2012 CHANGES
-rw-r--r-- 1 Smoke Smoke 302134 Mar 15  2012 CHANGES\.ru
drwxr-xr-x 2 Smoke Smoke   4096 Sep 23 15:01 conf
-rwxr-xr-x 1 Smoke Smoke   2345 Feb  6  2012 configure
drwxr-xr-x 3 Smoke Smoke   4096 Sep 23 15:01 contrib
drwxr-xr-x 2 Smoke Smoke   4096 Sep 23 15:01 html
-rw-r--r-- 1 Smoke Smoke   1365 Feb  6  2012 LICENSE
drwxr-xr-x 2 Smoke Smoke   4096 Sep 23 15:01 man
-rw-r--r-- 1 Smoke Smoke     49 Nov  1  2011 README
drwxr-xr-x 8 Smoke Smoke   4096 Sep 23 15:01 src
[Smoke@localhost SPECS]$ rpmbuild -bc nginx.spec(制作rpm包,-bc只执行到%build段) 
[Smoke@localhost SPECS]$ rpmbuild -bi nginx.spec(制作rpm包,-bi执行到%install段) 
[Smoke@localhost SPECS]$ vim nginx.spec(编辑nginx.spec文件) 

Name:           nginx
Version:        1.0.14
Release:        1%{?dist}
Summary:        A free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server.
Group:          System Environment/Daemons
Vendor: http://www.smoke.com
Packager: smoke <349817712@qq.com>
License:        BSD
URL:            http://www.nginx.org/
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root

BuildRequires:  pcre-devel,zlib-devel,openssl-devel
BuildRequires:  libxslt-devel,gd-devel
Requires:       pcre,openssl,gd
# for /usr/sbin/useradd
Requires(pre):  shadow-utils
Requires(post): chkconfig
# for /sbin/service
Requires(preun):        chkconfig, initscripts
Requires(postun):       initscripts
Provides:               webserver

Source:  http://sysoev.ru\/nginx/%{name}-%{version}.tar.gz

%description
Nginx is a free, open-source, high-performance HTTP server and reverse proxy,
as well as an IMAP/POP3 proxy server. Igor Sysoev started development of Nginx
in 2002, with the first public release in 2004. Nginx now hosts nearly 12.18%
(22.2M) of active sites across all domains. Nginx is known for its high
performance, stability, rich feature set, simple configuration, and low
resource consumption.

%prep
%setup -q

%build
export DESTDIR=%{buildroot}
./configure \
  --sbin-path=/usr/sbin/nginx \
  --conf-path=/etc/nginx/nginx.conf \
  --error-log-path=/var/log/nginx/error.log \
  --http-log-path=/var/log/nginx/access.log \
  --pid-path=/var/run/nginx/nginx.pid \
  --lock-path=/var/lock/nginx.lock \
  --user=nginx \
  --group=nginx \
  --with-http_ssl_module \
  --with-http_flv_module \
  --with-http_stub_status_module \
  --with-http_gzip_static_module \
  --http-client-body-temp-path=/var/tmp/nginx/client/ \
  --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
  --with-pcre
make %{?_smp_mflags}

%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}
%{__install} -p -d -m 0775 %{buildroot}/var/run/nginx
%{__install} -p -d -m 0775 %{buildroot}/var/log/nginx

%clean
rm -rf %{buildroot}

%pre
if [ $1 == 1 ]; then
     /usr/sbin/useradd -s /bin/false -r nginx 2>/dev/null || :
fi

%post
if [ $1 == 1 ]; then
     /sbin/chkconfig --add %{name}
fi

%preun
if [ $1 = 0 ]; then
     /sbin/service %{name} stop >/dev/null 2>&1
     /sbin/chkconfig --del %{name}
fi

%files
%defattr(-,root,root,-)
%doc LICENSE CHANGES README
%{_sbindir}/%{name}
%dir /var/run/nginx
%dir /var/log/nginx
%dir /etc/nginx
%config(noreplace) /etc/nginx/win-utf
%config(noreplace) /etc/nginx/mime.types.default
%config(noreplace) /etc/nginx/fastcgi.conf
%config(noreplace) /etc/nginx/fastcgi.conf.default
%config(noreplace) /etc/nginx/fastcgi_params
%config(noreplace) /etc/nginx/fastcgi_params.default
%config(noreplace) /etc/nginx/%{name}.conf
%config(noreplace) /etc/nginx/mime.types
%config(noreplace) /etc/nginx/scgi_params
%config(noreplace) /etc/nginx/scgi_params.default
%config(noreplace) /etc/nginx/uwsgi_params
%config(noreplace) /etc/nginx/uwsgi_params.default
%config(noreplace) /etc/nginx/koi-win
%config(noreplace) /etc/nginx/koi-utf
%config(noreplace) /etc/nginx/%{name}.conf.default
/usr/local/nginx/html/50x.html
/usr/local/nginx/html/index.html
#%attr(0775, root, root) %{_initrddir}/%{name}

%changelog
* Fri Sep 23 2016 smoke.com <349817712@qq.com> - 1.0.14-1
- Initial version

# End Of nginx.spec

[Smoke@localhost SPECS]$ ls /var/tmp/nginx-1.0.14-1-root/(查看/var/tmp/nginx-1.0.14-root目录文件及子目录)
etc  usr  var
[Smoke@localhost SPECS]$ ls /var/tmp/nginx-1.0.14-1-root/etc/(查看/var/tmp/nginx-1.0.14-1-root/etc目录文件及子目录)
nginx
[Smoke@localhost SPECS]$ ls /var/tmp/nginx-1.0.14-1-root/etc/nginx/(查看/var/tmp/nginx-1.0.14-1-root/etc/nginx目录文件及子目录)
fastcgi.conf          fastcgi_params.default  mime.types          nginx.conf.default   uwsgi_params
fastcgi.conf.default  koi-utf                 mime.types.default  scgi_params          uwsgi_params.default
fastcgi_params        koi-win                 nginx.conf          scgi_params.default  win-utf
[Smoke@localhost SPECS]$ ls /var/tmp/nginx-1.0.14-1-root/usr/(查看/var/tmp/nginx-1.0.14-1-root/usr/root/user目录文件及子目录)      
lib  local  sbin  share  src
[Smoke@localhost SPECS]$ ls /var/tmp/nginx-1.0.14-1-root/usr/sbin/(查看/var/tmp/nginx-1.0.14-1-root/usr/sbin目录文件及子目录)
nginx
[Smoke@localhost SPECS]$ ls /var/tmp/nginx-1.0.14-1-root/usr/src/(查看/var/tmp/nginx-1.0.14-root/usr/src目录文件及子目录)
debug
[Smoke@localhost SPECS]$ ls /var/tmp/nginx-1.0.14-1-root/usr/share/(查看/var/tmp/nginx-1.0.14-root/usr/share目录文件及子目录)    
doc
[Smoke@localhost SPECS]$ rpmbuild -ba nginx.spec(制作二进制和源码rpm包) 
[Smoke@localhost SPECS]$ cd ../RPMS/(切换到../RPMS目录)
[Smoke@localhost RPMS]$ ls(查看当前目录文件及子目录)
i386
[Smoke@localhost RPMS]$ cd i386/(切换到i386目录)
[Smoke@localhost i386]$ ls(查看当前目录文件及子目录)
nginx-1.0.14-1.i386.rpm  nginx-debuginfo-1.0.14-1.i386.rpm(调试rpm用的包)
[Smoke@localhost i386]$ netstat -tnlp(查看系统服务,-t代表tcp,-n以数字显示,-l监听端口,-p显示服务名称)
(No info could be read for "-p": geteuid()=500 but you should be root.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN      -                   
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      -                   
tcp        0      0 0.0.0.0:852                 0.0.0.0:*                   LISTEN      -                   
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      -                   
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      -                   
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      -                   
tcp        0      0 127.0.0.1:6010              0.0.0.0:*                   LISTEN      -                   
tcp        0      0 127.0.0.1:6011              0.0.0.0:*                   LISTEN      -                   
tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN      -                   
tcp        0      0 :::80                       :::*                        LISTEN      -                   
tcp        0      0 :::22                       :::*                        LISTEN      -                   
tcp        0      0 ::1:6010                    :::*                        LISTEN      -                   
tcp        0      0 ::1:6011                    :::*                        LISTEN      -   
[root@localhost ~]# rpm -ivh /home/Smoke/rpmbuild/RPMS/i386/nginx-1.0.14-1.i386.rpm(安装nginx-1.0.14软件包) 
Preparing...                ########################################### [100%]
   1:nginx                  ########################################### [100%]
error reading information on service nginx: No such file or directory(找不到服务文件)
error: %post(nginx-1.0.14-1.i386) scriptlet failed, exit status 1
[root@localhost ~]# rpm -qi nginx(查看nginx软件信息)
Name        : nginx                        Relocations: (not relocatable)
Version     : 1.0.14                            Vendor: http://www.smoke.com
Release     : 1                             Build Date: Fri 23 Sep 2016 04:04:38 PM CST
Install Date: Fri 23 Sep 2016 04:20:46 PM CST      Build Host: localhost.localdomain
Group       : System Environment/Daemons    Source RPM: nginx-1.0.14-1.src.rpm
Size        : 703706                           License: BSD
Signature   : (none)
Packager    : smoke <349817712@qq.com>
URL         : http://www.nginx.org/
Summary     : A free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server.
Description :
Nginx is a free, open-source, high-performance HTTP server and reverse proxy,
as well as an IMAP/POP3 proxy server. Igor Sysoev started development of Nginx
in 2002, with the first public release in 2004. Nginx now hosts nearly 12.18%
(22.2M) of active sites across all domains. Nginx is known for its high
performance, stability, rich feature set, simple configuration, and low
resource consumption.
[root@localhost ~]# rpm -e nginx(卸载nginx)
error reading information on service nginx: No such file or directory
error: %preun(nginx-1.0.14-1.i386) scriptlet failed, exit status 1
[root@localhost ~]# rpm -e -f nginx(强制卸载nginx)
error reading information on service nginx: No such file or directory
error: %preun(nginx-1.0.14-1.i386) scriptlet failed, exit status 1
[root@localhost ~]# rpm -q nginx(查看是否安装nginx)
nginx-1.0.14-1
[Smoke@localhost ~]$ cd rpmbuild/SOURCES/(切换到rpmbuild/SOURCES目录)
[Smoke@localhost SOURCES]$ ls(查看当前目录文件及子目录)
nginx-1.0.14.tar.gz
[Smoke@localhost SOURCES]$ vim nginx.sysinit(编辑nginx.sysinit文件)

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15 
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid
 
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
 
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
 
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
 
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
 
lockfile=/var/lock/subsys/nginx
 
make_dirs() {
   # make required directories
   user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
   options=`$nginx -V 2>&1 | grep 'configure arguments:'`
   for opt in $options; do
       if [ `echo $opt | grep '.*-temp-path'` ]; then
           value=`echo $opt | cut -d "=" -f 2`
           if [ ! -d "$value" ]; then
               # echo "creating" $value
               mkdir -p $value && chown -R $user $value
           fi
       fi
   done
}
 
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
 
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    configtest || return $?
    stop
    sleep 1
    start
}
 
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}
 
force_reload() {
    restart
}
 
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
 
rh_status() {
    status $prog
}
 
rh_status_q() {
    rh_status >/dev/null 2>&1
}
 
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac
#END Of nginx.init
[Smoke@localhost SOURCES]$ ll(查看当前目录文件及子目录详细信息)
total 696
-rw-r--r-- 1 root  root  692465 Sep 23 13:54 nginx-1.0.14.tar.gz
-rw-rw-r-- 1 Smoke Smoke   2537 Sep 23 16:37 nginx.sysinit
[Smoke@localhost SOURCES]$ cd ../SPECS/(切换到SPECS目录)
[Smoke@localhost SPECS]$ ls(查看当前目录文件及子目录)
nginx.spec
[Smoke@localhost SPECS]$ vim nginx.spec(编辑nginx.spec文件) 

Name:           nginx
Version:        1.0.14
Release:        2%{?dist}
Summary:        A free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server.
Group:          System Environment/Daemons
Vendor: http://www.smoke.com
Packager: smoke <349817712@qq.com>
License:        BSD
URL:            http://www.nginx.org/
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root

BuildRequires:  pcre-devel,zlib-devel,openssl-devel
BuildRequires:  libxslt-devel,gd-devel
Requires:       pcre,openssl,gd
# for /usr/sbin/useradd
Requires(pre):  shadow-utils
Requires(post): chkconfig
# for /sbin/service
Requires(preun):        chkconfig, initscripts
Requires(postun):       initscripts
Provides:               webserver

Source0:  http://sysoev.ru\/nginx/%{name}-%{version}.tar.gz
Source1:  nginx.sysinit

%description
Nginx is a free, open-source, high-performance HTTP server and reverse proxy,
as well as an IMAP/POP3 proxy server. Igor Sysoev started development of Nginx
in 2002, with the first public release in 2004. Nginx now hosts nearly 12.18%
(22.2M) of active sites across all domains. Nginx is known for its high
performance, stability, rich feature set, simple configuration, and low
resource consumption.

%prep
%setup -q

%build
export DESTDIR=%{buildroot}
./configure \
  --sbin-path=/usr/sbin/nginx \
  --conf-path=/etc/nginx/nginx.conf \
  --error-log-path=/var/log/nginx/error.log \
  --http-log-path=/var/log/nginx/access.log \
  --pid-path=/var/run/nginx/nginx.pid \
  --lock-path=/var/lock/nginx.lock \
  --user=nginx \
  --group=nginx \
  --with-http_ssl_module \
  --with-http_flv_module \
  --with-http_stub_status_module \
  --with-http_gzip_static_module \
  --http-client-body-temp-path=/var/tmp/nginx/client/ \
  --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
  --with-pcre
make %{?_smp_mflags}

%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}
%{__install} -p -d -m 0775 %{buildroot}/var/run/nginx
%{__install} -p -d -m 0775 %{buildroot}/var/log/nginx
%{__install} -p -D -m 0755 %{SOURCE1} %{buildroot}/etc/rc.d/init.d/nginx

%clean
rm -rf %{buildroot}

%pre
if [ $1 == 1 ]; then
     /usr/sbin/useradd -s /bin/false -r nginx 2>/dev/null || :
fi

%post
if [ $1 == 1 ]; then
     /sbin/chkconfig --add %{name}
fi

%preun
if [ $1 = 0 ]; then
     /sbin/service %{name} stop >/dev/null 2>&1
     /sbin/chkconfig --del %{name}
fi

%files
%defattr(-,root,root,-)
%doc LICENSE CHANGES README
%{_sbindir}/%{name}
%dir /var/run/nginx
%dir /var/log/nginx
%dir /etc/nginx
%config(noreplace) /etc/nginx/win-utf
%config(noreplace) /etc/nginx/mime.types.default
%config(noreplace) /etc/nginx/fastcgi.conf
%config(noreplace) /etc/nginx/fastcgi.conf.default
%config(noreplace) /etc/nginx/fastcgi_params
%config(noreplace) /etc/nginx/fastcgi_params.default
%config(noreplace) /etc/nginx/%{name}.conf
%config(noreplace) /etc/nginx/mime.types
%config(noreplace) /etc/nginx/scgi_params
%config(noreplace) /etc/nginx/scgi_params.default
%config(noreplace) /etc/nginx/uwsgi_params
%config(noreplace) /etc/nginx/uwsgi_params.default
%config(noreplace) /etc/nginx/koi-win
%config(noreplace) /etc/nginx/koi-utf
%config(noreplace) /etc/nginx/%{name}.conf.default
/usr/local/nginx/html/50x.html
/usr/local/nginx/html/index.html
%attr(0775, root, root) /etc/rc.d/init.d/nginx

%changelog
* Fri Sep 23 2016 smoke.com <349817712@qq.com> - 1.0.14-2
-- Add sysv script /etc/rc.d/init.d/nginx

* Fri Sep 23 2016 smoke.com <349817712@qq.com> - 1.0.14-1
- Initial version

# End Of nginx.spec

[Smoke@localhost SPECS]$ rpmbuild -ba nginx.spec(制作rpm包)
[root@localhost ~]# rpm -Uvh /home/Smoke/rpmbuild/RPMS/i386/nginx-1.0.14-2.i386.rpm(升级nginx,U更新,-v显示过程,-h显示进度条)
Preparing...                ########################################### [100%]
   1:nginx                  ########################################### [100%]
[root@localhost ~]# service nginx start(启动nginx服务)
Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
                                                           [FAILED]
[root@localhost ~]# service httpd stop(停止httpd服务)
Stopping httpd:                                            [  OK  ]
[root@localhost ~]# service nginx start(启动nginx服务)
Starting nginx:                                            [  OK  ]
[Smoke@localhost SPECS]$ vim ../SOURCES/nginx.params(编辑nginx.params文件)

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

[Smoke@localhost SPECS]$ vim nginx.spec(编辑nginx.spec)

Name:           nginx
Version:        1.0.14
Release:        3%{?dist}
Summary:        A free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server.
Group:          System Environment/Daemons
Vendor: http://www.smoke.com
Packager: smoke <349817712@qq.com>
License:        BSD
URL:            http://www.nginx.org/
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root

BuildRequires:  pcre-devel,zlib-devel,openssl-devel
BuildRequires:  libxslt-devel,gd-devel
Requires:       pcre,openssl,gd
# for /usr/sbin/useradd
Requires(pre):  shadow-utils
Requires(post): chkconfig
# for /sbin/service
Requires(preun):        chkconfig, initscripts
Requires(postun):       initscripts
Provides:               webserver

Source0:  http://sysoev.ru\/nginx/%{name}-%{version}.tar.gz
Source1:  nginx.sysinit
Source2:  nginx.params

%description
Nginx is a free, open-source, high-performance HTTP server and reverse proxy,
as well as an IMAP/POP3 proxy server. Igor Sysoev started development of Nginx
in 2002, with the first public release in 2004. Nginx now hosts nearly 12.18%
(22.2M) of active sites across all domains. Nginx is known for its high
performance, stability, rich feature set, simple configuration, and low
resource consumption.

%prep
%setup -q

%build
export DESTDIR=%{buildroot}
./configure \
  --sbin-path=/usr/sbin/nginx \
  --conf-path=/etc/nginx/nginx.conf \
  --error-log-path=/var/log/nginx/error.log \
  --http-log-path=/var/log/nginx/access.log \
  --pid-path=/var/run/nginx/nginx.pid \
  --lock-path=/var/lock/nginx.lock \
  --user=nginx \
  --group=nginx \
  --with-http_ssl_module \
  --with-http_flv_module \
  --with-http_stub_status_module \
  --with-http_gzip_static_module \
  --http-client-body-temp-path=/var/tmp/nginx/client/ \
  --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
  --with-pcre
make %{?_smp_mflags}

%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}
%{__install} -p -d -m 0775 %{buildroot}/var/run/nginx
%{__install} -p -d -m 0775 %{buildroot}/var/log/nginx
%{__install} -p -D -m 0755 %{SOURCE1} %{buildroot}/etc/rc.d/init.d/nginx
mv %{buildroot}/etc/nginx/fastcgi_params %{buildroot}/etc/nginx/fastcgi_params.orig
%{__install} -p -D -m 0644 %{SOURCE2} %{buildroot}/etc/nginx/fastcgi_params

%clean
rm -rf %{buildroot}

%pre
if [ $1 == 1 ]; then
     /usr/sbin/useradd -s /bin/false -r nginx 2>/dev/null || :
fi

%post
if [ $1 == 1 ]; then
     /sbin/chkconfig --add %{name}

%preun
if [ $1 = 0 ]; then
     /sbin/service %{name} stop >/dev/null 2>&1
     /sbin/chkconfig --del %{name}
fi

%files
%defattr(-,root,root,-)
%doc LICENSE CHANGES README
%{_sbindir}/%{name}
%dir /var/run/nginx
%dir /var/log/nginx
%dir /etc/nginx
%config(noreplace) /etc/nginx/win-utf
%config(noreplace) /etc/nginx/mime.types.default
%config(noreplace) /etc/nginx/fastcgi.conf
%config(noreplace) /etc/nginx/fastcgi.conf.default
%config(noreplace) /etc/nginx/fastcgi_params
%config(noreplace) /etc/nginx/fastcgi_params.orig
%config(noreplace) /etc/nginx/fastcgi_params.default
%config(noreplace) /etc/nginx/%{name}.conf
%config(noreplace) /etc/nginx/mime.types
%config(noreplace) /etc/nginx/scgi_params
%config(noreplace) /etc/nginx/scgi_params.default
%config(noreplace) /etc/nginx/uwsgi_params
%config(noreplace) /etc/nginx/uwsgi_params.default
%config(noreplace) /etc/nginx/koi-win
%config(noreplace) /etc/nginx/koi-utf
%config(noreplace) /etc/nginx/%{name}.conf.default
/usr/local/nginx/html/50x.html
/usr/local/nginx/html/index.html
%attr(0775, root, root) /etc/rc.d/init.d/nginx

%changelog
* Fri Sep 23 2016 smoke.com <349817712@qq.com> - 1.0.14-3
-- Add fastcgi_params for php-fpm

* Fri Sep 23 2016 smoke.com <349817712@qq.com> - 1.0.14-2
-- Add sysv script /etc/rc.d/init.d/nginx

* Fri Sep 23 2016 smoke.com <349817712@qq.com> - 1.0.14-1
- Initial version

# End Of nginx.spec

[Smoke@localhost SPECS]$ rpmbuild -ba nginx.spec(制作rpm包)
[root@localhost ~]#  rpm -Uvh /home/Smoke/rpmbuild/RPMS/i386/nginx-1.0.14-3.i386.rpm(升级nginx)
Preparing...                ########################################### [100%]
   1:nginx                  ########################################### [100%]
[root@localhost ~]# cd /etc/nginx/(切换到/etc/nginx目录)
[root@localhost nginx]# ls(查看当前目录文件及子目录)
fastcgi.conf          fastcgi_params.default  koi-win             nginx.conf          scgi_params.default   win-utf
fastcgi.conf.default  fastcgi_params.orig     mime.types          nginx.conf.default  uwsgi_params
fastcgi_params        koi-utf                 mime.types.default  scgi_params         uwsgi_params.default
[root@localhost nginx]# less fastcgi_params(分页显示fastcgi_params文件) 

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

The spec file

rpmfind.net 查找rpm软件包

rpmpone.com 查找rpm软件包

Spec files overview(spec文件概况)

Defining Package Information(怎么定义软件包信息)

Controlling the Build(如何控制编译过程)

Filling the List of Files(怎么填充files列表)

Adding Change Log Entries(添加change log entries)

 

The spec file

Spec files are text files containing RPM directives

  These directives use a simple syntax of a tag name,a colon, and a value;

    TagName: value (Name: nginx)(在spec文件大多数内容,尤其是信息相关内容都是标签的方式定义的,标签的名字不区分大小写的)

  The name of the item is not case sensitive

  Additionally, can define macros using the RPM %define syntax(可以自定义一些宏,将宏当作变量的方式使用)

    %define macro_name value(%define表示要定义宏了,syntax宏的名字,宏的名字最好不要跟标签的名字重名了,也不要跟其它关键字重名后面空格跟值)

    Using the %{macro_name} or just %macro_name syntaxes to access macros(引用这些宏的时候使用%{宏名}或者把%百分号省略也可以)

  Note: Major sections in the spec file are also delimited with % markers

Comments

  # This is a comment(所有#井号开头的都是注释信息)

  Avoid single percent signs, %, in comments, instead,using two percent signs,such as %%prep(在注释当中用到宏要使用%%prep,多加一个%百分号)

 

Defining Package Information

Descriibing the package

  The first part of the spec file deines macros

  Naming the Package(定义软件包信息必须参数)

    Name(名字不用横线)

      nome-version-release.rpm

      nome-version-releose.orch.rpm

    Version(版本号不能使用横线)

      connot use a dosh in the version number

    Release(修订号)

    Group

    /usr/share/doc/rpm-version/GROUPS

Describing the package

  Specifying Company Information(公司相关的信息)

    Vendor(提供rpm包的公司)

      the company or organization behind on RPM

  URL(制作者公司那个网站上可以找到rpm包下载的位置)

    A URL to your company or orgonization home page,or perhaps to a URL for a particular application

    URL:http://www.magedu.com/downloads/RPMS

  Packager(制作者)

    An optional name and e-mail address for person who created the RPM

    Packager:Marion <linuxedu@formail.com>

  License(版权)

    Provides legal information about the package

    License:GPLv2

 

Describing the package(软件包描述信息)

Filling in the Description

  Summary(简要描述,不能超过50字符)

    Provides a one-line short description of the package

    Should not exceed much more than 50 characters

  The %description section allows for longer text describing your package

Describing the Package

  Defining Package Dependencies

    Requires:capability(安装时所依赖的rpm包)

      Can put more than one capability,separated by space or comma,on the dependency line

        Requires:bash.chkconfig(依赖的软件包)

      Can also add version information

        Requires: bash >= 2.0(要求软件包的版本)

      RPM users a special syntax with parenthesis to indicate script module dependencies

        Requires: perl(Caro) >= 3.2(某个模块依赖)

    Povides: capability(定义自己提供的能力,如果不提供就是自己的名字)

      Creating Virtual CAPABILITIES

    BuildRequires: capability(编译时候所依赖的能力,可以出现多次)

      Specify what is necessary to build the package

 

Setting build locations(设定build目录)

  RPM supports two build-related directories with very similar name,the build directory and the buildroot.

    The build directory is the location where RPM actually builds the software,compiling source code,running the configure script,and so on

  The buildroot,on the other hand,acts as a staging area that looks like the final installation directory

    The name buildroot refers to the fact that the final installation directory is usually the root directory,/

BuildRoot

  Buildroot:%{_tmppath}/%{name}-%{version}-root

  Can access the buildroot using the RPM_BUILD_ROOT environment variable

  $RPM_BUILD_ROOT,%{buildroot}(引用表示意义相同)

Naming source file(命令源文件)

  Most packages have one or more bundles of source code,which you need to name in the spec file

  Can define one or more source tags,counting from 0

    Source0:nginx-1.0.12.tar.gz

    Source1:nginx.conf

    Source2:nginx.init

  If you just have one Source directive,you can skip the 0

  You can also use FTP or HTTP URLs to name sources

 

Naming patches(命令软件包)

  Patch are named similar to sources,using a similar syntax

    Patch1:httpd-2.2.22-pcre830.patch(补丁文件)

    Patch3:httpd-2.2.21-mod_proxy-change-state.patch

  Can set Patch directives are not numberred sequentially

Controlling the Build(控制编译安装过程)

In RPM terms,building the package is split into four steps:

  1.Preparing for building,including unpacking the sources

  2.Building

  3.Installing the application or library

  4.Cleaning up

 

Preparing for the build: %prep

  The %prep section deines the commands to prepare for the build(%prep把源码包解压到build目录下,设置一下环境变量并且cd进去)

  In most cases, you can run the simple %setup macro, For example:

    %prep

    %setup -q

  The %patch directive applies a patch to the sources(使用%patch打补丁)

    Nedd a %patch directive for each patch

 

Command-line parameters for %setup(%setup选项)

-q: 表示静默模式,以最少的输出信息的;

-a number: after 展开多少个源文件,

-b number: before 一般说来要使用-b要先使用-c,-b表示不跳进去直接展开,而且仅展开不会创建目录;

-T: 表示不展开,直接复制进去;

Building the software: %build

  You need to fill in the %build section with all the commands necessary to build the software

  For example

    %build

    ./configure --prefix=/usr \

      --sysconfdir=/etc/nginx

    make %{?_smp_mflags}

  %build

  perl Mailfile.PL

  make

 

Installing the software: %install

  For example

  %install

  rm -rf %{buildroot}

  make install DESTDIR=%{buildroot}

  %{__install} -p -D -m 0644 %{SOURCE5} \

    %{buildroot}%{_sysconfdir}/sysconfig/%{name}

  %{__install} -p -d -m 0775 %{buildroot}/var/log/nginx

 

Cleaning up after the build: %clean(%clean作用删除buildroot)

  For example

  %clean

  rm -rf %{buildroot}

Defining installation scripts

  %pre

    A script run prior to installation

  %post

    A script run after installation

  %preun

    A script run before the uninstall

  %postun

    A script run after the uninstall

 

Fox example

$1 holds a count of the number of versions of the package that are installed($1安装类型)

Filling the List of Files(列出的文件)

The %files section holds a list of all the files that RPM should install from the package

  This list should be exhaustive,so that the RPM system knows exactly whtat your package install

  There are some options,though,to name all the files within a directory to help with packages containing hundreds of iles

In the default case, each line under the %files section names a separate file with its full path

  %files

  %/usr/sbin/nginx

  /etc/nginx/nginx.conf

Using glob-style wildcards

  %files

  /usr/sbin/nginx

  /etc/nginx/nginx.*

Can specify whole directories as part of your package

  %files

  /usr/sbin/nginx

  /etc/nginx(%dir把目录当作空目录,目录中的内容不予关心的)

 

%doc

  Marks a file as a documentation file(文件当作文档)

%docdir

  Names a directory that holds documentation(把整个目录所有文件都当作文档)

%config(noreplace,missingok)

  Marks a file as configuration(把文件当作配置文件,原来的文件如果没有改变有可能会替换掉)

  A special option to the %config directive,noreplace,tells RPM not to overwrite,or replace a configuration file(noreplace不做替换,仅仅不替换已改变的文件)

  missingok

setting file attributes

%attr(文件包含rpm包以后获取安装到系统以后具有什么样的权限属性的格式)

  %attr(mode,user,group) filename(每一个文件都可以单独指定权限,使用%attr,后面是文件路径,mode权限,user属主,group属组)

  If you don't need to specify a value,use a dash,-,to leave the setting as is for the file

    %attr(-,root,-)/etc/nginx/nginx.conf(如果使用默认的使用-横线就可以)

  Can combine directives,one after another.

    %config %attr(-,root,-)/etc/nginx/nginx.conf(即是配置文件还定义了权限)

Using the %defattr directive to set the default attributes for all files in the package(%defattr定义默认权限)

Adding Change Log Entries

The change log usually appears at the end of a spec file and is marked with %changelog(时间、制作者、版本号)

PGP

Pretty Good Privacy (PGP) is a data encryption and decryption computer program that provides cryptographic privacy and authentication for data communication.

PGP is often used for signing,encrypting and decrypting texts,E-mails,directories and whole disk partitions to increase the security of e-mail communications.

It was created by Phil Zimmermann is 1991.

PGP and similar products follow the OpenPGP standard(RFC 4880) for encrypting and decrypting data.

很好的隐私(PGP)是一种数据加密和解密的计算机程序,它提供了数据通信加密的隐私和身份验证。

PGP通常用于签名,加密和解密文本,电子邮件,目录和整个磁盘分区增加电子邮件通信的安全。

它是由菲尔·齐默尔曼是1991。

PGP和类似产品遵循OpenPGP标准(RFC 4880)加密和解密数据。

$ gpg --gen-key(生成密钥)

$ gpg --list-keys(查看密钥)

$ gpg --export -a 'Mage Edu' > RPM-GPG-KEY-magedu(把密钥中的公钥提取出来)

$ rpm --addsign nginx-1.0.14-1.i386.rpm(给rpm包添加签名)

# rpm --import RPM-GPG-KEY-magedu

$ rpm --checksig nginx-1.0.14-1.i386.rpm

~/.rpmmacros(在制作rpm时候直接签名)

  %_signature gpg

  %_gpg_name Mage Edu

[root@localhost nginx]# cp /home/Smoke/rpmbuild/SRPMS/nginx-1.0.14-3.src.rpm ./(复制nginx-1.0.14-3.src.rpm到当前目录)
[root@localhost nginx]# mv nginx-1.0.14-3.src.rpm /tmp/(移动nginx文件到/tmp目录)
[root@localhost nginx]# cd /tmp/(切换到/tmp目录)
[root@localhost tmp]# ls(查看当前目录文件及子目录)
fstab  mapping-Smoke  nagios  nginx-1.0.14-3.src.rpm  scim-panel-socket:0-Smoke  test
[root@localhost tmp]# rpm2cpio nginx-1.0.14-3.src.rpm(将nginx文件转换为cpio文件)
[root@localhost tmp]# rpm2cpio nginx-1.0.14-3.src.rpm > nginx-1.0.14-3.cpio(将nginx文件转换为cpio文件保存到nginx-1.0.14-3.cpio)
[root@localhost tmp]# ll(查看当前目录文件及子目录详细信息)
total 1416
-rwxr-xr-x 1 root  root     532 Sep 23 13:13 fstab
srwxrwxr-x 1 Smoke Smoke      0 Nov 22  2014 mapping-Smoke
drwxr-xr-x 2 root  root    4096 Sep 23 13:20 nagios
-rw-r--r-- 1 root  root  700316 Sep 23 17:20 nginx-1.0.14-3.cpio
-rw-r--r-- 1 root  root  698304 Sep 23 17:12 nginx-1.0.14-3.src.rpm
srw------- 1 Smoke Smoke      0 Nov 22  2014 scim-panel-socket:0-Smoke
drwxr-xr-x 2 root  root    4096 Sep 23 13:15 test
[root@localhost tmp]# rpm2cpio nginx-1.0.14-3.src.rpm | cpio -t(将nginx文件转换为cpio文件将结果送给cpio命令查看文件内容)            
nginx-1.0.14.tar.gz
nginx.params
nginx.spec
nginx.sysinit
1368 blocks
[root@localhost tmp]# rpm -ivh nginx-1.0.14-3.src.rpm(安装nginx-1.0.14-3.src.rpm软件) 
   1:nginx                  ########################################### [100%]
[root@localhost tmp]# rpm -q nginx(查看是否安装nginx文件)          
nginx-1.0.14-3
[root@localhost tmp]# cd /usr/src/redhat/(切换到/usr/src/redhat目录)
[root@localhost redhat]# tree .(显示当前目录树)
.
|-- BUILD
|-- RPMS
|   |-- athlon
|   |-- geode
|   |-- i386
|   |-- i486
|   |-- i586
|   |-- i686
|   `-- noarch
|-- SOURCES
|   |-- nginx-1.0.14.tar.gz
|   |-- nginx.params
|   `-- nginx.sysinit
|-- SPECS
|   `-- nginx.spec
`-- SRPMS

12 directories, 4 files
提示:当安装src格式的rpm包的时候,给你安装到当前用户所指的制作工厂车间里面;
[root@localhost redhat]# cd -(切换到上次所处目录)
/tmp
[root@localhost tmp]# ls(查看当前目录文件及子目录)
fstab  mapping-Smoke  nagios  nginx-1.0.14-3.cpio  nginx-1.0.14-3.src.rpm  scim-panel-socket:0-Smoke  test
[root@localhost tmp]# man rpmbuild(查看rpmbuild的man手册)   

       rpmbuild {--rebuild|--recompile} SOURCEPKG ...

       rpmbuild --rebuild|--recompile SOURCEPKG ...(不用展开直接编译成rpm包)

       When  invoked  this  way, rpmbuild installs the named source package, and does a prep, compile and install.  In addi-
       tion, --rebuild builds a new binary package. When the build has completed, the build  directory  is  removed  (as  in
       --clean) and the the sources and spec file for the package are removed.

[root@localhost tmp]# rpmbuild --rebuild nginx-1.0.14-3.src.rpm(不展开直接制作rpm包)
[root@localhost tmp]# cd /usr/src/redhat/(切换到/usr/src/redhat目录)
[root@localhost redhat]# ls(查看当前目录文件及子目录)
BUILD  RPMS  SOURCES  SPECS  SRPMS
[root@localhost redhat]# tree .(查看当前目录树)
.
|-- BUILD
|-- RPMS
|   |-- athlon
|   |-- geode
|   |-- i386
|   |   |-- nginx-1.0.14-3.i386.rpm
|   |   `-- nginx-debuginfo-1.0.14-3.i386.rpm
|   |-- i486
|   |-- i586
|   |-- i686
|   `-- noarch
|-- SOURCES
|-- SPECS
`-- SRPMS

12 directories, 2 files
提示:不应该使用管理员帐号制作rpm,如果要制作应该切换到普通用户,以普通用户身份在它的家目录下做,这是非常危险的,万一别人在里面放一个非常危险的命令;
[root@localhost redhat]# ls(查看当前目录文件及子目录)
BUILD  RPMS  SOURCES  SPECS  SRPMS
[root@localhost redhat]# cd(切换到用户家目录)
[root@localhost ~]# cd /tmp/(切换到/tmp目录)
提示:下载的src包,即可以不用编译也可以不用安装,只要是src包里面都有spec文件,看别人怎么写spec文件,直接展开也可以;
[root@localhost tmp]# ls(查看当前目录文件及子目录)
fstab  mapping-Smoke  nagios  nginx-1.0.14-3.cpio  nginx-1.0.14-3.src.rpm  scim-panel-socket:0-Smoke  test
[root@localhost tmp]# rpm2cpio nginx-1.0.14-3.src.rpm | cpio -id(将nginx文件转换为cpio文件送给管道展开cpio文件)
1368 blocks
[root@localhost tmp]# ls(查看当前目录文件及子目录)
fstab          nagios               nginx-1.0.14-3.src.rpm  nginx.params  nginx.sysinit              test
mapping-Smoke  nginx-1.0.14-3.cpio  nginx-1.0.14.tar.gz     nginx.spec    scim-panel-socket:0-Smoke
提示:展开之后就有nginx.spec文件了;
[root@localhost tmp]# vim nginx.spec(编辑nginx.spec文件) 

Name:           nginx
Version:        1.0.14
Release:        3%{?dist}
Summary:        A free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server.
Group:          System Environment/Daemons
Vendor: http://www.smoke.com
Packager: smoke <349817712@qq.com>
License:        BSD
URL:            http://www.nginx.org/
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root

BuildRequires:  pcre-devel,zlib-devel,openssl-devel
BuildRequires:  libxslt-devel,gd-devel
Requires:       pcre,openssl,gd
# for /usr/sbin/useradd
Requires(pre):  shadow-utils
Requires(post): chkconfig
# for /sbin/service
Requires(preun):        chkconfig, initscripts
Requires(postun):       initscripts
Provides:               webserver

Source0:  http://sysoev.ru\/nginx/%{name}-%{version}.tar.gz
Source1:  nginx.sysinit
Source2:  nginx.params

%description
Nginx is a free, open-source, high-performance HTTP server and reverse proxy,
as well as an IMAP/POP3 proxy server. Igor Sysoev started development of Nginx
in 2002, with the first public release in 2004. Nginx now hosts nearly 12.18%
(22.2M) of active sites across all domains. Nginx is known for its high

%prep
%setup -q

%build
export DESTDIR=%{buildroot}
./configure \
  --sbin-path=/usr/sbin/nginx \
  --conf-path=/etc/nginx/nginx.conf \
  --error-log-path=/var/log/nginx/error.log \
  --http-log-path=/var/log/nginx/access.log \
  --pid-path=/var/run/nginx/nginx.pid \
  --lock-path=/var/lock/nginx.lock \
  --user=nginx \
  --group=nginx \
  --with-http_ssl_module \
  --with-http_flv_module \
  --with-http_stub_status_module \
  --with-http_gzip_static_module \
  --http-client-body-temp-path=/var/tmp/nginx/client/ \
  --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
  --with-pcre
make %{?_smp_mflags}

%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}
%{__install} -p -d -m 0775 %{buildroot}/var/run/nginx
%{__install} -p -d -m 0775 %{buildroot}/var/log/nginx
%{__install} -p -D -m 0755 %{SOURCE1} %{buildroot}/etc/rc.d/init.d/nginx
mv %{buildroot}/etc/nginx/fastcgi_params %{buildroot}/etc/nginx/fastcgi_params.orig
%{__install} -p -D -m 0644 %{SOURCE2} %{buildroot}/etc/nginx/fastcgi_params

%clean
rm -rf %{buildroot}

%pre
if [ $1 == 1 ]; then
     /usr/sbin/useradd -s /bin/false -r nginx 2>/dev/null || :
fi

%post
if [ $1 == 1 ]; then
     /sbin/chkconfig --add %{name}
fi

%preun
if [ $1 = 0 ]; then
     /sbin/service %{name} stop >/dev/null 2>&1
     /sbin/chkconfig --del %{name}
fi

%files
%defattr(-,root,root,-)
%doc LICENSE CHANGES README
%{_sbindir}/%{name}
%dir /var/run/nginx
%dir /var/log/nginx
%dir /etc/nginx
%config(noreplace) /etc/nginx/win-utf
%config(noreplace) /etc/nginx/mime.types.default
%config(noreplace) /etc/nginx/fastcgi.conf
%config(noreplace) /etc/nginx/fastcgi.conf.default
%config(noreplace) /etc/nginx/fastcgi_params
%config(noreplace) /etc/nginx/fastcgi_params.orig
%config(noreplace) /etc/nginx/fastcgi_params.default
%config(noreplace) /etc/nginx/%{name}.conf
%config(noreplace) /etc/nginx/mime.types
%config(noreplace) /etc/nginx/scgi_params
%config(noreplace) /etc/nginx/scgi_params.default
%config(noreplace) /etc/nginx/uwsgi_params
%config(noreplace) /etc/nginx/uwsgi_params.default
%config(noreplace) /etc/nginx/koi-win
%config(noreplace) /etc/nginx/koi-utf
%config(noreplace) /etc/nginx/%{name}.conf.default
/usr/local/nginx/html/50x.html
/usr/local/nginx/html/index.html
%attr(0775, root, root) /etc/rc.d/init.d/nginx

%changelog
* Fri Sep 23 2016 smoke.com <349817712@qq.com> - 1.0.14-3
-- Add fastcgi_params for php-fpm

* Fri Sep 23 2016 smoke.com <349817712@qq.com> - 1.0.14-2
-- Add sysv script /etc/rc.d/init.d/nginx

* Fri Sep 23 2016 smoke.com <349817712@qq.com> - 1.0.14-1
- Initial version

# End Of nginx.spec

[root@localhost tmp]# vim nginx.spec(编辑nginx.spec) 

%define nginx_user nginx(定义宏)

Name:           nginx
Version:        1.0.14
Release:        3%{?dist}
Summary:        A free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server.
Group:          System Environment/Daemons
Vendor: http://www.smoke.com
Packager: smoke <349817712@qq.com>
License:        BSD
URL:            http://www.nginx.org/
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root

BuildRequires:  pcre-devel,zlib-devel,openssl-devel
BuildRequires:  libxslt-devel,gd-devel
Requires:       pcre,openssl,gd
# for /usr/sbin/useradd
Requires(pre):  shadow-utils
Requires(post): chkconfig
# for /sbin/service
Requires(preun):        chkconfig, initscripts
Requires(postun):       initscripts
Provides:               webserver

Source0:  http://sysoev.ru\/nginx/%{name}-%{version}.tar.gz
Source1:  nginx.sysinit
Source2:  nginx.params

%description
Nginx is a free, open-source, high-performance HTTP server and reverse proxy,
as well as an IMAP/POP3 proxy server. Igor Sysoev started development of Nginx
in 2002, with the first public release in 2004. Nginx now hosts nearly 12.18%
(22.2M) of active sites across all domains. Nginx is known for its high
performance, stability, rich feature set, simple configuration, and low
resource consumption.

%prep
%setup -q

%build
export DESTDIR=%{buildroot}
./configure \
  --sbin-path=/usr/sbin/nginx \
  --conf-path=/etc/nginx/nginx.conf \
  --error-log-path=/var/log/nginx/error.log \
  --http-log-path=/var/log/nginx/access.log \
  --pid-path=/var/run/nginx/nginx.pid \
  --lock-path=/var/lock/nginx.lock \
  --user=%{nginx_user} \(引用宏)
  --group=nginx \
  --with-http_ssl_module \
  --with-http_flv_module \
  --with-http_stub_status_module \
  --with-http_gzip_static_module \
  --http-client-body-temp-path=/var/tmp/nginx/client/ \
  --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
  --with-pcre
make %{?_smp_mflags}

%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}
%{__install} -p -d -m 0775 %{buildroot}/var/run/nginx
%{__install} -p -d -m 0775 %{buildroot}/var/log/nginx
%{__install} -p -D -m 0755 %{SOURCE1} %{buildroot}/etc/rc.d/init.d/nginx
mv %{buildroot}/etc/nginx/fastcgi_params %{buildroot}/etc/nginx/fastcgi_params.orig
%{__install} -p -D -m 0644 %{SOURCE2} %{buildroot}/etc/nginx/fastcgi_params

%clean
rm -rf %{buildroot}

%pre(有特殊意义的宏)
if [ $1 == 1 ]; then
     /usr/sbin/useradd -s /bin/false -r %{nginx} 2>/dev/null || :
fi

%post
if [ $1 == 1 ]; then
     /sbin/chkconfig --add %{name}
fi

%preun
if [ $1 = 0 ]; then
     /sbin/service %{name} stop >/dev/null 2>&1
     /sbin/chkconfig --del %{name}
fi

%files
%defattr(-,root,root,-)
%doc LICENSE CHANGES README
%{_sbindir}/%{name}
%dir /var/run/nginx
%dir /var/log/nginx
%dir /etc/nginx
%config(noreplace) /etc/nginx/win-utf
%config(noreplace) /etc/nginx/mime.types.default
%config(noreplace) /etc/nginx/fastcgi.conf
%config(noreplace) /etc/nginx/fastcgi.conf.default
%config(noreplace) /etc/nginx/fastcgi_params
%config(noreplace) /etc/nginx/fastcgi_params.orig
%config(noreplace) /etc/nginx/fastcgi_params.default
%config(noreplace) /etc/nginx/%{name}.conf
%config(noreplace) /etc/nginx/mime.types
%config(noreplace) /etc/nginx/scgi_params
%config(noreplace) /etc/nginx/scgi_params.default
%config(noreplace) /etc/nginx/uwsgi_params
%config(noreplace) /etc/nginx/uwsgi_params.default
%config(noreplace) /etc/nginx/koi-win
%config(noreplace) /etc/nginx/koi-utf
%config(noreplace) /etc/nginx/%{name}.conf.default
/usr/local/nginx/html/50x.html
/usr/local/nginx/html/index.html
%attr(0775, root, root) /etc/rc.d/init.d/nginx

%changelog
* Fri Sep 23 2016 smoke.com <349817712@qq.com> - 1.0.14-3
-- Add fastcgi_params for php-fpm

* Fri Sep 23 2016 smoke.com <349817712@qq.com> - 1.0.14-2
-- Add sysv script /etc/rc.d/init.d/nginx

* Fri Sep 23 2016 smoke.com <349817712@qq.com> - 1.0.14-1
- Initial version

# End Of nginx.spec

[root@localhost ~]# cd /home/Smoke/rpmbuild/(切换到/home/Smoke/rpmbuild目录)
[root@localhost rpmbuild]# ls(查看当前目录文件及子目录)
BUILD  RPMS  SOURCES  SPECS  SRPMS
[root@localhost rpmbuild]# cd BUILD/(切换到BUILD目录)
[root@localhost BUILD]# ls(查看当前目录文件及子目录)
nginx-1.0.14
[root@localhost BUILD]# cd nginx-1.0.14/(切换到nginx-1.0.14目录)
[root@localhost nginx-1.0.14]# ls(查看当前目录文件及子目录)
auto     CHANGES\.ru  configure  debugfiles.list  debugsources.list  LICENSE   man   README
CHANGES  conf        contrib    debuglinks.list  html               Makefile  objs  src
[root@localhost nginx-1.0.14]# less LICENSE(分页显示LICENSE文件)

/* 
 * Copyright (C) 2002-2012 Igor Sysoev
 * Copyright (C) 2011,2012 Nginx, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

[root@localhost nginx-1.0.14]# cd(切换到用户家目录)
[root@localhost ~]# cd /tmp/(切换到/tmp目录)
[root@localhost tmp]# ls(查看当前目录文件及子目录)
fstab          nagios               nginx-1.0.14-3.src.rpm  nginx.params  nginx.sysinit              test
mapping-Smoke  nginx-1.0.14-3.cpio  nginx-1.0.14.tar.gz     nginx.spec    scim-panel-socket:0-Smoke
[root@localhost tmp]# tar xf nginx-1.0.14.tar.gz -C /var/tmp/(解压nginx文件,x解压,f后面跟文件-C更改解压目录)
[root@localhost tmp]# cd /var/tmp/(切换到/var/tmp目录)
[Smoke@localhost SPECS]$ rpmbuild -bp nginx.spec(制作rpm包,只制作到%prep阶段) Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.26023
+ umask 022
+ cd /home/Smoke/rpmbuild/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /home/Smoke/rpmbuild/BUILD
+ rm -rf nginx-1.0.14
+ /usr/bin/gzip -dc /home/Smoke/rpmbuild/SOURCES/nginx-1.0.14.tar.gz
+ tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd nginx-1.0.14
++ /usr/bin/id -u
+ '[' 500 = 0 ']'
++ /usr/bin/id -u
+ '[' 500 = 0 ']'
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
[root@localhost tmp]# gzip -dc /tmp/nginx-1.0.14.tar.gz | tar -xf -(解压nginx从标准输出送给管道解压当前文件,-d解压,-c从标准输出,-代表当前文件)
[root@localhost tmp]# ls(查看当前目录文件及子目录)
nginx  nginx-1.0.14  rpm-tmp.78597  rpm-tmp.96765
[root@localhost tmp]# man install(查看install的man文档)

       -p, --preserve-timestamps(把原来的时间戳保留)
              apply access/modification times of SOURCE files to corresponding destination files

[Smoke@localhost SPECS]$ rpmbuild -bi nginx.spec(制作rpm包,执行到安装,安装buildroot路径下)
[Smoke@localhost SPECS]$ rpmbuild --clean nginx.spec(清理nginx.spec当中所定义的clean命令执行一下)         
Executing(--clean): /bin/sh -e /var/tmp/rpm-tmp.40228
+ umask 022
+ cd /home/Smoke/rpmbuild/BUILD
+ rm -rf nginx-1.0.14
+ exit 0
[Smoke@localhost ~]$ cd rpmbuild/SOURCES/(切换到rpmbuild/SOURCES目录)
[Smoke@localhost SOURCES]$ ls(查看当前目录文件及子目录)
nginx-1.0.14.tar.gz  nginx.params  nginx.sysinit
[Smoke@localhost SOURCES]$ lftp 172.16.0.1(连接ftp服务器)
lftp 172.16.0.1:~> cd pub/Sources/nagios(切换到pub/Sources/nagios目录)
lftp 172.16.0.1:/pub/Sources/nagios> mirror linuso_20101113/(映像到本地)
new: 5 files, 0 symlinks
13527593 bytes transferred
lftp 172.16.0.1:/pub/Sources/nagios> bye(退出)
[Smoke@localhost SOURCES]$ ls(查看当前目录文件及子目录)
fetion_for_x32.gz  nginx-1.0.14.tar.gz  nginx.params  nginx.sysinit
[Smoke@localhost SOURCES]$ tar xf fetion_for_x32.gz(解压fetion文件)
[Smoke@localhost SOURCES]$ ls(查看当前目录文件及子目录)
fetion_for_x32  fetion_for_x32.gz  nginx-1.0.14.tar.gz  nginx.params  nginx.sysinit
[Smoke@localhost SOURCES]$ mv fetion_for_x32 fetion-0.1.1(重命名fetion_for_x32为fetion-0.1.1)
[Smoke@localhost SOURCES]$ tar jcf fetion-0.1.1.tar.bz2 fetion-0.1.1/*(将fetion-0.1.1所有文件压缩,j代表bz2格式压缩,c创建压缩,f后面跟文件)
[Smoke@localhost SOURCES]$ ls(查看当前目录文件及子目录)
fetion-0.1.1  fetion-0.1.1.tar.bz2  fetion_for_x32.gz  nginx-1.0.14.tar.gz  nginx.params  nginx.sysinit
[Smoke@localhost SOURCES]$ rm -rf fetion-0.1.1 fetion_for_x32.gz(删除feton-0.1.1目录和fetion_for_x32.gz文件,r递归删除,-f强制删除)
[Smoke@localhost SOURCES]$ ls(查看当前目录文件及子目录)
fetion-0.1.1.tar.bz2  nginx-1.0.14.tar.gz  nginx.params  nginx.sysinit
[Smoke@localhost SOURCES]$ tar xf fetion-0.1.1.tar.bz2(解压fetion文件,x解压,f后面跟文件) 
[Smoke@localhost SOURCES]$ ls(查看当前目录文件及子目录)
fetion-0.1.1  fetion-0.1.1.tar.bz2  nginx-1.0.14.tar.gz  nginx.params  nginx.sysinit
[Smoke@localhost SOURCES]$ rm -rf fetion-0.1.1(删除fetion-0.1.1文件)
[Smoke@localhost SOURCES]$ ls(查看当前目录文件及子目录)
fetion-0.1.1.tar.bz2  nginx-1.0.14.tar.gz  nginx.params  nginx.sysinit
[Smoke@localhost SOURCES]$ cd ../SPECS(切换到SPECS目录)
[Smoke@localhost SPECS]$ vim fetion.spec(编辑fetion.spec文件)
[Smoke@localhost SPECS]$ lftp 172.16.0.1(连接ftp服务器)
lftp 172.16.0.1~> cd pub/Sources/rpmbuild/(切换到pub/Sources/rpmbuild目录)
lftp 172.16.0.1:/pub/Sources/rpmbuild> get example.spec(下载example.spec文件)
509 bytes transferred
lftp 172.16.0.1:/pub/Sources/rpmbuild> bye(退出)
[Smoke@localhost SPECS]$ vim fetion.spec(编辑fetion.spec文件)

Name: fetion
Version: 0.1.1
Release:        1%{?dist}
Summary: fetion rebot

Group: Applications/Internet
License: GPL
URL: http://smoke.com
Packager: smoke.com <349817712@qq.com>
Vendor: http://www.smoke.com

Source0: fetion-0.1.1.tar.bz2
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root

#Requires:

%description
fetion robot from Internet.

%prep
%setup -q

%build

%install
rm -rf $RPM_BUILD_ROOT
%{__install} -p -D -m 0755 fetion %{buildroot}/usr/local/bin/fetion
%{__install} -p -D -m 0755 libACE-5.7.2.so %{buildroot}/usr/local/lib/libACE-5.7.2.so
%{__install} -p -D -m 0755 libACE_SSL-5.7.2.so %{buildroot}/usr/local/lib/libACE_SSL-5.7.2.so
%{__install} -p -D -m 0755 libcrypto.so.4 %{buildroot}/usr/local/lib/libcrypto.so.4
%{__install} -p -D -m 0755 libssl.so.4 %{buildroot}/usr/local/lib/libssl.so.4


%clean
rm -rf $RPM_BUILD_ROOT

#%pre

%post
if [ $1 == 1 ]; then
  echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
  /sbin/ldconfig
fi

#%preun
if [ $1 == 0 ]; then
  rm -f /etc/ld.so.conf.d/usr_local.conf 2> /dev/null || :
  /sbin/ldconfig
fi

%files
%defattr(-,root,root,-)
%attr(0755,root,root) /usr/local/bin/fetion
/usr/local/lib/libACE-5.7.2.so
/usr/local/lib/libACE_SSL-5.7.2.so
/usr/local/lib/libcrypto.so.4
/usr/local/lib/libssl.so.4

%changelog
* Fri Sep 23 2016 Smoke <349817712@qq.com> - 0.1.1-1
- Initial version

[root@localhost ~]# less /usr/share/doc/rpm-4.4.2.3/GROUPS(分页显示GROUPS文件)

Amusements/Games
Amusements/Graphics
Applications/Archiving
Applications/Communications
Applications/Databases
Applications/Editors
Applications/Emulators
Applications/Engineering
Applications/File
Applications/Internet
Applications/Multimedia
Applications/Productivity
Applications/Publishing
Applications/System
Applications/Text
Development/Debuggers
Development/Languages
Development/Libraries
Development/System
Development/Tools
Documentation
System Environment/Base
System Environment/Daemons
System Environment/Kernel
System Environment/Libraries
System Environment/Shells
User Interface/Desktops
User Interface/X
User Interface/X Hardware Support

[root@localhost fetion_for_x32]# ls(查看当前目录文件及子目录)
fetion  libACE-5.7.2.so  libACE_SSL-5.7.2.so  libcrypto.so.4  libssl.so.4
[root@localhost SOURCES]# which ldconfig(查看ldconfig命令绝对路径)
/sbin/ldconfig
[Smoke@localhost SPECS]$ rpmbuild -bc fetion.spec(制作rpm包,执行到%build阶段)
[Smoke@localhost SPECS]$ rpmbuild -ba fetion.spec(制作rpm包,既制作二进制格式又制作源码格式rpm包)
[root@localhost SOURCES]# cd(切换到用户家目录)
[root@localhost ~]# rpm -ivh /home/Smoke/rpmbuild/RPMS/i386/fetion-0.1.1-1.i386.rpm(安装fetion软件) 
Preparing...                ########################################### [100%]
   1:fetion                 ########################################### [100%]
error: unpacking of archive failed on file /usr/local/lib/libcrypto.so.4;57e548b8: cpio: MD5 sum mismatch(解压包md5信息有误)
[Smoke@localhost SPECS]$ vim fetion.spec(编辑fetion.spec文件)

Name: fetion
Version: 0.1.1
Release:        1%{?dist}
Summary: fetion rebot

Group: Applications/Internet
License: GPL
URL: http://smoke.com
Packager: smoke.com <349817712@qq.com>
Vendor: http://www.smoke.com

Source0: fetion-0.1.1.tar.bz2
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root

#Requires:

%description
fetion robot from Internet.

%prep
%setup -q

%build

%install
rm -rf $RPM_BUILD_ROOT
%{__install} -p -D -m 0755 fetion %{buildroot}/usr/local/bin/fetion
%{__install} -p -D -m 0755 libACE-5.7.2.so %{buildroot}/usr/local/lib/libACE-5.7.2.so
%{__install} -p -D -m 0755 libACE_SSL-5.7.2.so %{buildroot}/usr/local/lib/libACE_SSL-5.7.2.so
#%{__install} -p -D -m 0755 libcrypto.so.4 %{buildroot}/usr/local/lib/libcrypto.so.4
%{__install} -p -D -m 0755 libssl.so.4 %{buildroot}/usr/local/lib/libssl.so.4


%clean
rm -rf $RPM_BUILD_ROOT

#%pre

%post
if [ $1 == 1 ]; then
  echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
  /sbin/ldconfig
fi

#%preun
if [ $1 == 0 ]; then
  rm -f /etc/ld.so.conf.d/usr_local.conf 2> /dev/null || :
  /sbin/ldconfig
fi

%files
%defattr(-,root,root,-)
%attr(0755,root,root) /usr/local/bin/fetion
/usr/local/lib/libACE-5.7.2.so
/usr/local/lib/libACE_SSL-5.7.2.so
#/usr/local/lib/libcrypto.so.4
/usr/local/lib/libssl.so.4

%changelog
* Fri Sep 23 2016 Smoke <349817712@qq.com> - 0.1.1-1
- Initial version

[Smoke@localhost SPECS]$ ls /usr/lib | grep crypt(查看/usr/lib目录文件及子目录将结果送给管道只显示crypt相关)
libcrypt.a
libcrypto.a
libcrypto.so
libcryptsetup.so.0
libcryptsetup.so.0.0.0
libcrypt.so
libgcrypt.a
libgcrypt.so
libgcrypt.so.11
libgcrypt.so.11.5.2
libk5crypto.a
libk5crypto.so
libk5crypto.so.3
libk5crypto.so.3.1
[Smoke@localhost SPECS]$ rpmbuild -ba fetion.spec(制作rpm包,既制作二进制格式又制作源码格式rpm包)
[root@localhost ~]# rpm -ivh /home/Smoke/rpmbuild/RPMS/i386/fetion-0.1.1-1.i386.rpm(安装fetion软件) 
error: Failed dependencies:
	libcrypto.so.4 is needed by fetion-0.1.1-1.i386
[Smoke@localhost SPECS]$ vim fetion.spec(编辑fetion.spec文件)

Name: fetion
Version: 0.1.1
Release:        1%{?dist}
Summary: fetion rebot

Group: Applications/Internet
License: GPL
URL: http://smoke.com
Packager: smoke.com <349817712@qq.com>
Vendor: http://www.smoke.com

Source0: fetion-0.1.1.tar.bz2
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root

#Requires:

%description
fetion robot from Internet.

%prep
%setup -q

%build

%install
rm -rf $RPM_BUILD_ROOT
%{__install} -p -D -m 0755 fetion %{buildroot}/usr/local/bin/fetion
%{__install} -p -D -m 0755 libACE-5.7.2.so %{buildroot}/usr/local/lib/libACE-5.7.2.so
%{__install} -p -D -m 0755 libACE_SSL-5.7.2.so %{buildroot}/usr/local/lib/libACE_SSL-5.7.2.so
%{__install} -p -D -m 0755 libcrypto.so.4 %{buildroot}/usr/local/lib/libcrypto.so.4
%{__install} -p -D -m 0755 libssl.so.4 %{buildroot}/usr/local/lib/libssl.so.4


%clean
rm -rf $RPM_BUILD_ROOT

#%pre

%post
if [ $1 == 1 ]; then
  echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
  /sbin/ldconfig
fi

#%preun
if [ $1 == 0 ]; then
  rm -f /etc/ld.so.conf.d/usr_local.conf 2> /dev/null || :
  /sbin/ldconfig
fi

%files
%defattr(-,root,root,-)
%attr(0755,root,root) /usr/local/bin/fetion
/usr/local/lib/libACE-5.7.2.so
/usr/local/lib/libACE_SSL-5.7.2.so
/usr/local/lib/libcrypto.so.4
/usr/local/lib/libssl.so.4

%changelog
* Fri Sep 23 2016 Smoke <349817712@qq.com> - 0.1.1-1
- Initial version
[Smoke@localhost SPECS]$ rpmbuild -ba fetion.spec(制作rpm包,既制作二进制格式又制作源码格式rpm包)
[root@localhost ~]# rpm -ivh /home/Smoke/rpmbuild/RPMS/i386/fetion-0.1.1-1.i386.rpm(安装fetion软件) 
Preparing...                ########################################### [100%]
   1:fetion                 ########################################### [100%]
error: unpacking of archive failed on file /usr/local/lib/libcrypto.so.4;57e548b8: cpio: MD5 sum mismatch(解压包md5信息有误)
[root@localhost ~]# rpm -ivh /home/Smoke/rpmbuild/RPMS/i386/fetion-0.1.1-1.i386.rpm --force(安装fetion软件,--force强制安装)
Preparing...                ########################################### [100%]
   1:fetion                 ########################################### [100%]
error: unpacking of archive failed on file /usr/local/lib/libcrypto.so.4;57e54a72: cpio: MD5 sum mismatch
[root@localhost ~]# man rpm(查看rpm命令的man文档)

       rpm {-K|--checksig} [--nosignature] [--nodigest]
           PACKAGE_FILE ...(验证包的来源)

[Smoke@localhost i386]$ gpg --gen-key(生成一组密钥)
gpg (GnuPG) 1.4.5; Copyright (C) 2006 Free Software Foundation, Inc.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions. See the file COPYING for details.

gpg: directory `/root/.gnupg' created(在用户家目录创建.gnupg的隐藏目录)
gpg: new configuration file `/root/.gnupg/gpg.conf' created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: keyring `/root/.gnupg/pubring.gpg' created
Please select what kind of key you want:
   (1) DSA and Elgamal (default)
   (2) DSA (sign only)
   (5) RSA (sign only)
Your selection? 1(选择签名算法)
DSA keypair will have 1024 bits.
ELG-E keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 1024(密钥长度)
Requested keysize is 1024 bits
Please specify how long the key should be valid.
         0 = key does not expire(永不过期)
      <n>  = key expires in n days(n天)
      <n>w = key expires in n weeks(n周)
      <n>m = key expires in n months(n月)
      <n>y = key expires in n years(n年)
Key is valid for? (0) (有效期限)
Key does not expire at all
Is this correct? (y/N) y(确认)

You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
    "Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"

Real name: Smoke(名字)
Email address: 349817712@qq.com(邮箱)
Comment: 
You selected this USER-ID:
    "Smoke <349817712@qq.com>"

Change (N)ame,(改名) (C)omment,(改注释) (E)mail(该邮箱) or (O)kay(确认)/(Q)uit? O
You need a Passphrase to protect your secret key.

You don't want a passphrase - this is probably a *bad* idea!
I will do it anyway.  You can change your passphrase at any time,
using this program with the option "--edit-key".

We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
..++++++++++++++++++++++++++++++++++++++++++++++++++....+++++++++++++++.+++++.++++++++++.++++++++++++++++++++++++++++++..+++++

Not enough random bytes available.  Please do some other work to give
the OS a chance to collect more entropy! (Need 284 more bytes)
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
++++++++++++++++++++++++++++++.+++++++++++++++.+++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key FF1841BF marked as ultimately trusted
public and secret key created and signed.

gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
pub   1024D/FF1841BF 2016-09-23
      Key fingerprint = 08A9 99DC 3D16 C32A 8579  F5BD A87F EB12 FF18 41BF
uid                  Smoke <349817712@qq.com>
sub   1024g/D52F2623 2016-09-23

[root@localhost ~]# su - Smoke(切换到Smoke用户)
[Smoke@localhost ~]$ cd rpmbuild/SPECS/(切换到rpmbuild/SPECS目录)
[Smoke@localhost SPECS]$ vim fetion.spec(编辑fetion.spec文件)

Name: fetion
Version: 0.1.1
Release:        1%{?dist}
Summary: fetion rebot

Group: Applications/Internet
License: GPL
URL: http://smoke.com
Packager: smoke.com <349817712@qq.com>
Vendor: http://www.smoke.com

Source0: fetion-0.1.1.tar.bz2
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root

#Requires:

%description
fetion robot from Internet.

%package libs
Summary: fetion libraries.
Group: Development/Libraries
Requires: %{name} = %{version}

%description libs
fetion libraries.

%prep
%setup -q

%build

%install
rm -rf $RPM_BUILD_ROOT
%{__install} -p -D -m 0755 fetion %{buildroot}/usr/local/bin/fetion
%{__install} -p -D -m 0755 libACE-5.7.2.so %{buildroot}/usr/local/lib/libACE-5.7.2.so
%{__install} -p -D -m 0755 libACE_SSL-5.7.2.so %{buildroot}/usr/local/lib/libACE_SSL-5.7.2.so
%{__install} -p -D -m 0755 libcrypto.so.4 %{buildroot}/usr/local/lib/libcrypto.so.4
%{__install} -p -D -m 0755 libssl.so.4 %{buildroot}/usr/local/lib/libssl.so.4

%clean
rm -rf $RPM_BUILD_ROOT

#%pre

%post
if [ $1 == 1 ]; then
  echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
  /sbin/ldconfig
fi

#%preun

%postun
if [ $1 == 0 ]; then
  rm -f /etc/ld.so.conf.d/usr_local.conf 2> /dev/null || :
  /sbin/ldconfig
fi

%files
%defattr(-,root,root,-)
%attr(0755,root,root) /usr/local/bin/fetion

%files libs
%defattr(-,root,root,-)
/usr/local/lib/libACE-5.7.2.so
/usr/local/lib/libACE_SSL-5.7.2.so
/usr/local/lib/libcrypto.so.4
/usr/local/lib/libssl.so.4

%changelog
* Fri Sep 23 2016 Smoke <349817712@qq.com> - 0.1.1-1
- Initial version

[root@localhost ~]# less /usr/share/doc/rpm-4.4.2.3/GROUPS(分页显示GROUPS文件内容)

Amusements/Games
Amusements/Graphics
Applications/Archiving
Applications/Communications
Applications/Databases
Applications/Editors
Applications/Emulators
Applications/Engineering
Applications/File
Applications/Internet
Applications/Multimedia
Applications/Productivity
Applications/Publishing
Applications/System
Applications/Text
Development/Debuggers
Development/Languages
Development/Libraries
Development/System
Development/Tools
Documentation
System Environment/Base
System Environment/Daemons
System Environment/Kernel
System Environment/Libraries
System Environment/Shells
User Interface/Desktops
User Interface/X
User Interface/X Hardware Support

[Smoke@localhost SPECS]$ rpmbuild -ba fetion.spec(制作rpm包,既制作二进制格式又制作源码格式rpm包)
[root@localhost ~]# rpm -ivh /home/Smoke/rpmbuild/RPMS/i386/fetion-libs-0.1.1-1.i386.rpm(安装fetion-libs软件)
error: Failed dependencies:(依赖错误,依赖于fetion)
	fetion = 0.1.1 is needed by fetion-libs-0.1.1-1.i386
[Smoke@localhost SPECS]$ cd ../RPMS/i386/(切换到RPMS/i386目录)
[Smoke@localhost i386]$ ls
fetion-0.1.1-1.i386.rpm            nginx-1.0.14-1.i386.rpm  nginx-debuginfo-1.0.14-1.i386.rpm
fetion-debuginfo-0.1.1-1.i386.rpm  nginx-1.0.14-2.i386.rpm  nginx-debuginfo-1.0.14-2.i386.rpm
fetion-libs-0.1.1-1.i386.rpm       nginx-1.0.14-3.i386.rpm  nginx-debuginfo-1.0.14-3.i386.rpm
[Smoke@localhost i386]$ gpg --list-keys(查看密钥)
/home/Smoke/.gnupg/pubring.gpg
------------------------------
pub   1024D/C9537ADF 2016-09-23
uid                  Smoke <349817712@qq.com>
sub   1024g/8AD94C57 2016-09-23
[Smoke@localhost i386]$ gpg --export -a 'Smoke' > RPM-GPG-KEY-Smoke(导出公钥)
[Smoke@localhost i386]$ ll(查看当前目录文件及子目录详细信息)
total 16128
-rw-rw-r-- 1 Smoke Smoke 4656770 Sep 24 00:08 fetion-0.1.1-1.i386.rpm
-rw-rw-r-- 1 Smoke Smoke 3674367 Sep 24 00:08 fetion-debuginfo-0.1.1-1.i386.rpm
-rw-rw-r-- 1 Smoke Smoke 1114258 Sep 24 00:08 fetion-libs-0.1.1-1.i386.rpm
-rw-rw-r-- 1 Smoke Smoke  277245 Sep 23 16:04 nginx-1.0.14-1.i386.rpm
-rw-rw-r-- 1 Smoke Smoke  278489 Sep 23 16:47 nginx-1.0.14-2.i386.rpm
-rw-rw-r-- 1 Smoke Smoke  278755 Sep 23 17:03 nginx-1.0.14-3.i386.rpm
-rw-rw-r-- 1 Smoke Smoke 2043159 Sep 23 16:04 nginx-debuginfo-1.0.14-1.i386.rpm
-rw-rw-r-- 1 Smoke Smoke 2043240 Sep 23 16:47 nginx-debuginfo-1.0.14-2.i386.rpm
-rw-rw-r-- 1 Smoke Smoke 2043319 Sep 23 17:03 nginx-debuginfo-1.0.14-3.i386.rpm
-rw-rw-r-- 1 Smoke Smoke    1324 Sep 24 00:31 RPM-GPG-KEY-Smoke
[Smoke@localhost i386]$ vim ~/.rpmmacros(编辑.rpmmacros文件)

%_topdir        /home/Smoke/rpmbuild
%_gpg_name      Smoke

[Smoke@localhost i386]$ rpm --addsign fetion-0.1.1-1.i386.rpm(给rpm包添加签名) 
Enter pass phrase: 
Pass phrase is good.
fetion-0.1.1-1.i386.rpm:
gpg: WARNING: standard input reopened
gpg: WARNING: standard input reopened
[Smoke@localhost i386]$ cp RPM-GPG-KEY-Smoke /tmp/(复制RPM-GPG-KEY-Smoke文件到/tmp目录)
[root@localhost ~]# rpm --import /tmp/RPM-GPG-KEY-Smoke(导入密钥)
[Smoke@localhost i386]$ cp fetion-0.1.1-1.i386.rpm /tmp/(复制fetion文件到/tmp目录)
[root@localhost ~]# rpm -K /tmp/fetion-0.1.1-1.i386.rpm(验证包的来源)
/tmp/fetion-0.1.1-1.i386.rpm: (sha1) dsa sha1 md5 gpg OK
[root@localhost ~]# rpm -qpi /tmp/fetion-0.1.1-1.i386.rpm(查看fetion软件包的信息) 
Name        : fetion                       Relocations: (not relocatable)
Version     : 0.1.1                             Vendor: http://www.smoke.com
Release     : 1                             Build Date: Sat 24 Sep 2016 12:08:36 AM CST
Install Date: (not installed)               Build Host: localhost.localdomain
Group       : Applications/Internet         Source RPM: fetion-0.1.1-1.src.rpm
Size        : 4663495                          License: GPL
Signature   : DSA/SHA1, Sat 24 Sep 2016 12:34:47 AM CST, Key ID f266562dc9537adf
Packager    : smoke.com <349817712@qq.com>
URL         : http://smoke.com
Summary     : fetion rebot
Description :
fetion robot from Internet.
[root@localhost ~]# man rpm(查看rpm包的man手册)

       rpm {--addsign(添加签名)|--resign(修改软件包签名)} PACKAGE_FILE ...

[Smoke@localhost i386]$ vim ~/.rpmmacros(编辑.rpmmacros文件)

%_topdir        /home/Smoke/rpmbuild
%_gpg_name      Smoke
%_signature     gpg(签名方法)