How to change rpmbuild default directory form /root/rpmbuild directory to other
Asked Answered
P

4

12

I have to build a rpm package for some drivers. I need to build the rpm from a .tar.gz archive. The tar ball also contains the .spec file. I have set up my rpmbuild environment as described here: http://wiki.centos.org/HowTos/SetupRpmBuildEnvironment

My directory structure is thus:

/home/rpmbuild
/home/rpmbuild/BUILD
/home/rpmbuild/RPMS
/home/rpmbuild/SOURCES
/home/rpmbuild/SPECS
/home/rpmbuild/SRPMS

The .tar.gz file contains the specfile and is placed in /home/rpmbuild/SOURCES

If I then navigate to that directory and run the following, the rpm package is built correctly, but is placed in /root/rpmbuild/RPMS instead of /home/rpmbuild/RPMS (where I expected it to be).

sudo rpmbuild -ta driver.tar.gz

I assume this is because I ran rpmbuild with sudo. Am I thinking of this correctly? Is there a way to direct it to build in /home/rpmbuild instead?

I know it is bad practice to use rpmbuild as root, but if I don't run it as root I run into many errors (not having permissions to access directories owned by root - like /tmp/orbit-root). It seems like it would be much more difficult to change the permissions of each of these directories then to change them back.

Is this the correct way to go about this? I greatly appreciate the help.

Platt answered 31/5, 2014 at 2:58 Comment(1)
NEVER run rpmbuild as root. You can very easily ruin your entire system.Entero
C
17

Don't create setup-tree for rpm with command as:

rpmdev-setuptree

Make rpm tree where you want to build the rpm with the command as given below:

mkdir -p rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}

Now, copy the appropriate files in the folders as specs and tar.gz and run the following command in the rpmbuild directory:

rpmbuild --define "_topdir `pwd`" -v -ba SPECS/{*spec_file.specs*}
Currin answered 5/3, 2020 at 4:53 Comment(0)
H
2

the non-privileged user should have access to BUILDROOT. I would check .rpmmacros file inside $HOME/rpmbuild , it defines where is your top directory.

I have setup my .rpmmacros like this:

%packager YourName
%_topdir /home/build/rpmbuild 
%_tmppath /home/build/rpmbuild/tmp
Halm answered 3/3, 2015 at 16:14 Comment(2)
That tmppath was keySmithery
Super! I wanted to build RPM on a container using gitlab runner. Adding .rpmmacros to home dir of user resolved rpm issues.Myrtia
W
0

If you are needing non-root write permission on system directories, then your %install scriptlet is not installing into %{buildroot}.

You will need to patch your build to install into %{buildroot}.

For autoconf generated Makefiles this is often done like

make DESTDIR=%{buildroot} ...
Walkabout answered 9/1, 2015 at 17:33 Comment(0)
A
-1

To keep build files out of the default location, I specify a different build root by using the --root option to rpmbuild:

rpmbuild --root /home/rpmbuild -ta driver.tar.gz

It'll treat that directory as the total root and attempt to use /home/rpmbuild/root/rpmbuild/{BUILDROOT,RPMS} and /home/rpmbuild/root/rpmbuild/var/tmp. The latter you may need to create before invoking the command. You can remove the /root/ part of the name by prefixing the rpmbuild command with HOME="".

Apiarian answered 5/4, 2016 at 16:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.