RPM包的构建

  1. 创建文件夹helloworld,用于存放编写的程序代码

    mkdir ~/helloworld

  2. 编写程序代码

    helloworld.c

    #include <stdio.h>

    int main(void)

    {

    1. printf(“Hello, world !/n”);

      return 0;

      }


  1. Makefile

    all:

    1. gcc -o helloworld helloworld.c

         fresh:

                    rm -rf Makefile

        clean:

                   rm -rf helloworld helloworld.o

        install:

                  cp helloworld /usr/bin

        uninstall:

                  rm -rf /usr/bin/helloworld


       readme

       author: sam shen

       description: this is the first program for testing rpm build

  1. 复制~/helloworld文件夹到/usr/src/redhat/SOURCES

    cp -R ~/helloworld /usr/src/redhat/SOURCES

  2. 压缩源码

    cd /usr/src/redhat/SOURCES

    tar -zcvf helloworld-0.1-1.tar.gz helloworld

  3. 编写spec文件

    cd /usr/src/redhat/SPECS

    编写helloworld-0.1-1.spec,内容如下:

    Summary: the First RPM of sam

    Name:helloworld

    Version:0.1

    Release:1

    Vendor:Sam Shen (sxc_1985921@126.com)

    License:Share

    Group:Applications/Text

    Source0:helloworld-0.1-1.tar.gz

    #Patch0:helloworld-0.1-1.patch

    %description

    My test helloworld

    %prep

    export RPM_SOURCES_DIR=/usr/src/redhat/SOURCES

    export RPM_BUILD_DIR=/usr/src/redhat/BUILD

    tar -xvf $RPM_SOURCES_DIR/helloworld-0.1-1.tar.gz

    #%patch

    %build

    cd $RPM_BUILD_DIR/helloworld

    make

    %install

    cd $RPM_BUILD_DIR/helloworld

    make install

    %clean

    rm -rf $RPM_BUILD_DIR/helloworld

    %files

    %defattr(-,root,root)

    /usr/bin/helloworld

    %doc

    /usr/src/redhat/BUILD/helloworld/readme

    %changelog

    * Tue Sep 2 2008 Sam Shen sxc_1985921@126.com

    - sam test it

  4. 打包,在/usr/src/redhat/SPEC目录下执行如下命令:

    rpmbuild -ba helloworld-0.1-1.spec

    后在/usr/src/redhat/RPMS/i386目录下产生helloworld-0.1-1.i386.rpm,在/usr/src/redhat/SRPMS目录下产生helloworld-0.1-1.src.rpm

    此时,在终端运行helloworld将输出:Hello, world !

  5. 修改源程序,进行源程序更新

    cd /usr/src/redhat/SOURCES/

    mkdir helloworld2

    cd helloworld2

    cp ../helloworld/* ./

    vim helloworld.c

    在第一个prinf语句后加上printf(“This is a simple program for testing rpm build/n”);

    vim readme

    在末尾加上you can input helloworld in terminal , and you can see what happened

    回到上级目录

    cd /usr/src/redhat/SOURCES

    diff -uNr helloworld helloworld2 > helloworld-0.1-1.patch

    上条命令将产生一个patch文件helloworld-0.1-1.patch

    现在回头把Patch0%patch前面的注释去掉

  6. 重新生成RPM包,观察变化

    rpmbuild -bb helloworld-0.1-1.spec (只生成二进制格式的rpm),或

    rpmbuild -bs helloworld-0.1-1.spec (只生成src格式的rpm),或

    rpmbuild -bp helloworld-0.1-1.spec (只需要生成完整的源文件,存在BUILD目录下,它的作用就是把tar包解开然后把所有的补丁文件合并而生成一个完整的最新功能的源文件),或

    rpmbuild -ba helloworld-0.1-1.spec (产生以上3个过程分别生成的包)

    rpmbuild -bc helloworld-0.1-1.spec Build (compile) the program but do not make the full RPM, stopping just after the %build section

    rpmbuild -bi helloworld-0.1-1.spec Create a binary RPM and stop just after the %install section

    rpmbuild -bl helloworld-0.1-1.spec Check the listing of files for the RPM and generate errors if the buildroot is missing any of the files to be installed

    此时,在终端运行helloworld将输出:

    Hello, world !

    This is a simple program for testing rpm build

  7. 检查gpg软件是否安装

    rpm -qf `which gpg`

    显示gnupg-1.4.7-7类似的名称,则已经安装

  8. 配置一个签名

    gpg –gen-key

    按照提示回答问题

  9. 建立RPM宏文件/home/sam/.rpmmacros

    %_signature gpg

    %_gpg_path /home/sam/.gnupg

    %_gpg_name shen xiao cheng (sam shen) <sxc_1985921@126.com>

    %_gpgbin /usr/bin/gpg

  10. RPM包签名

    rpm --addsign helloworld-0.1-1.i386.rpm

    或者在打包时加上--sign选项,如:

    rpmbuild -ba --sign helloworld-0.1-1.spec

  11. 也可以从src.rpm打成platform.rpm

    src.rpm.spec文件放在一个文件夹下

    rpm -ivh helloworld-0.1-1.src.rpm

    查看安装到哪里:

    locate helloworld

    rpm -ba helloworld-0.1-1.spec



RPM命令

  1. 查询系统中已经安装的软件

    rpm -q softname

  2. 查看系统中所有已经安装的包

    rpm -qa

  3. 查询已经安装的软件包都安装都何处

    rpm -ql softname

  4. 查看一下已经安装软件的配置文件

    rpm -qc softname

  5. 查看一个已经安装软件的文档安装位置

    rpm -qd softname

  6. 查看一下已经安装软件所依赖的软件包及文件

    rpm -qR softname

  7. 查看一个已安装文件属于哪个包

    rpm -qf file

  8. 查看一个已安装软件包的信息

    rpm -qi softname

  9. 查看当前目录下软件的信息

    rpm -qpi name-version-release.platform.rpm

  10. 查看当前目录下软件包将会在系统中安装那些部分

    rpm -qpl name-version-release.platform.rpm

  11. 查看软件包的文档所在的位置

    rpm -qpd name-version-release.platform.rpm

  12. 查看一个软件包的配置文件

    rpm -qpc name-version-release.platform.rpm

  13. 查看一个软件包的依赖关系

    rpm -qpR name-verseion-release.platform.rpm

  14. 安装软件

    rpm -ivh name-version-release.platform.rpm

  15. 如果在安装过程中提示此软件已安装过或因其他原因无法继续安装,但确实要执行安装命令

    rpm -ivh -replacepkgs name-version-release.platform.rpm

  16. 在线安装

    rpm -i serveraddress/name-version-release.platform.rpm

  17. 卸载软件

    rpm -e filename

  18. 升级软件

    rpm -uvh filename

  19. 判定某个文件属于哪个软件包

    rpm -qf file

  20. 导入签名

    rpm --import RPM-GPG-KEY

  21. 更新软件包数据库

    updatedb

  22. 查询软件安装的位置

    locate softname

  23. rpm软件包中抽取文件

    rpm2cpio name-version-release.platform.rpm | cpio -idmv

  24. 只生成二进制格式的rpm

    rpmbuild -bb helloworld-0.1-1.spec

  25. 只生成src格式的rpm

    rpmbuild -bs helloworld-0.1-1.spec

  26. 只需要生成完整的源文件,存在BUILD目录下,它的作用就是把tar包解开然后把所有的补丁文件合并而生成一个完整的最新功能的源文件 rpmbuild -bp helloworld-0.1-1.spec

  27. 产生以上3个过程分别生成的包

    rpmbuild -ba helloworld-0.1-1.spec

  28. rpm包管理的配置文件

    locate rpmrc

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值