1

This question already has an answer here:

I have a RPM spec file. How can I make it so that after the RPM installs, a random string is injected into one of the configuration files?

For example:

The RPM installs the binaries and config file to

/opt/bin/foo
/opt/bar.cfg

Inside the bar.cfg, I have the following configuration.

foo.bar = [
        [
                clientId:"herp-derp",
                clientSecret:"<ENTER-CLIENTSECRET-HERE>",
                authorizedGrantTypes:["password"]
        ]
]

I want the RPM's that are distributed to replace "<ENTER-CLIENTSECRET-HERE>" with an actual random string.

Here is how I am generating the random string

echo cat /dev/urandom | base64 | tr -dc "[:alnum:]" | head -c32

Since I have never worked much with RPM or spec files in the past, I'm not sure the appropriate way to go about this. Can I just add something like this to the spec file?

%post
RANDOM_STRING=`cat /dev/urandom | base64 | tr -dc "[:alnum:]" | head -c32`
sed -i.bak "s/clientSecret:\"<ENTER-CLIENTSECRET-HERE>\",/clientSecret:\"$RANDOM_STRING\",/g" /opt/bar.cfg

marked as duplicate by Braiam, jasonwryan, strugee, Ramesh, slm Jun 17 '14 at 0:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Browse other questions tagged or ask your own question.