Balasekhar Nelli
Balasekhar Nelli

Reputation: 1295

How to execute shell script in RPM spec file?

I have an RPM which includes to place files on the target machine. How can write shell script in such a way that if file already exists do not copy it.

Description:

When the RPM gets install it should not replace the file, if the file already exists in the location. Currently, it is changing the configuration as it is replacing. I am planning to write a conditional in the %install script section. I tried and it is not working, throwing error like "else"/"fi" not found.

Upvotes: 1

Views: 8554

Answers (1)

Chris Maes
Chris Maes

Reputation: 37712

in the %files section of your spec file; you can mark your files with %config(noreplace) . That way if the file exists already on the target machine; it will not be overwritten (except if it was left untouched... see more details here).

If you want to keep the existing file no matter what; then you can mess around in %pre and %post sections, but avoid that if you can... something like:

%pre
# gets executed before installation of the files: 
if [ -e /path/to/file]
then
    cp /path/to/file /path/to/backup
fi

%post
# gets executed after installatin of the files
if [ -e /path/to/file]
then
    cp /path/to/backup /path/to/file
fi

Upvotes: 3

Related Questions