m (moved User:Toshio/Scriptlet postrans to User:Toshio/Writing scriptlets: section became more generic) |
(close tag) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 14: | Line 14: | ||
* If we only want the program in <code>%posttrans</code> to do its work once per-transaction, we may need to write out a flag file so that the <code>%posttrans</code> knows whether to perform an action. | * If we only want the program in <code>%posttrans</code> to do its work once per-transaction, we may need to write out a flag file so that the <code>%posttrans</code> knows whether to perform an action. | ||
To address these issues scriptlets that run earlier need to write out information that is used in <code>%posttrans</code>. We recommend using a subdirectory of <code>%{_localstatedir}/lib/rpm</code> for that. For instance, the eclipse plugin scripts touch a file in <code>%{_localstatedir}/lib/rpm/eclipse/</code> when they're installed. The <code>%posttrans</code> runs a script that checks if that file exists. If it does, it performs its action and then deletes the file. That way the script only performs its action once per transaction. | To address these issues scriptlets that run earlier need to write out information that is used in <code>%posttrans</code>. We recommend using a subdirectory of <code>%{_localstatedir}/lib/rpm-state/</code> for that. For instance, the eclipse plugin scripts touch a file in <code>%{_localstatedir}/lib/rpm-state/eclipse/</code> when they're installed. The <code>%posttrans</code> runs a script that checks if that file exists. If it does, it performs its action and then deletes the file. That way the script only performs its action once per transaction. | ||
{{admon/note||We're asking that the <code>%{_localstatedir}/lib/rpm</code> directory be owned by either the rpm or filesystem packages in Fedora. Until that happens, a package that is providing this functionality needs to own <code>%{_localstatedir}/lib/rpm</code> as well as their subdirectory of it.}} | {{admon/note||We're asking that the <code>%{_localstatedir}/lib/rpm-state/</code> directory be owned by either the rpm or filesystem packages in Fedora. Until that happens, a package that is providing this functionality needs to own <code>%{_localstatedir}/lib/rpm-state/</code> as well as their subdirectory of it.}} | ||
=== Macros === | === Macros === | ||
Line 26: | Line 26: | ||
When writing the macros, the FPC will still want to review the macros (and perhaps include the implementation of the macros in the guideline to show packagers what's happening behind the scenes). | When writing the macros, the FPC will still want to review the macros (and perhaps include the implementation of the macros in the guideline to show packagers what's happening behind the scenes). | ||
One principle that the FPC follows is that macros must not | One principle that the FPC follows is that macros must not contain the start of scriptlet tags (for instance, <code>%pre</code>). This also means that a single macro must not be defined to do things in both <code>%pre</code> and <code>%post</code>. Instead, write one macro that performs the actions in <code>%pre</code> and a separate macro that performs the actions in <code>%post</code>. This principle makes it so that all spec files can use your macros in the same manner even if they already have a <code>%pre</code> or <code>%post</code> defined. | ||
[[Category:Packaging guidelines drafts]] | [[Category:Packaging guidelines drafts]] |
Latest revision as of 17:32, 4 January 2012
To be added to Packaging:ScriptletSnippets after the Syntax Ordering section.
Writing scriptlets
Some tips for writing good scriptlets
Saving state between scriptlets
Sometimes a scriptlet needs to save some state from an earlier running scriptlet in order to use it at a later running scriptlet. This is especially common when trying to optimize the scriptlets. Examples:
- If a
%posttrans
needs to de-register some piece of information when upgrading but the file that has that information is removed when the old package is removed the scriptlets need to save that file during%pre
or%post
so that the script in%posttrans
can access it. - If we only want the program in
%posttrans
to do its work once per-transaction, we may need to write out a flag file so that the%posttrans
knows whether to perform an action.
To address these issues scriptlets that run earlier need to write out information that is used in %posttrans
. We recommend using a subdirectory of %{_localstatedir}/lib/rpm-state/
for that. For instance, the eclipse plugin scripts touch a file in %{_localstatedir}/lib/rpm-state/eclipse/
when they're installed. The %posttrans
runs a script that checks if that file exists. If it does, it performs its action and then deletes the file. That way the script only performs its action once per transaction.
Macros
Complex scriptlets may be placed in rpm macros. This has two benefits:
- The standard package authors only have to remember the macros, not the complex stuff that it does
- The macros' implementations may change without having to update the package
When writing the macros, the FPC will still want to review the macros (and perhaps include the implementation of the macros in the guideline to show packagers what's happening behind the scenes).
One principle that the FPC follows is that macros must not contain the start of scriptlet tags (for instance, %pre
). This also means that a single macro must not be defined to do things in both %pre
and %post
. Instead, write one macro that performs the actions in %pre
and a separate macro that performs the actions in %post
. This principle makes it so that all spec files can use your macros in the same manner even if they already have a %pre
or %post
defined.