add `before_install` and `before_uninstall`

This is intended as a tool to force some truly odd cases like #2654. (The container is weird, we need to pre-preprocess it).

I intentionally left this undocumented for now in case we think of a better way to do this, for example as an extension to #2649.