[SOLVED] - Relocatable RPM SPEC example

Issues related to applications and software problems
Post Reply
User avatar
warron.french
Posts: 616
Joined: 2014/03/27 20:21:58

[SOLVED] - Relocatable RPM SPEC example

Post by warron.french » 2019/01/02 21:50:28

Below is the entirety of my SPEC file (relocat_files.spec)

I have been reading through different walk-throughs for creating a SPEC file that will enable an RPM builder/engineer to make the files relocatable, but I am not clear on a couple of details, so I am hoping I can get some guidance on how to handle the changes necessary to make it happen.

Where do I add the Prefix: tag, between lines 13 and 15, or is anywhere acceptable?

If I make the /usr files relocatable, do I update the lines under the %files section to reflect the Prefix: tag somehow in their paths?

To what do I change the lines to make it reflect accordingly?

I know that I can use the

Code: Select all

rpm -i --prefix /usr=/opt/usr  --prefix /etc=/opt/etc relocate_files.rpm

Code: Select all

  1 Name:           relocat_files
  2 Version:        1.0.0
  3 Release:        1%{?dist}
  4 Summary:        To enable learning about creating a simple RPM that distributes files; with a relocatable/changeable FS-prefix.
  5
  6 Group:          System Environment/Base
  7 License:        GPL
  8 URL:            none
  9 Source0:        relocat_files-1.0.0.tar.gz
 10
 11
 12 BuildArch:      noarch
 13 BuildRoot:      %{_tmppath}/%{name}-buildroot
 14
 15 %description
 16 To enable learning about creating a simple RPM that distributes files; as predecessor with relocatable files as the next (this) evolution of the RPM into relocat_files.rpm.
 17
 18
 19 %prep
 20 %setup -q
 21
 22
 23
 24 %install
 25 mkdir -p "$RPM_BUILD_ROOT"
 26 cp -R * "$RPM_BUILD_ROOT"
 27
 28
 29 %files
 30 %defattr(-,root,root,-)
 31 /etc/wsf.etc
 32 /usr/bin/wsf.bin
 33 /usr/sbin/wsf.sbin
 34
 35
 36
 37 %changelog
Thanks for any direct guidance.
Last edited by warron.french on 2019/01/04 00:20:05, edited 1 time in total.
Thanks,
War

User avatar
TrevorH
Site Admin
Posts: 33191
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Relocatable RPM SPEC example

Post by TrevorH » 2019/01/02 23:46:40

You mean so you can install it using rpm --relocate? Short answer is don't try, that functionality is either deprecated or just plain removed.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

User avatar
warron.french
Posts: 616
Joined: 2014/03/27 20:21:58

Re: Relocatable RPM SPEC example

Post by warron.french » 2019/01/03 01:36:00

Well more specifically to use

rpm -i --prefix /usr=/opt/usr relocat_files.rpm

But it sounds like the same feature. Is it --prefix truly deprecated?
Thanks,
War

User avatar
TrevorH
Site Admin
Posts: 33191
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Relocatable RPM SPEC example

Post by TrevorH » 2019/01/03 09:21:56

It still seems to be in the man pages but I don't think it a) works or b) is supported any more.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

User avatar
warron.french
Posts: 616
Joined: 2014/03/27 20:21:58

Re: Relocatable RPM SPEC example

Post by warron.french » 2019/01/03 13:40:34

Uggh, OK.
Thanks,
War

User avatar
warron.french
Posts: 616
Joined: 2014/03/27 20:21:58

Re: Relocatable RPM SPEC example

Post by warron.french » 2019/01/03 20:15:31

I did end up figuring out how to make the RPM files relocatable.

Adding 2 SPEC directive lines for Prefix (I simply added them above %description):

Code: Select all

 14 Prefix: /usr
 15 Prefix: /etc
 16
 17 %description
 18 To enable learning about creating a simple RPM that distributes files; as predecessor with relocatable files as the next (this) evolution of the RPM into relocat_files.rpm.
Then executes the command to install, like this:
rpm -iv --relocate /usr=/opt/usr --relocate /etc=/opt/etc relocat_files.rpm

That was all that I had to do.

As others might read this thread; it should be reiterated that the community is frowning developers from using relocatable RPMs. In other words, drop your files precisely where you want them to go, do not enable flexibility in your builds.

[NOTE]
So, just because you can, does not mean you should make a relocatable RPM. The installation worked, the removal... it removed the files, but not the directories that were created by the package.

The resulting SPEC files looked like this:

Code: Select all

  1 Name:           relocat_files
  2 Version:        1.0.0
  3 Release:        1%{?dist}
  4 Summary:        To enable learning about creating a simple RPM that distributes files; with a relocatable/changeable FS-prefix.
  5
  6 Group:          System Environment/Base
  7 License:        GPL
  8 URL:            none
  9 Source0:        relocat_files-1.0.0.tar.gz
 10
 11
 12 BuildArch:      noarch
 13 BuildRoot:      %{_tmppath}/%{name}-buildroot
 14
 New 14  Prefix: /usr
 New 15  Prefix: /etc
 All lines below will be incremented up (++).
 
 
 15 %description
 16 To enable learning about creating a simple RPM that distributes files; as predecessor with relocatable files as the next (this) evolution of the RPM into relocat_files.rpm.
 17
 18
 19 %prep
 20 %setup -q
 21
 22
 23
 24 %install
 25 mkdir -p "$RPM_BUILD_ROOT"
 26 cp -R * "$RPM_BUILD_ROOT"
 27
 28
 29 %files
 30 %defattr(-,root,root,-)
 31 /etc/wsf.etc
 32 /usr/bin/wsf.bin
 33 /usr/sbin/wsf.sbin
 34
 35
 36
 37 %changelog
 
Thanks,
War

Mike_Rochefort
Posts: 215
Joined: 2016/03/16 02:34:19

Re: [SOLVED] - Relocatable RPM SPEC example

Post by Mike_Rochefort » 2019/01/09 16:44:49

I don’t believe directories are removed for normal RPMs either. As far as I remember the last time I checked. Multiple RPMs could share data location, and you wouldn’t want /usr being wiped out, would you? ;)

Cheers,
Mike
Solution Architect @RedHat | RHCE
Former SysAdmin @BlueSkyStudios and @Pixar
Feature animation and VFX enthusiast
--
Report CentOS Stream 8 bugs: https://da.gd/c8s-bugs
Report CentOS Stream 9 bugs: https://da.gd/c9s-bugs

User avatar
warron.french
Posts: 616
Joined: 2014/03/27 20:21:58

Re: [SOLVED] - Relocatable RPM SPEC example

Post by warron.french » 2019/01/10 21:21:04

@Mike, good point. Something I totally wasn't thinking about. So, it's not because I wrote a relocatable RPM, but the nature of RPMs in general; to not remove directories.
Thanks,
War

Post Reply