My linux world » RPM

RPM


Red Hat Package Manager or RPM Package Manager (RPM) is a package management system. The name RPM variously refers to the .rpm file format, files in this format, software packaged in such files, and the package manager itself. RPM was intended primarily for Linux distributions; the file format is the baseline package format of the Linux Standard Base.

Wikipedia

Objectives

Prerequiste

I assume that you have a Centos installation.

Installation

You can copy/paste this script and use it to configure automatically your server.

  1. #!/bin/bash
  2.  
  3. echo "install rpmdevtools automake autoconf gcc"
  4. dnf -y install rpmdevtools rpmlint automake autoconf gcc make
  5.  
  6. echo "clean rpmbuild directory"
  7. rm ~/rpmbuild/ -fr
  8.  
  9. ##################################################
  10. # EXAMPLE FILE : HELLO WORLD
  11. ##################################################
  12. echo "create build files"
  13. mkdir -p ~/rpmbuild/BUILD/
  14. cat >~/rpmbuild/BUILD/Makefile.am << "EOF"
  15. bin_PROGRAMS=hello
  16. hello_SOURCES=hello.c
  17. EOF
  18.  
  19. cat >~/rpmbuild/BUILD/configure.ac << "EOF"
  20. AC_INIT([hello], [1.0], [bug@libhello.org])
  21. AM_INIT_AUTOMAKE([-Wall -Werror foreign])
  22. AC_PROG_CC
  23. AC_PROG_RANLIB
  24. AC_CONFIG_FILES([Makefile])
  25. AC_OUTPUT
  26. EOF
  27.  
  28. cat >~/rpmbuild/BUILD/hello.c << "EOF"
  29. #include <stdio.h>
  30. int main(int argc, char* argv[])
  31. {
  32. printf("Hello, world!\n");
  33. return 0;
  34. }
  35. EOF
  36.  
  37. # move to ~/rpmbuild/BUILD
  38. echo "move to ~/rpmbuild/BUILD"
  39. cd ~/rpmbuild/BUILD
  40.  
  41. # create macros for automake
  42. aclocal
  43.  
  44. # create Makefile.in from Makefile.am
  45. automake --add-missing --copy
  46.  
  47. # create configure
  48. autoconf
  49.  
  50. ##################################################
  51. # SPEC FILE
  52. ##################################################
  53. echo "create SPECS file"
  54. mkdir -p ~/rpmbuild/SPECS/
  55. cd ~/rpmbuild/SPECS/
  56. rpmdev-newspec hello
  57.  
  58. echo "configure spec file"
  59. sed -i "s/^Version:/Version: 1.0/g" hello.spec
  60. sed -i "s/^Summary:/Summary: My newpackage rocks\!/g" hello.spec
  61. sed -i "s/^Group:/Group: Development\/Tools/g" hello.spec
  62. sed -i "s/^License:/License: GPL/g" hello.spec
  63. sed -i "s/^URL:/URL: http:\/\/mysite\/hello.html/g" hello.spec
  64. sed -i "s/^Source0:/Source0: ./g" hello.spec
  65. sed -i "s/^\(BuildRequires:\)/#\1/g" hello.spec
  66. sed -i "s/^\(Requires:\)/#\1/g" hello.spec
  67. sed "s/^\%description/\%description Desc to say that my newpackage rocks\!/g" hello.spec
  68. sed -i "s/^\(\%prep\)/#\1/g" hello.spec
  69. sed -i "s/^\(\%doc\)/\1\\n\/usr\/bin\/hello/g" hello.spec
  70. sed -i "s/^\(\%changelog\)/\1\\n* Tue May 06 2014 marc rabahi <marc.rabahi@gmail.com> 1.0-1\n- my hello world change log./g" hello.spec
  71.  
  72. ##################################################
  73. # BUILD RPM
  74. ##################################################
  75.  
  76. echo "Check patches and BR":
  77. rpmbuild -bp hello.spec
  78.  
  79. echo "Build":
  80. rpmbuild -bc --short-circuit hello.spec
  81.  
  82. echo "Package %files":
  83. rpmbuild -bi --short-circuit hello.spec
  84.  
  85. echo "Finally build rpm":
  86. rpmbuild -ba hello.spec
  87.  
  88. ##################################################
  89. # CHECK RPM
  90. ##################################################
  91. echo "Now check commons errors in RPM packages (rpm software, sources rpm)"
  92. rpmlint ~/rpmbuild/RPMS/x86_64/hello-1.0-1.el7.centos.x86_64.rpm
  93. rpmlint ~/rpmbuild/SRPMS/hello-1.0-1.el7.centos.src.rpm
  94.  
  95.  

That’s all 🙂


Copyright © 2024 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.