I would like to use custom options during RPM install. I use rpmbuild to craft the RPM so I have the SPEC file.
Can I define my own option that I can use in the SPEC file (e.g. rpm -i --r_password=something acme-1.1-1.el7.noarch.rpm and the value of r_password will be put to a file -> controlled by in the %post section in the SPEC file)?


No, you cannot. You can use macros in %post. But they are evaluated during build time and you can only override it during build time:

%{!?foo:%global foo SOME_DEFAULT}

echo %{foo}

The first line defines some default when macro foo is not present.

Then you can run:

rpmbuild -ba --define='foo bar' evil.spec

where you define your own macro foo with the content bar. After the rpm is built then everything is put into stone and you cannot change the rpm.

But you can do something like:

cat /etc/myconfig.cfg | ... #do something based on content of the file

and the tell user to:

echo foo > /etc/myconfig.cfg; rpm -i acme-1.1-1.el7.noarch.rpm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.