linux之rpm包制作


难点:spec文件的编写


1,首先安装rpm-build命令

yum install rpm-build

2,介绍spec编写规则:

#ll
#drwxr-xr-x  2 root root 4096 Jul 29 13:50 BUILD
#drwxr-xr-x  2 root root 4096 Jul 29 13:51 RPMS
#drwxr-xr-x  2 root root 4096 Jul 29 13:51 SOURCES
#drwxr-xr-x  2 root root 4096 Jul 29 13:51 SPECS
#drwxr-xr-x  2 root root 4096 Jul 29 13:51 SRPMS


rpmbuild --showrc  #查看一些变量


rpmbuild --showrc | grep macrofiles  定义宏变量


vim .rpmmacros

%_topdir /home/sm/rpmbuild

mkdir pv /home/sm/rpmbuild/BUILD RPMS SOURCES SPECS SRPMS 


之后查看_topdir:

rpmbuild --showrc | grep _topdir


发现topdir路径已经改成了/home/sm/rpmbuild了

Summary:

Name:

Version: 2.2

License: GPLv2

Group:

URL:


Packager: Richie.Song<***.@qq.com>

Vendor: Richie


Source:

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root


BuildRequires: gcc,gd-devel


%description

***********描述信息**********


%prep

%setup -q  (静默模式)


%build

./configure \

--参数

%{__make} %{?_smp_mflags}


%install

%{__rm} -fr %{buildroot}

%{__make} install DESTDIR="%{buildroot}" 安装到buildroot下

-d  #创建目录

-D    #create all leading components of DEST except the  last,  then  copy

              SOURCE to DEST

%clean

%{__rm} -fr %{buildroot}


#scripts

%pre     安装前执行的脚本

%post    安装后执行的脚本

%preun   卸载前执行的脚本

%postun  卸载后执行的脚本


%files

%defattr(-,root,root,0755)

%doc %{_mandir}/man1/*

%config %{_sysconfdir}/


%changelog

*    时间 

-    谁更改的


#rpmbuild  -ba 二进制+源码

  -bb 二进制

  -bs 源码

  -bc

  -bi 到install

  -bl

  -bp 到pre


nginx例子分析:


Summary:

Version:

Release:

Group:

Vendor:

Packager:

License:

URL:


BuildRoot:


BuildRequires: build依赖包

Requires:  安装依赖包


Requires(pre): shadow-utils

Reuqires(post): chkconfig


Requires(preun): chkconfig,initscripts

Requires(postun): initscripts


Provides: webserver


Source0: http://nginx.%{version}tar.gz

Source1: 

%description


%prep

%setup -q


%build

export DESTDIR=%{buildroot}

./configure \

--

--

make %{?_smp_mflags}


%install

rm -fr %{buildroot}

make install DESTDIR=%{buildroot}

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

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


%clean

 rm -fr %{buildroot}


%pre

if [ $1 == 1 ]; then

/usr/sbin/useradd -s /bin/false -r nginx 2>/dev/null ||: #如果失败就停止,冒号代表停止

fi

%post

if [ $1 == 1 ]; then  #1代表第一次安装

  /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,-)


%{_sbindir}/%{name}

%dir /etc/nginx  #明确说明空目录

%config(noreplace) /etc/nginx/*

%doc  /usr/

%docdir  


--prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --http-log-path=/var/log/nginx/access.log --add-module=/root/downloads/nginx-upload-progress-module/ --add-module=/root/downloads/nginx-http-concat/


rpmbuild --rebuild src.rpm  #重新编译成RPM包到工作车间里,直接使用即可

rpm2cpio *.src.rpm | cpio -id  解压里面的文件到当前目录

| cpio -t 查看包含文件


rpmfind.net src包

rpmpone.com


注释中不要用到%,如果一定要表示%  可以双%%。



nginx实例:

Name:           nginx

Version:        1.4.7

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.songming.com

Packager: Richie <[email protected]>

License:        BSD

URL:            http://www.nginx.org/ 

BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root

 

BuildRequires:      pcre-devel,zlib-devel,openssl-devel,git

BuildRequires:      libxslt-devel,gd-devel

Requires:           pcre,openssl,gd

# for /usr/sbin/useradd

Requires(pre):      shadow-utils,git

Requires(post):     chkconfig

# for /sbin/service

Requires(preun):    chkconfig, initscripts

Requires(postun):   initscripts

Provides:           webserver

 

Source0:    http://sysoev.ru/nginx/nginx-%{version}.tar.gz

Source1:    nginx.init

Source2:    nginx.conf

Source3:    ecommerce.conf

#Source4:    README.md

#Source5:    config


%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

#rm -fr /root/downloads

#mkdir /root/downloads

#cd /root/downloads

#git clone https://github.com/masterzen/nginx-upload-progress-module.git

#git clone https://github.com/alibaba/nginx-http-concat.git

%build

export DESTDIR=%{buildroot}

./configure \

  --prefix=/usr/local/nginx \

  --sbin-path=/usr/sbin/nginx \

  --error-log-path=/var/log/nginx/error.log \

  --conf-path=/etc/nginx/nginx.conf \

  --http-log-path=/var/log/nginx/access.log \

  --pid-path=/var/run/nginx/nginx.pid  \

  --user=nginx \

  --group=nginx \

  --with-http_realip_module \

  --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 \

#  --add-module=/root/downloads/nginx-upload-progress-module \

#  --add-module=/root/downloads/nginx-http-concat 

make %{?_smp_mflags}

 

%install

rm -rf %{buildroot}

make install DESTDIR=%{buildroot} 

%{__install} -p -D -m 0755 %{SOURCE1} %{buildroot}%{_initrddir}/%{name}

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

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

mv %{buildroot}/etc/nginx/nginx.conf %{buildroot}/etc/nginx/nginx.conf.old


%{__install} -p -D -m 0644 %{SOURCE2} %{buildroot}/etc/nginx/nginx.conf

%{__install} -p -D -m 0644 %{SOURCE3} %{buildroot}/etc/nginx/conf.d/ecommerce.conf

#%{__install} -p -D -m 0644 %{SOURCE5} %{buildroot}/root/downloads/nginx-http-concat/config

#%{__install} -p -D -m 0644 %{SOURCE3} %{buildroot}/root/downloads/nginx-http-concat/ngx_http_concat_module.c

#%{__install} -p -D -m 0644 %{SOURCE4} %{buildroot}/root/downloads/nginx-http-concat/README.md



%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/nginx.conf

%config(noreplace) /etc/nginx/nginx.conf.old

%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/conf.d/ecommerce.conf

%config(noreplace) /etc/nginx/%{name}.conf.default

/usr/local/nginx/html/50x.html

/usr/local/nginx/html/index.html

%attr(0755, root, root) %{_initrddir}/%{name}

 

%changelog

* Wed Apr 11 2014 Richie <[email protected]> - 1.4.7-2

- Replace nginx.conf on line

* Wed Apr 07 2014 Richie <[email protected]> - 1.4.7-1

- Initial version


本文出自 “守望de猫” 博客,请务必保留此出处http://1460169.blog.51cto.com/1450169/1533291

linux之rpm包制作,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。