I have created my first rpm package for a NodeJS app which is ran as a systemd service.
Since I do not want to package the node_modules folder with the rpm (AFAIK npm install is system/node version dependent so it could create some other issues?) I put this in the %post section of the spec file:
npm install --prefix /opt/%{modname} --production
The first problem with this is that the resulting node_modules folder is now owned by the root user, and not the app user.
The other problem is that uninstalling the rpm package from the system does not remove the node_modules directory and the resulting package-lock.json file.
I realize that I could resolve these two problems by adding this in the %postun and %post sections but this way seems very "hacky" to me:
%post
...
%__chown -R %{username}:%{username} /opt/%{modname}
%postun
...
%__rm -rf /opt/%{modname}
Is there a "proper" way to accomplish what I am trying to do?
Here is the entire spec file: https://gist.github.com/shunkica/d6064c1a743029ea75328114b6dc036d