1

Example snippet of a SPEC file:

...    
%install
unzip $RPM_SOURCE_DIR/APPLICATION-%{version}.zip -d %{buildroot}/
find %{buildroot} -type f ! -name "*.conf" | awk -F %{buildroot} '{print $2}' > filelist.txt
find %{buildroot} -type f -name "*.conf" | awk -F %{buildroot} '{print $2}' > configfilelist.txt


%files -f filelist.txt
...

For regular files I can use the -f option to load the list in the generated file:

%files -f filelist.txt

I want to apply the confilelist in a similar fashion.

%config(noreplace) xyz

Is there a way to do this?

gspoosi
  • 131
  • 4

1 Answers1

1

Add a little awk string concatenation magic and this should work. The rationale is that you now only define a single file for %files -f to parse. To make the single file, I used the shell redirect operator for append rather than force write.

I swapped your order of instructions by defining configuration files first but that probably isn't necessary.

...
%install
unzip $RPM_SOURCE_DIR/APPLICATION-%{version}.zip -d %{buildroot}/

# add prefix to all config files
find %{buildroot} -type f -name "*.conf" | awk -F '%{buildroot}' '{print "%config(noreplace)", $2}' > filelist.txt

# add the rest
find %{buildroot} -type f ! -name "*.conf" | awk -F %{buildroot} '{print $2}' >> filelist.txt

%files -f filelist.txt
...

If you have docs you want to specify you should be able to do the same thing just with {print "%doc", $2} for the awk print string.

Great question, I'm all about these type of logical tricks because it becomes more ripe for CI/CD, less manual data entry, and longer lasting templates.

codejedi365
  • 156
  • 5