Maintainer scripts (preinst prerm postinst postrm pre post preun postun ...) - xing/fpm-fry GitHub Wiki

Maintainer scripts provide a powerful way to hook into package managers. Each packaging system has it's own hooks and calling conventions but most package managers have at least the following:

  • before installing a package ( preinst in deb slang, pre in rpm slang )
  • after installing a package ( postinst in deb slang, post in rpm slang )
  • before removing a package ( prerm in deb slang, preun in rpm slang )
  • after removing a package ( postrm in deb slang, postun in rpm slang )

I don't want to write the boilerplate for the different systems

Let's be honest: writing maintainer scripts is tedious and error-prone. Furthermore, the calling conventions of the different package managers differ. Fpm-fry comes with plugins that supply you with some high-level abstractions for things that are frequently used.

There is also one plugin "script_helper" that wraps your script in the necessary boilerplate code for the different package managers.

plugin 'script_helper' do
  # This will create the folder "/var/lib/foo" after a package is installed or upgraded.
  after_install_or_upgrade "mkdir -p /var/lib/foo"
end

Note that this tiny example does neither include a shebang nor the usual checks in which phase of the package installation the maintainer script was called ¹. This stuff is entirely added by fpm-fry.

I want full control over my maintainer scripts

Good luck. Fpm-fry gives you these methods for your recipe:

  • before_install
  • after_install
  • before_remove
  • after_remove

These methods add your script directly to the package. You can do there what ever you want.

# Inserts the whole file as before_install.sh script
before_install File.open('before_install.sh')

Further readings

Footnotes

¹ Did you consider that dpkg calls the very same maintainer scripts with different arguments when errors occur?