Hello,
I have an extensive experience with RPMs. I have been using Fedora for 20+ years and I am also a Linux developer.
For RPMs you can generally have scripts that are run before and/or after installation or removal of a package. You can distinguish between installation and upgrade using an argument in the scripts.
(%pre, %post, %preun, %postun directives).
Please describe in more detail what you want and I will integrate your scriplets into the spec file.
Best regards
George