请选择 进入手机版 | 继续访问电脑版
 找回密码
 立即注册
搜索

本文来自

安全运维工具

安全运维工具

人已关注

请添加对本版块的简短描述

精选帖子

Curl RPM with OpenSSL

[复制链接]
981 abc 发表于 2019-4-3 13:30:00
  1. Hello Readers,

  2. With this tutorial, I intend to provide more insight to developers who want to package their own RPM and are starting from scratch. I will provide an overview to .spec file which is the key essential file on generating RPM's so that you can get started really quickly. Just to mention, I did this on CentOS 6.2 virtual machine.

  3. Requirements:
  4. In-order to package RPM's and create an environment to work on this, we will need the following

  5. sudo yum install -y rpm-build  
  6. sudo yum install -y redhat-rpm-config  
  7. sudo yum install -y rpmdevtools rpmlint  
  8. #Post Installation
  9. rpmdev-setuptree  
  10. Process:
  11. This will create the directory rpmbuild in your home path. Inside that directory, we can see multiple folders such as :BUILD, RPMS, SOURCES, SPECS, SRPMS , BUILDROOT*, tmp



  12. In short descriptions, I will explain what each directory contains. BUILD will contain files when your packaging process is in the preparation state. RPMS folder contains the resultant rpm files. SOURCES will contain your tar source file to be used for RPM. There can be multiple source files. SRPMS similarly contains Source RPMS which can be re-packaged to generate different RPMS. I copied my curl-7.50.0.tar.gz
  13. The script which generates the package is the SPEC file and resides in the SPECS directory. Everything is scripted into this file. The various major sections of a spec file are header, installation preparation, build, install, files, post install and clean-up. There are many more, but we would concentrate on these. The spec file is as follows and these 2 files are all that you need to generate your rpm.

  14. [palash@localhost SPECS]$ cat curl.spec
  15. %define name owncurl
  16. %define tarball curl
  17. %define version 7.50.0
  18. %define release 1

  19. %define curlroot %{_builddir}/%{tarball}-%{version}
  20. %define curlprefix /opt/owncurl

  21. Summary: get a file from an FTP or HTTP server.  
  22. Name: %{name}  
  23. Version: %{version}  
  24. License: MIT  
  25. Release: %{release}  
  26. Vendor: Daniel Stenberg <Daniel.Stenberg@haxx.se>  
  27. Packager: Troy Engel <tengel@sonic.net>  
  28. Group: Utilities/Console  
  29. Source: %{tarball}-%{version}.tar.gz  
  30. URL: http://curl.haxx.se/  
  31. BuildRoot: %{_tmppath}/%{tarball}-%{version}-root  
  32. Requires: libssh2  
  33. AutoReqProv: no


  34. %description
  35. curl is a client to get documents/files from servers, using any of the  
  36. supported protocols. The command is designed to work without user  
  37. interaction or any kind of interactivity.

  38. curl offers a busload of useful tricks like proxy support, user  
  39. authentication, ftp upload, HTTP post, file transfer resume and more.

  40. %package    devel
  41. Summary:    The includes, libs, and man pages to develop with libcurl  
  42. Group:        Development/Libraries  
  43. Provides:    curl-devel  
  44. AutoReqProv: no


  45. %description devel
  46. libcurl is the core engine of curl; this packages contains all the libs,  
  47. headers, and manual pages to develop applications using libcurl.

  48. %prep

  49. %setup -q -n %{tarball}-%{version}

  50. %build
  51. cd %{curlroot} && (if [ -f configure.in ]; then mv -f configure.in configure.in.rpm; fi)

  52. %define CONFIG_FLAGS --prefix=%{curlprefix} --with-ssl=/opt/alt-openssl/ --enable-http --enable-ftp
  53. %define LDFLAGS -L/opt/alt-openssl/lib
  54. %define CPP_FLAGS -I/opt/alt-openssl/include
  55. %define SSL_LDFLAGS -L/opt/alt-openssl/lib
  56. %define SSL_CPPFLAGS -I/opt/alt-openssl/include

  57. ./configure  %{CONFIG_FLAGS}

  58. cd %{curlroot} && (if [ -f configure.in.rpm ]; then mv -f configure.in.rpm configure.in; fi)  
  59. make

  60. %install
  61. [ "%{buildroot}" != "/" ] && rm -rf %{buildroot}
  62. make DESTDIR=%{buildroot} install-strip

  63. %clean
  64. [ "%{buildroot}" != "/" ] && rm -rf %{buildroot}
  65. [ "%{curlroot}" != "/" ] && rm -rf %{curlroot}

  66. %post
  67. /sbin/ldconfig

  68. %postun
  69. /sbin/ldconfig

  70. %files
  71. %defattr(-,root,root)
  72. %attr(0755,root,root) %{curlprefix}/bin/curl
  73. %attr(0644,root,root) %{curlprefix}/share/man/man1/curl.1*
  74. %{curlprefix}/lib/libcurl.so*
  75. %{curlprefix}/lib/pkgconfig/libcurl.pc*
  76. %{curlprefix}/lib/libcurl.so*
  77. %{curlprefix}/share/aclocal/libcurl.m4
  78. #%{_datadir}/curl/curl-ca-bundle.crt
  79. %doc CHANGES COPYING README docs/BUGS docs/SSLCERTS
  80. %doc docs/CONTRIBUTE docs/FAQ docs/FEATURES docs/HISTORY docs/INSTALL
  81. %doc docs/KNOWN_BUGS docs/MANUAL docs/RESOURCES docs/THANKS
  82. %doc docs/TODO docs/VERSIONS docs/TheArtOfHttpScripting tests

  83. %files devel
  84. %defattr(-,root,root)
  85. %attr(0755,root,root) %{curlprefix}/bin/curl-config
  86. %attr(0644,root,root) %{curlprefix}/share/man/man1/curl-config.1*
  87. %attr(0644,root,root) %{curlprefix}/share/man/man3/*
  88. %attr(0644,root,root) %{curlprefix}/include/curl/*
  89. %{curlprefix}/lib/libcurl.a
  90. %{curlprefix}/lib/libcurl.la
  91. %doc docs/BINDINGS docs/INTERNALS docs/examples/*
  92. [palash@localhost ~]$
  93. Generate the RPM:
  94. To generate the RPM, all you have to do is run and it will generate the rpm package

  95. rpmbuild -ba

  96. The SPEC file, explained:
  97. The %prep section will un-tar the archive file in the BUILD directory. I have named the package Owncurl so that it does not conflict with the native curl on the system. The %setup will switch the working directory for %build to the directory where the files are extracted. If the folder is of a different name, than your package, then you need to pass the -n parameter. In the %build portion of the spec file, we have configured curl to pick up the native installation of openssl. The %install code decides the directories which this code will be installed into post building. And similarly %files section lists all the files to be packaged in the RPM. Make sure that you push in all the files in your buildroot to the %files  section to avoid errors.
  98. Thanks for reading! For any doubts or clarifications, feel free to drop me an email.
复制代码


回复

使用道具 举报

 楼主| abc 发表于 2019-4-3 13:30:25
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表