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?
The RPM installs the binaries and config file to
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
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