rpmbuild的原理,意義,具體參考官方文檔
http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/index.html
一、rpmbuild大致步驟
英文 | 中文 |
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的文件,編輯rpmbuild命令要做什麼 |
4.Build the source andbinary RPMs | 建立源碼及二進制包 |
二、rpmbuild各目錄的作用
BUILD | The rpmbuild command builds software in this directory |
RPMS | The rpmbuild command stores binary RPMs it reates in this irectory |
SOURCES | You should put the sources for the application in this directory |
SPECS | You should place the spec file for each RPM you plan to make in this directory |
SRPMS | The rpmbuild command places source RPMs in this directory |
三、rpmbuild安裝配置步驟
3.1、安裝rpm-build軟件包
在製作rpm包之前,需要安裝rpm-build這個軟件包
[root@test01 ~]# yum -y install rpm-build 增加一個普通用戶,不要以root身份來進行rpmbuild,危險操作,慎重,慎重! [root@test01 ~]# useradd kuangl [root@test01 ~]# su – kuangl |
3.2、創建rpmbuild所需要的目錄
[kuangl@test01 software]$ mkdir -pv rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} mkdir: 已創建目錄 “rpmbuild” mkdir: 已創建目錄 “rpmbuild/BUILD” mkdir: 已創建目錄 “rpmbuild/RPMS” mkdir: 已創建目錄 “rpmbuild/SOURCES” mkdir: 已創建目錄 “rpmbuild/SPECS” mkdir: 已創建目錄 “rpmbuild/SRPMS” [kuangl@test01 software]$ echo "% _topdir/home/kuangl/rpmbuild" >~/.rpmmacros [kuangl@test01 software]$ rpmbuild --showrc|grep _topdir -14: _builddir%{_topdir}/BUILD -14: _rpmdir%{_topdir}/RPMS -14: _sourcedir%{_topdir}/SOURCES -14: _specdir%{_topdir}/SPECS -14: _srcrpmdir%{_topdir}/SRPMS -14: _topdir/home/admin/rpmbuild |
3.3、rpmbuild系統內置變量
查看rpmbuild的內置變量
[kuangl@test01 software]$ rpmbuild --showrv |
3.4、默認的spec格式如下
[kuangl@test01 SPECS]$ pwd /home/kuangl/software/rpmbuild/SPECS [kuangl@test01 SPECS]$ vim test.spec |
隨便建立個以spec結尾的文件名,會出現以下信息
Name: Version: Release:1%{?dist} Summary: Group: License: URL: Source0: BuildRoot:%(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) BuildRequires: Requires: %description %prep %setup -q %build %configure make %{?_smp_mflags} %install rm -rf %{buildroot} make install DESTDIR=%{buildroot} %clean rm -rf %{buildroot} %files %defattr(-,root,root,-) %doc %changelog |
3.5、Spec文件中常用的變量
變量 | 系統目錄 |
RPM_BUILD_DIR: | /$HOME/rpmbuild/BUILD |
RPM_BUILD_ROOT: | /$HOME/rpmbuild/BUILDROOT |
%{_sysconfdir}: | /etc |
%{_sbindir}: | /usr/sbin |
%{_bindir}: | /usr/bin |
%{_datadir}: | /usr/share |
%{_mandir}: | /usr/share/man |
%{_libdir}: | /usr/lib64 |
%{_prefix}: | /usr |
%{_localstatedir}: | /usr/var |
3.6、rpmbuild的步驟
%prep預處理腳本程序(prep)開始執行" %setup %build"編譯連接腳本程序(build)開始執行" make %install"安裝腳本程序(install)開始執行" make install %clean"建包結束後清理腳本程序(clean)開始執行" %pre"安裝前執行腳本程序(pre)開始執行" %post"安裝後執行腳本程序(post)開始執行" %preun"卸載前執行腳本程序(preun)開始執行" %postun"卸載後執行腳本程序(postun)開始執行" %veryfiscript "軟件包校驗腳本程序(verifyscript)開始執行" %triggerin -- xiuwu"軟件包安裝時觸發腳本程序(triggerin)開始執行" %triggerun -- yuntaishan < 2.0 "軟件包卸載前觸發腳本程序(triggerun)開始執行" %triggerpostun – dapubu"軟件包卸載後觸發腳本程序(triggerpostun)開始執行" %files %defattr (-,root,root) %config /etc/funkey.def %doc %changelog更改日誌 |
四、實例說明
4.1、Nginx 實例爲例
# %define nginx_home %{_localstatedir}/cache/nginx %define nginx_user nginx %define nginx_group nginx # 軟件包的內容概要 Summary: high performance web server #軟件包的名稱 Name: nginx #軟件包的版本 Version: 1.2.6 #軟件包的發佈實際版本號 Release: 1%{?dist}.ngx #發行商或者打包組織的信息 Vendor: nginx inc. #軟件的主頁 URL: http://nginx.org/ #源代碼包,可以帶多個source0,source1等源,後面可以用%{source},%{source1}引用 Source0: http://nginx.org/download/%{name}-%{version}.tar.gz Source1: logrotate Source2: nginx.init Source3: nginx.sysconf Source4: nginx.conf Source5: nginx.vh.default.conf Source6: nginx.vh.example_ssl.conf Source7: nginx.suse.init #軟件授權方式 License: 2-clause BSD-like license %if 0%{?suse_version} #軟件分組 Group: Productivity/Networking/Web/Servers %else Group: System Environment/Daemons %endif #安裝或者編譯時使用的“虛擬目錄” BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root #需要依賴的軟件包 BuildRequires: zlib-devel BuildRequires: pcre-devel BuildRequires: perl %if 0%{?suse_version} BuildRequires: libopenssl-devel Requires(pre): pwdutils %else BuildRequires: openssl-devel Requires: initscripts >= 8.36 Requires(pre): shadow-utils Requires(post): chkconfig %endif #指明本軟件一些特定的功能,以便與其他rpm識別 Provides: webserver #軟件的詳細說明 %description nginx [engine x] is a HTTP and reverse proxy server, as well as a mail proxy server %package debug Summary: debug version of nginx Group: System Environment/Daemons Requires: nginx %description debug not stripped version of nginx build with the debugging log support #預處理腳本 %prep %setup -q #開始構建包 %build ./configure \ --prefix=%{_sysconfdir}/nginx/ \ --sbin-path=%{_sbindir}/nginx \ --conf-path=%{_sysconfdir}/nginx/nginx.conf \ --error-log-path=%{_localstatedir}/log/nginx/error.log \ --http-log-path=%{_localstatedir}/log/nginx/access.log \ --pid-path=%{_localstatedir}/run/nginx.pid \ --lock-path=%{_localstatedir}/run/nginx.lock \ --http-client-body-temp-path=%{_localstatedir}/cache/nginx/client_temp \ --http-proxy-temp-path=%{_localstatedir}/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=%{_localstatedir}/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=%{_localstatedir}/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=%{_localstatedir}/cache/nginx/scgi_temp \ --user=%{nginx_user} \ --group=%{nginx_group} \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_sub_module \ --with-http_dav_module \ --with-http_gzip_static_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_stub_status_module \ --with-mail \ --with-mail_ssl_module \ --with-file-aio \ --with-debug \ --with-cc-opt="%{optflags} $(pcre-config --cflags)" \ $* make %{?_smp_mflags} %{__mv} %{_builddir}/%{name}-%{version}/objs/nginx \ %{_builddir}/%{name}-%{version}/objs/nginx.debug ./configure \ --prefix=%{_sysconfdir}/nginx/ \ --sbin-path=%{_sbindir}/nginx \ --conf-path=%{_sysconfdir}/nginx/nginx.conf \ --error-log-path=%{_localstatedir}/log/nginx/error.log \ --http-log-path=%{_localstatedir}/log/nginx/access.log \ --pid-path=%{_localstatedir}/run/nginx.pid \ --lock-path=%{_localstatedir}/run/nginx.lock \ --http-client-body-temp-path=%{_localstatedir}/cache/nginx/client_temp \ --http-proxy-temp-path=%{_localstatedir}/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=%{_localstatedir}/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=%{_localstatedir}/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=%{_localstatedir}/cache/nginx/scgi_temp \ --user=%{nginx_user} \ --group=%{nginx_group} \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_sub_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gzip_static_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_stub_status_module \ --with-mail \ --with-mail_ssl_module \ --with-file-aio \ --with-ipv6 \ --with-cc-opt="%{optflags} $(pcre-config --cflags)" \ $* make %{?_smp_mflags} #開手機把軟件安裝到虛擬的根目錄中 %install %{__rm} -rf $RPM_BUILD_ROOT %{__make} DESTDIR=$RPM_BUILD_ROOT install %{__mkdir} -p $RPM_BUILD_ROOT%{_datadir}/nginx %{__mv} $RPM_BUILD_ROOT%{_sysconfdir}/nginx/html $RPM_BUILD_ROOT%{_datadir}/nginx/ %{__rm} -f $RPM_BUILD_ROOT%{_sysconfdir}/nginx/*.default %{__rm} -f $RPM_BUILD_ROOT%{_sysconfdir}/nginx/fastcgi.conf %{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/log/nginx %{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/run/nginx %{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/cache/nginx %{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/nginx/conf.d %{__rm} $RPM_BUILD_ROOT%{_sysconfdir}/nginx/nginx.conf %{__install} -m 644 -p %{SOURCE4} \ $RPM_BUILD_ROOT%{_sysconfdir}/nginx/nginx.conf %{__install} -m 644 -p %{SOURCE5} \ $RPM_BUILD_ROOT%{_sysconfdir}/nginx/conf.d/default.conf %{__install} -m 644 -p %{SOURCE6} \ $RPM_BUILD_ROOT%{_sysconfdir}/nginx/conf.d/example_ssl.conf %{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig %{__install} -m 644 -p %{SOURCE3} \ $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/nginx # install SYSV init stuff %{__mkdir} -p $RPM_BUILD_ROOT%{_initrddir} %if 0%{?suse_version} %{__install} -m755 %{SOURCE7} \ $RPM_BUILD_ROOT%{_initrddir}/nginx %else %{__install} -m755 %{SOURCE2} \ $RPM_BUILD_ROOT%{_initrddir}/nginx %endif # install log rotation stuff %{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d %{__install} -m 644 -p %{SOURCE1} \ $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/nginx %{__install} -m644 %{_builddir}/%{name}-%{version}/objs/nginx.debug \ $RPM_BUILD_ROOT%{_sbindir}/nginx.debug #清理臨時文件 %clean %{__rm} -rf $RPM_BUILD_ROOT #定義哪些文件或者目錄會放入rpm中 %files %defattr(-,root,root) %{_sbindir}/nginx %dir %{_sysconfdir}/nginx %dir %{_sysconfdir}/nginx/conf.d %config(noreplace) %{_sysconfdir}/nginx/nginx.conf %config(noreplace) %{_sysconfdir}/nginx/conf.d/default.conf %config(noreplace) %{_sysconfdir}/nginx/conf.d/example_ssl.conf %config(noreplace) %{_sysconfdir}/nginx/mime.types %config(noreplace) %{_sysconfdir}/nginx/fastcgi_params %config(noreplace) %{_sysconfdir}/nginx/scgi_params %config(noreplace) %{_sysconfdir}/nginx/uwsgi_params %config(noreplace) %{_sysconfdir}/nginx/koi-utf %config(noreplace) %{_sysconfdir}/nginx/koi-win %config(noreplace) %{_sysconfdir}/nginx/win-utf %config(noreplace) %{_sysconfdir}/logrotate.d/nginx %config(noreplace) %{_sysconfdir}/sysconfig/nginx %{_initrddir}/nginx %dir %{_datadir}/nginx %dir %{_datadir}/nginx/html %{_datadir}/nginx/html/* %attr(0755,root,root) %dir %{_localstatedir}/cache/nginx %attr(0755,root,root) %dir %{_localstatedir}/log/nginx %files debug #%attr(權限,屬主,屬組) %attr(0755,root,root) %{_sbindir}/nginx.debug #rpm安裝前執行的腳本 %pre # Add the "nginx" user getent group %{nginx_group} >/dev/null || groupadd -r %{nginx_group} getent passwd %{nginx_user} >/dev/null || \ useradd -r -g %{nginx_group} -s /sbin/nologin \ -d %{nginx_home} -c "nginx user"%{nginx_user} exit 0 #rpm安裝後執行的腳本 %post # Register the nginx service if [ $1 -eq 1 ]; then /sbin/chkconfig --add nginx # print site info cat <<BANNER --------------------------------------------------------------------- Thanks for using NGINX! Check out our community web site: * http://nginx.org/en/support.html If you have questions about commercial support for NGINX please visit: * http://www.nginx.com/support.html -------------------------------------------------------------------- BANNER fi #preunrpm卸載前執行的腳本 %preun #$0代表卸載,$1代表安裝,$2代表升級 if [ $1 -eq 0 ]; then /sbin/service nginx stop > /dev/null 2>&1 /sbin/chkconfig --del nginx fi #postrun 人拼命卸載後執行的腳本 %postun if [ $1 -ge 1 ]; then /sbin/service nginx upgrade &>/dev/null || : fi #變更日誌 %changelog * Tue Dec 11 2012 Sergey Budnevitch <[email protected]> - 1.2.6 |
4.2、實例分解說明
4.2.1、定義變量
%define nginx_home %{_localstatedir}/cache/nginx %define nginx_user nginx %define nginx_group nginx |
4.2.2、軟件包的內容概要描述
Summary: high performance web server |
4.2.3、軟件包的名稱
後面可使用%{name}的方式引用,具體命令需跟源包一致
Name: nginx |
4.2.4、軟件的實際版本號
具體命令需跟源包一致
Version: 1.2.6 |
4.2.5、軟件包的發佈實際版本號
Release: 1%{?dist}.ngx |
4.2.6、發行商或者打包組織的信息
Vendor: nginx inc. |
4.2.7、軟件的主頁
URL: http://nginx.org/ |
4.2.8、源代碼包
可以帶多個source0,source1等源,後面可以用%{SOURCE0},%{SOURCE1}引用
Source0: http://nginx.org/download/%{name}-%{version}.tar.gz Source1: logrotate Source2: nginx.init Source3: nginx.sysconf Source4: nginx.conf Source5: nginx.vh.default.conf Source6: nginx.vh.example_ssl.conf Source7: nginx.suse.init Source8: nginx.vh.example.conf |
4.2.9、軟件授權方式
License: 2-clause BSD-like license %if 0%{?suse_version} |
4.2.10、軟件分組
Group: Productivity/Networking/Web/Servers %else Group: System Environment/Daemons %endif |
4.2.11、安裝或者編譯時使用的“虛擬目錄
考慮到多用戶的環境,一般定義爲
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root |
該參數非常重要,因爲在生成rpm的過程中,執行make install時就會把軟件安裝到上述的路徑中,在打包的時候,同樣依賴“虛擬目錄”爲“根目錄”進行操作。
後面可使用$RPM_BUILD_ROOT 方式引用。
4.2.12、需要依賴的軟件包
BuildRequires: zlib-devel BuildRequires: pcre-devel BuildRequires: perl %if 0%{?suse_version} BuildRequires: libopenssl-devel Requires(pre): pwdutils %else BuildRequires: openssl-devel Requires: initscripts >= 8.36 Requires(pre): shadow-utils Requires(post): chkconfig %endif |
4.3.13、指明本軟件一些特定的功能,以便與其他rpm識別
Provides: webserver |
4.3.14、軟件的描述信息明
%description nginx [engine x] is a HTTP and reverse proxy server, as well as a mail proxy server %package debug Summary: debug version of nginx Group: System Environment/Daemons Requires: nginx %description debug not stripped version of nginx build with the debugging log support |
4.3.15、預處理腳本
%prep |
#該段內容爲安裝前腳本程序。它在軟件包安裝之前執行,通常是檢測操作環境,建立有關目錄,清理多餘文件等等,爲軟件包的順利安裝做準備。本段很少使用,其段名格式爲: %pre [子包選項]
4.3.16、解壓源碼
%setup -q |
4.3.17、打補丁
%patch |
此宏利用系統中的patch命令,來給指定的源程序包打補丁,從而將程序升級。其使用格式爲:
%patch [-P N] [-p N] [-b name] [-E] |
注: []所括爲可選項
(1) 當沒有任何選項時:
沒有任何選項時,該宏使用的是默認的補丁文件(第0個補丁文件),即由文件頭Patch或Patch0域所定義的文件
patch命令用了兩個選項:(有關patch命令用法,詳見其用戶手冊)
* -p :這個選項用於確定patch所要操作的文件。它針對補丁文件頭部的文件名,刪除名字中指定數目個
斜槓(/)前面的所有字符,從而得到要操作的文件名。
* -s :這個選項指示patch在打補丁過程中不輸出任何信息,即使有錯誤發生。
(2) -P N :
使用此選項以指示RPM使用第N個補丁文件(由文件頭PatchN域定義)。
(3) -p N :
此選項與其參數是由%patch宏直接傳給patch命令的。請參見上面patch命令所用的-p選項的介紹。
(4) -b name :
當有多個patch命令操作同一個文件時,patch會將原文件換名保存(其後綴變作.orig)
(5) -E :
此選項直接傳給patch命令,其作用是:如果一個文件打完補丁後內容爲空(字節數爲0),則刪除這個文件。
4.3.18、開始構建包
%build |
此 爲編譯段,其內容爲編譯腳本程序。該程序完成源程序的編譯和連接。一個最簡單的例子就是程序中僅有一個make命令。這適用於大部分情況,因爲多數軟件均 有自己的makefile,這樣通過make命令就可實現編譯與連接。如果沒有makefile的話,需要軟件包製作者自己在編譯段書寫上一系列的編譯連 接命令。
./configure \ --prefix=%{_sysconfdir}/nginx/ \ --sbin-path=%{_sbindir}/nginx \ --conf-path=%{_sysconfdir}/nginx/nginx.conf \ --error-log-path=%{_localstatedir}/log/nginx/error.log \ --http-log-path=%{_localstatedir}/log/nginx/access.log \ --pid-path=%{_localstatedir}/run/nginx.pid \ --lock-path=%{_localstatedir}/run/nginx.lock \ --http-client-body-temp-path=%{_localstatedir}/cache/nginx/client_temp \ --http-proxy-temp-path=%{_localstatedir}/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=%{_localstatedir}/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=%{_localstatedir}/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=%{_localstatedir}/cache/nginx/scgi_temp \ --user=%{nginx_user} \ --group=%{nginx_group} \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_sub_module \ --with-http_dav_module \ --with-http_gzip_static_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_stub_status_module \ --with-mail \ --with-mail_ssl_module \ --with-file-aio \ --with-ipv6 \ --with-debug \ --with-cc-opt="%{optflags} $(pcre-config --cflags)" \ $* make %{?_smp_mflags} %{__mv} %{_builddir}/%{name}-%{version}/objs/nginx \ %{_builddir}/%{name}-%{version}/objs/nginx.debug ./configure \ --prefix=%{_sysconfdir}/nginx/ \ --sbin-path=%{_sbindir}/nginx \ --conf-path=%{_sysconfdir}/nginx/nginx.conf \ --error-log-path=%{_localstatedir}/log/nginx/error.log \ --http-log-path=%{_localstatedir}/log/nginx/access.log \ --pid-path=%{_localstatedir}/run/nginx.pid \ --lock-path=%{_localstatedir}/run/nginx.lock \ --http-client-body-temp-path=%{_localstatedir}/cache/nginx/client_temp \ --http-proxy-temp-path=%{_localstatedir}/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=%{_localstatedir}/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=%{_localstatedir}/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=%{_localstatedir}/cache/nginx/scgi_temp \ --user=%{nginx_user} \ --group=%{nginx_group} \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_sub_module \ --with-http_gzip_static_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_stub_status_module \ --with-file-aio \ --with-ipv6 \ --with-cc-opt="%{optflags} $(pcre-config --cflags)" \ $* make %{?_smp_mflags} |
4.3.19、把軟件安裝到虛擬的根目錄中
%install |
此 爲安裝段,其內容是安裝腳本程序。該程序將已編譯連接好的執行程序或其它文件存放到指定目錄下,這些程序或文件供RPM打包時使用。一個最簡單的例子就是 程序中僅用一個make install命令,從而完成安裝。這也需要相應的軟件有makefile維護文件。沒有的話,軟件包製作者也得自己寫指令。
%{__rm} -rf $RPM_BUILD_ROOT %{__make} DESTDIR=$RPM_BUILD_ROOT install %{__mkdir} -p $RPM_BUILD_ROOT%{_datadir}/nginx %{__mv} $RPM_BUILD_ROOT%{_sysconfdir}/nginx/html $RPM_BUILD_ROOT%{_datadir}/nginx/ %{__rm} -f $RPM_BUILD_ROOT%{_sysconfdir}/nginx/*.default %{__rm} -f $RPM_BUILD_ROOT%{_sysconfdir}/nginx/fastcgi.conf %{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/log/nginx %{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/run/nginx %{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/cache/nginx %{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/nginx/conf.d %{__rm} $RPM_BUILD_ROOT%{_sysconfdir}/nginx/nginx.conf %{__install} -m 644 -p %{SOURCE4} \ $RPM_BUILD_ROOT%{_sysconfdir}/nginx/nginx.conf %{__install} -m 644 -p %{SOURCE5} \ $RPM_BUILD_ROOT%{_sysconfdir}/nginx/conf.d/example.txt %{__install} -m 644 -p %{SOURCE6} \ $RPM_BUILD_ROOT%{_sysconfdir}/nginx/conf.d/example_ssl.conf %{__install} -m 644 -p %{SOURCE8} \ $RPM_BUILD_ROOT%{_sysconfdir}/nginx/conf.d/example.conf %{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig %{__install} -m 644 -p %{SOURCE3} \ $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/nginx # install SYSV init stuff %{__mkdir} -p $RPM_BUILD_ROOT%{_initrddir} %if 0%{?suse_version} %{__install} -m755 %{SOURCE7} \ $RPM_BUILD_ROOT%{_initrddir}/nginx %else %{__install} -m755 %{SOURCE2} \ $RPM_BUILD_ROOT%{_initrddir}/nginx %endif # install log rotation stuff %{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d %{__install} -m 644 -p %{SOURCE1} \ $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/nginx %{__install} -m644 %{_builddir}/%{name}-%{version}/objs/nginx.debug \ $RPM_BUILD_ROOT%{_sbindir}/nginx.debug |
4.3.20、清理臨時文件
%clean %{__rm} -rf $RPM_BUILD_ROOT |
4.3.21、定義哪些文件或者目錄會放入rpm中
%files %defattr(-,root,root) %{_sbindir}/nginx %dir %{_sysconfdir}/nginx %dir %{_sysconfdir}/nginx/conf.d %config(noreplace) %{_sysconfdir}/nginx/nginx.conf #%config(noreplace) %{_sysconfdir}/nginx/conf.d/default.conf %config(noreplace) %{_sysconfdir}/nginx/conf.d/example.conf %config(noreplace) %{_sysconfdir}/nginx/conf.d/example_ssl.conf %config(noreplace) %{_sysconfdir}/nginx/conf.d/example.txt %config(noreplace) %{_sysconfdir}/nginx/mime.types %config(noreplace) %{_sysconfdir}/nginx/fastcgi_params %config(noreplace) %{_sysconfdir}/nginx/scgi_params %config(noreplace) %{_sysconfdir}/nginx/uwsgi_params %config(noreplace) %{_sysconfdir}/nginx/koi-utf %config(noreplace) %{_sysconfdir}/nginx/koi-win %config(noreplace) %{_sysconfdir}/nginx/win-utf %config(noreplace) %{_sysconfdir}/logrotate.d/nginx %config(noreplace) %{_sysconfdir}/sysconfig/nginx %{_initrddir}/nginx %dir %{_datadir}/nginx %dir %{_datadir}/nginx/html %{_datadir}/nginx/html/* %attr(0755,root,root) %dir %{_localstatedir}/cache/nginx %attr(0755,root,root) %dir %{_localstatedir}/log/nginx %files debug |
4.3.22、設置權限
#%attr(權限,屬主,屬組) %attr(0755,root,root) %{_sbindir}/nginx.debug |
4.3.23、安裝前後執行動作
#rpm安裝前執行的腳本
%pre # Add the "nginx" user getent group %{nginx_group} >/dev/null || groupadd -r %{nginx_group} getent passwd %{nginx_user} >/dev/null || \ useradd -r -g %{nginx_group} -s /sbin/nologin \ -d %{nginx_home} -c "nginx user"%{nginx_user} exit 0 |
4.3.24、#rpm安裝後執行的腳本
%post |
該段內容爲安裝後腳本程序。它在軟件包安裝完成之後執行,常用來建立符號連接,修改系統配置文件,運行ldconfig程序等,以利軟件的正常運
#preunrpm卸載前執行的腳本
[ -d "/opt/web/www" ] [ "$?" != "0" ]&& mkdir -p /opt/web/www # Register the nginx service if [ $1 -eq 1 ]; then /sbin/chkconfig nginx on /sbin/service nginx start #ngpassword is a tool for nginx to create password cat >/usr/sbin/ngpassword <<EOF #!/usr/bin/perl use strict; my \$pw=\$ARGV[0] ; print crypt(\$pw,\$pw)."\n"; EOF chmod 755 /usr/sbin/ngpassword fi |
%preun |
#$1代表動作
0代表卸載
1代表安裝
2代表升級
if [ $1 -eq 0 ]; then /sbin/service nginx stop > /dev/null 2>&1 /sbin/chkconfig --del nginx fi #postrun rpm卸載後執行的腳本 %postun if [ $1 -ge 1 ]; then /sbin/service nginx upgrade &>/dev/null || : fi |
4.2.25、變更日誌
%changelog * Thu Jan 31 2013change config file<[email protected]> - 1.2.6 |
五、rpmbuild命令參數詳解
5.1、rpmbuild 基本格式
rpmbuild [options] [spec文檔|tarball包|源碼包]
[kuangl@test01 SPECS]$ rpmbuild -ba nginx.spec |
5.2、spec文檔建立有以下選項
選項 | 含義 |
-bp | 文件中安裝執行前的地方 |
-bc | 執行spec的%pre和%build 段(準備並編譯) |
-bi | 執行spec中%pre,%build與%install(準備,編譯並安裝) |
-bl | 檢查spec中的%file段(查看文件是否齊全) |
-ba | 建立源碼與二進制包(常用) |
-bb | 只建立二進制包(常用) |
-bs | 只建立源碼包 |
5.3、tarball包建立,與spec類似
選項 | 含義 |
-tp | 對應-bp |
-tc | 對應-bc |
-ti | 對應-bi |
-ta | 對應-ba |
-tb | 對應-bb |
-ts | 對應-bs |
5.4、從源碼包建立
選項 | 含義 |
--rebuild | 建立二進制包,通-bb |
其他的一些選項
選項 | 含義 |
--buildroot=DIRECTORY | 確定以root目錄建立包 |
--clean | 完成打包後清除BUILD下的文件目錄 |
--nobuild | 不進行%build的階段 |
--nodeps | 不檢查建立包時的關聯文件 |
--rmsource | 完成打包後清除SOURCES |
--rmspec | 完成打包後清除SPEC |
--target=CPU-VENDOR-OS | 確定包的最終使用平臺 |