-
Notifications
You must be signed in to change notification settings - Fork 2
Maintainer scripts (preinst prerm postinst postrm pre post preun postun ...)
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 )
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.
- Plugin "user" for creating users
- Plugin "alternatives" for managing update-alternatives
- Plugin "service" for managing services
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.
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')
- debian.org: Maintainer Scripts for deb packages
- Scripts: RPM's Workhorse for rpm packages
¹ Did you consider that dpkg calls the very same maintainer scripts with different arguments when errors occur?