修改、重建和安裝srpm源碼包

來源:互聯網
上載者:User

      RHEL/CentOS/Fedora/Suse等Linux發行版都使用rpm包作為軟體包格式。另外還有一個相關的格式srpm包(尾碼是.src.rpm),它包含了原始碼,可以用它重建rpm包。

      當前最新發行的RHEL/CentOS是6.X版本。目前最新版是RHEL6.5/CentOS6.5。(CentOS是RHEL的免費版本,與RHEL對應版本完全等價,除了去掉了Redhat的LOGO。)

      在如下地址,可以找到RHEL6的所有rpm包的源碼包:*.src.rpm。

http://ftp.redhat.com/redhat/linux/enterprise/6Server/en/os/SRPMS/

      CentOS就是使用這些*src.rpm源碼包構建出所有RPM包,產生CentOS作業系統的。

      *src.rpm源碼包解壓出來後,可以看到有該軟體的原始碼壓縮包和一些patch檔案。

       如果rpm包有問題,我們可以去http://ftp.redhat.com/redhat/linux/enterprise/6Server/en/os/SRPMS/下載對應的src.rpm包,然後把它解開後修改原始碼,重新編譯和產生rpm包,進行分發和安裝。



直接安裝*src.rpm源碼包

       有時,我們沒有找到可用的rpm包,但找到了其對應的*src.rpm源碼包,此時我們可以安裝這個*src.rpm源碼包。步驟與直接安裝rpm包很不相同。

rpm -i /tmp/mypackage-1.0.0-1.src.rpm此時還沒有安裝完成。只是在~/rpmbuild/ 目錄下準備了該src.rpm源碼包的資源,可用於進一步產生rpm包。[user@host ~]$ cd ~/rpmbuild/SPECS[user@host SPECS]$ rpmbuild -ba mypackage.spec

         *src.rpm源碼包的構建,使用的是rpmbuild命令。看一下這個命令的選項。

rpmbuild -bSTAGE|-tSTAGE [ rpmbuild-options]FILE ...



The argument used is -b if a spec file is being used to build the packageand -t if rpmbuild should look inside of a (possibly compressed) tar

file for the spec file to use. After the first argument, the nextcharacter (STAGE) specifies the stages of building and packaging tobe done

andis one of:



-ba Build binary and source packages (after doing the %prep, %build,and %install stages). 構建RPM包和SRPM包。



-bb Build a binary package (after doing the %prep, %build, and%install stages).構建RPM包。

-bp Executes the "%prep" stage from the spec file. Normallythis involves unpacking the sources and applying any patches.

執行spec檔案的%prep階段。一般是解壓源碼和應用源碼到~/rpmbuild/BUILD/目錄下。



-bc Do the "%build" stage from the spec file (after doingthe %prep stage). This generally involves the equivalent of a"make".

執行spec檔案的%build階段,一般是執行make。



-bi Do the "%install" stage from the spec file (after doingthe %prep and %build stages). This generally involves the equivalentof a "make

install".

執行spec檔案的%install階段,一般是執行make install。



-bl Do a "list check". The "%files" section from the spec file is macro expanded, and checks are made to verify that each file exists.

執行spec檔案的%%files階段,一般是執行驗證每一個檔案是否存在。

-bs Build just the source package.

        只構建源碼包。





       上述命令構建了rpm包和src.rpm包。可以在~/rpmbuild/RPMS/x86_64/或者其他架構的目錄下找到新產生的rpm包。

你可以使用sudo  rpm -i *.rpm命令安裝rpm包。



       你也可以直接使用如下命令:

rpmbuild --rebuild /tmp/mypackage-1.0.0-1.src.rpm這個命令一步即可在~/rpmbuild/RPMS/目錄下重建rpm包。



基於*src.rpm源碼包修改代碼後產生rpm包並安裝

          rpmbuild命令基於.spec檔案和源碼tar.gz及patch檔案產生src.rpm和rpm包。

因此,我們只需要修改.spec檔案,或者對應的源碼和patch檔案,然後再執行

rpmbuild -ba mypackage.spec命令,就可以產生更新後的src.rpm包和rpm包。rpm包在~/rpmbuild/RPMS目錄下,src.rpm包在~/rpmbuild/SRPMS目錄下。注意,要修改~/rpmbuild/SOURCES/目錄下的檔案:1,你可以重新打包~/rpmbuild/SOURCES/目錄下的tar.gz源檔案。2,你可以修改.spec檔案,增加或者減少對patch的應用。3,推薦你修改.spec的Release: 8%{?dist}  宏,增加它的數值。  這樣,你產生的rpm包和src.rpm包的小版本號碼就比原始的rpm包要高,從而你可以使用sudo rpm -U ../RPMS/x86_64/bzip2-1.0.5-8.el6.x86_64.rpm     這樣的命令來升級rpm包。如果你不把Release數字改大,則你必須首先卸載已經安裝的rpm包,然後才能重新安裝我們新產生的rpm包。     



修改deb包的方法

      這裡順便講一下另一個Linux上流行的軟體包格式debian包的重新打包方法。     

      dpkg-deb命令可以解壓縮deb包。是的,deb包是一個壓縮檔。正如office文檔,也是壓縮檔。Jar包也是壓縮檔,rpm包也是壓縮檔一樣。

 dpkg-deb --raw-extract   X.deb  X  

    解壓X.deb包到X目錄。

     可以修改X目錄內的檔案。如,替換資源檔,二進位檔案,修改設定檔等。

      

dpkg-deb --build    X [X.deb]

     構建目錄為deb包。  第二個參數可以省略,就是產生  目錄名.deb  格式命名的deb包。


dpkg  -i  X.deb

   命令可以安裝deb包。


deb包內的DEBIAN/control檔案有很多中繼資料,其中:

Architecture:    

一項設定該debian包適用的CPU架構。 常用的有i386,amd64。 使用all 或者any 表示這個deb包適用於任何架構。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.