How to execute a script at %pre, %post, %preun or %postun stage (spec file) while installing/upgrading an rpm
RPM spec files have several sections which allow packages to run code on installation and removal. These bits of code are called scriptlets and are mostly used to update the running system with information from