0

I would like to build a RPM Package for a website. in the %post section of my spec file I would like to check if the apache webserver is installed. If so, the config should be copied to /etc/httpd/conf.d/

If no Apache is installed, the config should just be stored in the projectfolder and the admin has to configure the webserver on his own.

So I need a construct like

if [Apache installed]
  cp [configfile] /etc/httpd/conf.d/

EDIT
I found out, I maybe could use rpm -q httpd for it. But how can I use it in the %post section?

Cœur
  • 37,241
  • 25
  • 195
  • 267
0xAffe
  • 1,156
  • 1
  • 13
  • 29

1 Answers1

0

(rpm -q --quiet httpd && cp yourfile /etc/httpd/conf.d/) || true

This will copy your config file over.

Of course, an easier way might just be

( [ -d /etc/httpd/conf.d ] && cp yourfile /etc/httpd/conf.d/) || true

Which says if the directory exists, drop it there, regardless of why the directory is there.

The extra "|| true " at the end causes the result of the line to always be OK so rpm won't claim a scriptlet failed if it didn't exist.

Here's how I tested it:

[user@Niflheim ~]# rpm -q --quiet httpds && echo Yep
[user@Niflheim ~]# echo $?
1
[user@Niflheim ~]# # Need to move to subshell...
[user@Niflheim ~]# (rpm -q --quiet httpds && echo Yep) || true
[user@Niflheim ~]# echo $?
0
[user@Niflheim ~]# (rpm -q --quiet httpd && echo Yep) || true
Yep
[user@Niflheim ~]# echo $?
0
[user@Niflheim ~]#

There are probably some macros you should be using instead of hardcoding /etc/, but I'm on my way out the door.

Aaron D. Marasco
  • 6,506
  • 3
  • 26
  • 39