1

I need advice about the following

I build simple spec file and build rpm

I transfer the new rpm to other Linux machine in order to install the new rpm

according to the spec file the new rpm -> test.sh-6.2-2.i386.rpm should create the /tmp/MY_RPM_TESTS directory , but this rpm not create the MY_RPM_TESTS and sub directories please advice why , what I need to fix in the spec file?

RPM installation:

   [root@linux1 rpm -Uvh  /root/rpmbuild/RPMS/i386/test.sh-6.2-2.i386.rpm
   Preparing...                ########################################### [100%]
   This is preinstall script
   Linux linux 2.6.18-164.2.1.el5PAE #1 SMP Mon Sep 21 04:45:05 EDT 2009 i686 i686 i386 GNU/Linux
   1:test.sh                ########################################### [100%]
   Linux linux 2.6.18-164.2.1.el5PAE #1 SMP Mon Sep 21 04:45:05 EDT 2009 i686 i686 i386 GNU/Linux
   Now we wait for sleep
   100

   [root@linux1 ls /tmp

   preinstall_dir

my SPEC file:

  root@linux /usr/src/redhat/SPECS]# more my_spec.spec
  Summary: An example tool. To show a simple rpm build of the tool.
  Name: test.sh
  Version: 6.2
  Release: 2
  Source0: /root/test.sh 
  Source1: /root/urim.sh
  Group: Development/Debuggers
  BuildRoot:/tmp/MY_RPM_TESTS
  License: OtherLicense
  %description


  %pre -p /bin/ksh
  print "This is preinstall script"
  uname -a
  rm -rf /tmp/preinstall_dir
  mkdir /tmp/preinstall_dir

  %install
  rm -rf %{buildroot}

  mkdir -p %{buildroot}
  mkdir -p %{buildroot}/home
  mkdir -p %{buildroot}/home/home1

  cp %SOURCE0 %{buildroot}/home
  cp %SOURCE0 %{buildroot}/home/home1

  cp %SOURCE1  %{buildroot}/home

  %files
  /home/test.sh
  /home/home1/test.sh
  /home/urim.sh



  %post -p /bin/ksh

  uname -a
  print "Now we wait for sleep" ; sleep  1
  NUM=100
  print $NUM

Build the rpm:

  [root@linux /usr/src/redhat/SPECS]# rpm -ba   /usr/src/redhat/SPECS/my_spec.spec
  Executing(%install): /bin/sh -e /root/rpmbuild/tmp/rpm-tmp.83360
  + umask 022
  + cd /root/rpmbuild/BUILD
  + rm -rf /tmp/MY_RPM_TESTS
  + mkdir -p /tmp/MY_RPM_TESTS
  + mkdir -p /tmp/MY_RPM_TESTS/home
  + mkdir -p /tmp/MY_RPM_TESTS/home/home1
  + cp /root/rpmbuild/SOURCES/test.sh /tmp/MY_RPM_TESTS/home
  + cp /root/rpmbuild/SOURCES/test.sh /tmp/MY_RPM_TESTS/home/home1
  + cp /root/rpmbuild/SOURCES/urim.sh /tmp/MY_RPM_TESTS/home
  + /usr/lib/rpm/brp-compress
  + /usr/lib/rpm/brp-strip
  + /usr/lib/rpm/brp-strip-static-archive
  + /usr/lib/rpm/brp-strip-comment-note
  Processing files: test.sh-6.2-2
  Requires(interp): /bin/ksh /bin/ksh
  Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib    (PayloadFilesHavePrefix) <= 4.0-1
  Requires(pre): /bin/ksh
  Requires(post): /bin/ksh
  Checking for unpackaged file(s): /usr/lib/rpm/check-files /tmp/MY_RPM_TESTS
  Wrote: /root/rpmbuild/SRPMS/test.sh-6.2-2.src.rpm
  Wrote: /root/rpmbuild/RPMS/i386/test.sh-6.2-2.i386.rpm

2 Answers 2

1

[It] should create the /tmp/MY_RPM_TESTS directory...

This is mistaken. The build root is only used when building, and erased afterward, and only files/directories/etc. listed in the %files section will be created.a

3
  • But I already create the /tmp/MY_RPM_TESTS by mkdir -p %{buildroot} what bad with this?
    – yael
    Apr 17, 2011 at 15:56
  • The build root is only used when building, and erased afterward, and only files/directories/etc. listed in the %files section will be created. Apr 17, 2011 at 16:51
  • please add example in order to fix my spec file thx
    – yael
    Apr 17, 2011 at 16:57
1

The %install and %post sections of the specfile are executed in completely different environments. The %install script is only run on your build machine as part of the package build process. The %post script is run on whichever machine you are trying to install the RPM to (the "target machine").

It is not possible or even desired for the target machine to know anything about the build environment that you used on your build machine to create the package. That is why you do not see /tmp/MY_RPM_TESTS being created on the target machine; that folder was created on the build machine during the %install process.

That said, from the looks of that specfile you do not need to create the /tmp/MY_RPM_TESTS folder on the target machine. When you install your RPM, the files should exist in...

/home/test.sh
/home/home1/test.sh
/home/urim.sh

...as defined by your %files section. If you need the scripts to be installed in /tmp/MY_RPM_TESTS, your spec file should look like this:

%install
rm -rf %{buildroot}
mkdir -p %{buildroot}/tmp/MY_RPM_TESTS/home/home1
cp %SOURCE0 %{buildroot}/tmp/MY_RPM_TESTS/home
cp %SOURCE0 %{buildroot}/tmp/MY_RPM_TESTS/home/home1
cp %SOURCE1 %{buildroot}/tmp/MY_RPM_TESTS/home

%files
/tmp/MY_RPM_TESTS/home/test.sh
/tmp/MY_RPM_TESTS/home/home1/test.sh
/tmp/MY_RPM_TESTS/home/urim.sh

By comparing the above with your original spec file, you should be able to see the difference and hopefully better understand how %{buildroot} should be used.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .