6

Looking for someone to just clarify the %install macro when it comes to just placing files. I created a RPM without errors that is supposed to just take files from the buildroot and cp them to /usr/lib. What I have in the SPEC file for the %install is the following, and based on this post. I though that would be enough for the rpm to copy the files from the buildroot to the /usr/lib location.

This is what I tried and it builds:

%install
mkdir -p %{buildroot}/usr/lib
install -d %{buildroot}/usr/lib/

Rethinking, I figure, well lets tell the rpm where I want to copy the files. SO I tried this:

%install
mkdir -p %{buildroot}/usr/lib
cp %{buildroot}/usr/lib/ /usr/lib/

well that complains about the /usr/lib/ location not being writable by the user I am creating the rpm as on the build machine. Which my impression is that %install section of the spec file should be instructions on where the files should be copied to when the rpm is installed on the destination server. I don't want it looking at the local files system for the rpm build server. My though behind this is, the RPM should build, but it shouldn't fail until the rpm install if I try to install the rpm as a non-privileged user. It shouldn't care during the build. I'm merely trying to cp/extract some lib files to the /usr/lib on the server I install the rpm on.

My assumption is, the rpm would create the BUILDROOT location on the server I'm installing the rpm on, then cp the contents from the buildroot location to the mentioned destination location.

Community
  • 1
  • 1
H-man
  • 163
  • 1
  • 2
  • 12
  • 1
    Note: `%install` is a specfile section. `install` is an executable on your system that is similar to `cp`, but maintains permissions, etc. – Aaron D. Marasco Jul 23 '16 at 14:50

1 Answers1

12

%install section is executed on your machine during buildtime of your package. In this section you should create the file structure in %{buildroot}. It is not your task to copy it final destination on client machine.

So you should do something like:

%install
mkdir -p %{buildroot}/usr/lib
cp -a some-your-file-from-extracted-targz %{buildroot}/usr/lib/

and then in %files section:

%files
/usr/lib/foobar.bin
/usr/lib/somedir/

Rpm will then takes all listed files in %files section from %buildroot and will put it in package.

msuchy
  • 5,162
  • 1
  • 14
  • 26
  • What if its a very long list of a perl distribution? Do I have to list all those files? Basically I used PerlBrew to install a perl version in a custom location from the default OS. Then I tarred up the file. i.e. perl-5.10.1.tgz and want to just untarr it into /opt/custom/location/ thats it. Just untar a tgz file in a specific location. – H-man Sep 14 '16 at 21:58
  • 1
    When you specify directory in %files then rpmbuild include that directory and everything within it. So in example above even file /usr/lib/somedir/foo/bar will be included. Or you can generate that list (but please avoid that if possible). For example see https://github.com/rpm-software-management/mock/blob/devel/mock.spec.in#L138 https://github.com/rpm-software-management/mock/blob/devel/mock.spec.in#L191 – msuchy Sep 15 '16 at 12:14
  • Thanks for all the information. For some reason, when I execute the building of the rpm it seems to seek out Perl dependencies. Again, all I did was compile a Perl distribution using perbrew in a custom location, and after installing all the desired Perl modules using cpanm. I tarred up the folder (i.e. tar -xzvf ) and place that file within the SOURCES folder. Run the rpmbuild -bb SPEC_FILE and it builds the rpm. When go to install the RPM it complains of missing Perl dependencies. Also I have not specified "require" in the spec file. – H-man Sep 16 '16 at 14:05