Install entire folder and files in it, RPM spec file
Asked Answered
P

1

8

I have a spec file to build an rpm package, in my %install section I have this:

%install
install -m 700 foo/bar/filesToCopy/. $RPM_BUILD_ROOT/

The filesToCopy folder is a tree exactly how the package file tree should look like. It has all the sub directories a package has such as etc/..., /usr/bin, /usr/share ..., and subsquent files in those.

When building it gives me

install: omitting directory 'foo/bar/filesToCopy/'
error: Bad exit status from /var/tmp/rpm-tmp.sea6XO (%install)

Is there a way I dont have to copy each file individuallly like this:

install -m 700 foo/bar/filesToCopy/usr/bin/file1.ex $RPM_BUILD_ROOT/usr/bin/
...

As everything in filesToCopy/ is the structure as in $RPM_BUILD_ROOT/

UPDATE

I found a solution, I changed the "install -m 700" to a "cp -a"

Photofluorography answered 12/11, 2015 at 8:44 Comment(4)
What is generating the files in the first place? Usually, you call make and make install using the RPM macros (e.g. %make_install), and they handle this all for you. Is your "source" a pre-compiled tarball or something?Perinephrium
Yea, Im using gradle to compile my code, and in my build.gradle file there is a task called preparePacakge. In my RPM Spec under %build I run the command: ./gradlew myApp:preparePackage . Then this creates a directory called TMPINST that has an etc folder and usr folder with sub-dir init, myApp in etc, then bin, lib,share in usr It also containing config files and a jar with all the class files and the man files and so on, all the things I want in the package. Its like what it would look like if you unpacked the .rpm filePhotofluorography
I know nothing about gradle, but this might help.Perinephrium
This question is similar: unix.stackexchange.com/questions/165463/…Oat
A
0

It looks like the %install section is just a shell script.

Try using cp instead of install.

%install
cp -a foo/bar/filesToCopy/* $RPM_BUILD_ROOT/

Or, for copying individual directories wholesale:

%install
mkdir -p $RPM_BUILD_ROOT/usr
cp -a foo/bar/filesToCopy/usr/bin $RPM_BUILD_ROOT/usr/

This will preserve permissions from the filesToCopy directory. If those files are chmod 0755, they'll be 0755 in the output directory. Same with if they're 0644 — they'll be copied as 0644. It'll also preserve timestamps and user ownership.*

In my experience, 99.99% of the time, make install assumes you're installing system programs, so install to the build jail with correct permissions. It's unlikely you'll need a step after this to fix the permissions.

I'd really only use install if you weren't sure about what the state of the files' permissions are, and must make manual corrections to them on a file-by-file basis.


* cp -a — short for cp --preserve=all — will also preserve hard-linked files (if they're copied in the same cp invocation), character device nodes, FIFOs, sockets, symbolic links, etc. It'll also copy file attributes, ACLs, and SELinux security contexts (IIRC) from the source files to the destination files. Without -a, cp can sometimes turn symbolic links into files. User ownership is only copied if possible (i.e. you're root and can chown), and silently ignored otherwise.

Ayurveda answered 9/4 at 16:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.