现在的位置: 首页 > 综合 > 正文

修改、重新生成和安装srpm源码包

2014年04月05日 ⁄ 综合 ⁄ 共 3131字 ⁄ 字号 评论关闭

      RHEL/CentOS/Fedora/SuseLinux发行版都使用rpm包作为软件包格式。另外还有一个相关的格式srpm包(后缀是.src.rpm),它包含了源代码,可以用它重新生成rpm包。

      当前最新发行的RHEL/CentOS6.X版本。目前最新版是RHEL6.5/CentOS6.5。(CentOSRHEL的免费版本,与RHEL对应版本完全等价,除了去掉了RedhatLOGO。)

      在如下地址,可以找到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.gzpatch文件生成src.rpmrpm包。

因此,我们只需要修改.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,推荐你修改.specRelease: 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包适用于任何架构。


抱歉!评论已关闭.