aboutsummaryrefslogtreecommitdiff
path: root/doc/hooks.html.skel
blob: e83076f71bd5f6e0785f92a534dfbf9215036c75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en">
<head>
<title>Paludis, the Other Package Mangler</title>
<link rel="stylesheet" href="paludis.css" type="text/css" />
</head>
<body>
@HEADER@

<h1>Paludis, the Other Package Mangler</h1>

<h2>Hooks</h2>

<h3>Overview</h3>

<p>This document describes the Paludis hooks interface. A hook is a piece of code
that is executed when a particular well defined action occurs.</p>

<p>There are currently four categories of hook:</p>

<ul>
    <li>General hooks. These have access to a limited environment. If
    a hook returns a non-zero exit code, the action will be aborted.
    See <a href="#general-hooks">General Hooks</a>.</li>

    <li>Ebuild phase hooks. These have <code>ebuild</code> in the hook name, and
    have full access to the ebuild environment (including the ability to call
    <code>die</code>), but are only used for ebuild-based activities.
    See <a href="#ebuild-hooks">Ebuild Hooks</a>.</li>

    <li>Ebuild message hooks. These are special hooks that are called for
    <code>einfo</code>, <code>ewarn</code> etc.
    See <a href="#ebuild-message-hooks">Ebuild Message Hooks</a>.</li>

    <li>Merger / Unmerger hooks. These are used when installing and uninstalling
    content to the live filesystem. If a check hook returns a non-zero exit
    code, the action will be aborted.
    See <a href="#merger-hooks">Merger / Unmerger Hooks</a>.</li>
</ul>

<p>There are currently three categories of hook execution code:</p>

<ul>
    <li><code>.bash</code> hooks. These are simple <code>.bash</code> files that
    are executed with a particular environment. See <a href="#bash-hooks">Bash Hooks</a>
    for details.</li>

    <li><code>.hook</code> hooks. These are also <code>bash</code> files, but rather
    than containing the relevant code in global scope, they make use of functions
    to perform hook actions. They also support specifying execution order dependencies
    upon other <code>.hook</code> files. See <a href="#hook-hooks">Hook Hooks</a>
    for details.</li>

    <li>Repository hooks. These are implemented internally by <code>Repository</code>
    classes.</li>
</ul>

<p>Not all hook execution code methods are available for all hook categories. The
following table indicates availability:</p>

<table border="1">
    <tr>
        <td></td>
        <th><code>.bash</code></th>
        <th><code>.hook</code></th>
        <th>Repository</th>
    </tr>
    <tr>
        <th>General</th>
        <td>yes</td>
        <td>yes</td>
        <td>yes</td>
    </tr>
    <tr>
        <th>Ebuild Phase</th>
        <td>yes</td>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <th>Ebuild Message</th>
        <td>yes</td>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <th>Merger</th>
        <td>yes</td>
        <td>yes</td>
        <td>yes</td>
    </tr>
</table>

<p>Where there is a choice, <code>.hook</code> hooks should be favoured over <code>.bash</code>
hooks.</p>

<h3>Available Hooks</h3>

<h4 id="general-hooks">General Hooks</h4>

<p>The following general normal hooks are available:</p>

<ul>
    <li><code>install_pre</code></li>
    <li><code>install_fail</code></li>
    <li><code>install_post</code></li>
    <li><code>install_all_pre</code></li>
    <li><code>install_all_post</code></li>
    <li><code>install_pretend_pre</code></li>
    <li><code>install_pretend_post</code></li>
    <li><code>install_pretend_display_item_pre</code></li>
    <li><code>install_pretend_display_item_post</code></li>
    <li><code>uninstall_pre</code></li>
    <li><code>uninstall_fail</code></li>
    <li><code>uninstall_post</code></li>
    <li><code>uninstall_all_pre</code></li>
    <li><code>uninstall_all_post</code></li>
    <li><code>clean_pre</code></li>
    <li><code>clean_post</code></li>
    <li><code>clean_fail</code></li>
    <li><code>clean_all_pre</code></li>
    <li><code>clean_all_post</code></li>
    <li><code>sync_pre</code></li>
    <li><code>sync_fail</code></li>
    <li><code>sync_post</code></li>
    <li><code>sync_all_pre</code></li>
    <li><code>sync_all_post</code></li>
    <li><code>fetch_pre</code></li>
    <li><code>fetch_post</code></li>
    <li><code>fetch_all_pre</code></li>
    <li><code>fetch_all_post</code></li>
</ul>

<p>In general, certain special environment variables will be set. <code>HOOK</code> will contain
the name of the hook. For <code>all</code> hooks, <code>TARGETS</code> will contain the targets
for the operation. For non-<code>all</code> hooks, <code>TARGET</code> will contain the current
target. The <code>PALUDIS_CMDLINE</code> variables described below are also available. For the
<code>install_pretend_display_item</code> hooks, the <code>KIND</code> variable will also be of
interest.</p>

<h4 id="ebuild-hooks">Ebuild Hooks</h4>

<p>The following ebuild hooks are available:</p>

<ul>
    <li><code>ebuild_metadata_pre</code></li>
    <li><code>ebuild_metadata_fail</code></li>
    <li><code>ebuild_metadata_post</code></li>
    <li><code>ebuild_init_pre</code></li>
    <li><code>ebuild_init_fail</code></li>
    <li><code>ebuild_init_post</code></li>
    <li><code>ebuild_fetch_pre</code></li>
    <li><code>ebuild_fetch_fail</code></li>
    <li><code>ebuild_fetch_post</code></li>
    <li><code>ebuild_tidyup_pre</code></li>
    <li><code>ebuild_tidyup_fail</code></li>
    <li><code>ebuild_tidyup_post</code></li>
    <li><code>ebuild_strip_pre</code></li>
    <li><code>ebuild_strip_fail</code></li>
    <li><code>ebuild_strip_post</code></li>
    <li><code>ebuild_unpack_pre</code></li>
    <li><code>ebuild_unpack_fail</code></li>
    <li><code>ebuild_unpack_post</code></li>
    <li><code>ebuild_compile_pre</code></li>
    <li><code>ebuild_compile_fail</code></li>
    <li><code>ebuild_compile_post</code></li>
    <li><code>ebuild_install_pre</code></li>
    <li><code>ebuild_install_fail</code></li>
    <li><code>ebuild_install_post</code></li>
    <li><code>ebuild_test_pre</code></li>
    <li><code>ebuild_test_fail</code></li>
    <li><code>ebuild_test_post</code></li>
    <li><code>ebuild_setup_pre</code></li>
    <li><code>ebuild_setup_fail</code></li>
    <li><code>ebuild_setup_post</code></li>
    <li><code>ebuild_config_pre</code></li>
    <li><code>ebuild_config_fail</code></li>
    <li><code>ebuild_config_post</code></li>
    <li><code>ebuild_nofetch_pre</code></li>
    <li><code>ebuild_nofetch_fail</code></li>
    <li><code>ebuild_nofetch_post</code></li>
    <li><code>ebuild_preinst_pre</code></li>
    <li><code>ebuild_preinst_fail</code></li>
    <li><code>ebuild_preinst_post</code></li>
    <li><code>ebuild_postinst_pre</code></li>
    <li><code>ebuild_postinst_fail</code></li>
    <li><code>ebuild_postinst_post</code></li>
    <li><code>ebuild_prerm_pre</code></li>
    <li><code>ebuild_prerm_fail</code></li>
    <li><code>ebuild_prerm_post</code></li>
    <li><code>ebuild_postrm_pre</code></li>
    <li><code>ebuild_postrm_fail</code></li>
    <li><code>ebuild_postrm_post</code></li>
</ul>

<p>As well as the full ebuild environment, the <code>HOOK</code> environment
variable will contain the name of the hook being called. The
<code>PALUDIS_CMDLINE</code> variables described below are also available.</p>

<h4 id="ebuild-message-hooks">Ebuild Message Hooks</h4>

<p>The following ebuild message hooks are available:</p>

<ul>
    <li><code>einfo</code></li>
    <li><code>ewarn</code></li>
    <li><code>eerror</code></li>
    <li><code>elog</code></li>
</ul>

<p>The <code>HOOK</code> environment variable will contain the name of the hook
being called, and the <code>MESSAGE</code> environment variable will contain
the message being passed to the function.  The <code>PALUDIS_CMDLINE</code>
variables described below are also available.</p>

<h4 id="merger-hooks">Merger / Unmerger Hooks</h4>

<p>The merger runs in two stages, for safety. First it checks that it can
probably install safely, then it does the actual install. Note that calculating
the md5, timestamp etc for VDB CONTENTS is done <em>after</em> the install_post
hooks are called.</p>

<p>In each of the following subcategories, the hooks that do not name
a specific type of object are called before or after the entire
process; those that do are called once for each relevant item.</p>

<p>The following merger check hooks are available:</p>

<ul>
    <li><code>merger_check_pre</code></li>
    <li><code>merger_check_post</code></li>
    <li><code>merger_check_file_pre</code></li>
    <li><code>merger_check_file_post</code></li>
    <li><code>merger_check_sym_pre</code></li>
    <li><code>merger_check_sym_post</code></li>
    <li><code>merger_check_dir_pre</code></li>
    <li><code>merger_check_dir_post</code></li>
</ul>

<p>The <code>INSTALL_SOURCE</code> and <code>INSTALL_DESTINATION</code>
environment variables contain the target source and destination. The
<code>ROOT</code> variable contains the filesystem root. The <code>IMAGE</code>
variable contains the image root.</p>

<p>The following merger hooks are available:</p>

<ul>
    <li><code>merger_install_pre</code></li>
    <li><code>merger_install_post</code></li>
    <li><code>merger_install_file_pre</code></li>
    <li><code>merger_install_file_post</code></li>
    <li><code>merger_install_sym_pre</code></li>
    <li><code>merger_install_sym_post</code></li>
    <li><code>merger_install_dir_pre</code></li>
    <li><code>merger_install_dir_post</code></li>
    <li><code>merger_unlink_file_pre</code></li>
    <li><code>merger_unlink_file_post</code></li>
    <li><code>merger_unlink_dir_pre</code></li>
    <li><code>merger_unlink_dir_post</code></li>
    <li><code>merger_unlink_sym_pre</code></li>
    <li><code>merger_unlink_sym_post</code></li>
    <li><code>merger_unlink_misc_pre</code></li>
    <li><code>merger_unlink_misc_post</code></li>
</ul>

<p>Again, <code>ROOT</code> and <code>IMAGE</code> are available. For
install hooks, <code>INSTALL_SOURCE</code>, <code>INSTALL_DESTINATION</code> are
set, and for uninstall hooks, <code>UNLINK_TARGET</code>.</p>

<p>The unmerger hooks are used for uninstalling a package, but not when existing
things have to be removed for an install (the merger does that). The following
unmerger hooks are available:</p>

<ul>
    <li><code>unmerger_unlink_pre</code></li>
    <li><code>unmerger_unlink_post</code></li>
    <li><code>unmerger_unlink_file_pre</code></li>
    <li><code>unmerger_unlink_file_post</code></li>
    <li><code>unmerger_unlink_dir_pre</code></li>
    <li><code>unmerger_unlink_dir_post</code></li>
    <li><code>unmerger_unlink_sym_pre</code></li>
    <li><code>unmerger_unlink_sym_post</code></li>
    <li><code>unmerger_unlink_misc_pre</code></li>
    <li><code>unmerger_unlink_misc_post</code></li>
</ul>

<p>The <code>UNLINK_TARGET</code> environment variable specifies the file about
to be unlinked, and <code>ROOT</code> is the filesystem root.</p>

<h3>User Defined Hooks</h3>

<p>User defined hooks should be executable (<code>chmod a+x</code>) scripts named
<code>*.bash</code> or <code>*.hook</code>. They can live in two locations (or
be symlinked there, to allow a single script to be shared between hooks):</p>

<ul>
    <li><code><em>confdir</em>/hooks/<em>hookname</em>/</code>, where
    <code><em>confdir</em></code> is the directory in which <code>use.conf</code>
    et al. reside.</li>

    <li><code><em>DATADIR</em>/paludis/hooks/<em>hookname</em>/</code>. On most
    systems, <code><em>DATADIR</em></code> is <code>/usr/share</code>.</li>
</ul>

<h4 id="bash-hooks">Bash Hooks</h4>

<p>A <code>.bash</code> hook is merely executed when the associated action is
triggered. There is no guarantee as to execution order.</p>

<h4 id="hook-hooks">Hook Hooks</h4>

<p>A <code>.hook</code> hook is more powerful. It must not run anything in
global scope, but instead defines all its actions in functions. It must, at
minimum, define a function called <code>hook_run_$HOOK</code> for each hook
that it can handle. It may also define functions called <code>hook_depend_$HOOK</code>,
which should output names of any other hooks upon which it depends, and
<code>hook_after_$HOOK</code>, which is similar but indicates an ordering
rather than hard dependency (the named hooks not existing is not an error).
For example:</p>

<pre>
#!/bin/bash

hook_run_install_all_post()
{
    # ensure that einfo etc are available
    export PATH="$(${PALUDIS_EBUILD_DIR}/utils/canonicalise ${PALUDIS_EBUILD_DIR}/utils/ ):${PATH}"
    source ${PALUDIS_EBUILD_DIR}/echo_functions.bash

    echo
    einfo "Checking for monkeys..."

    if [[ -d "${ROOT}/var/lib/monkeys" ]] ; then
        for m in "${ROOT}"/var/lib/monkeys/* ; do
            ewarn "Found monkey $(basename ${m} )"
        done
    else
        einfo "No monkeys found"
    fi
}

hook_depend_install_all_post()
{
    # we need to run after the Paludis standard eselect_env_update hook
    echo eselect_env_update
}

hook_after_install_all_post()
{
    # if checking for rabbits or squirrels, do those first
    echo check_for_rabbits check_for_squirrels
}
</pre>

<p>Note that the <code>hook_depend_</code> and <code>hook_after_</code> functions
are cached, and are generally only called once per session, so the output should
not vary based upon outside parameters.</p>

<h3>Package Manager Defined Hooks</h3>

<p>Paludis places some of its own hooks in
<code><em>LIBEXECDIR</em>/hooks/<em>hookname</em></code>. These directories are
not for end user use.</p>

<h3>Example Hooks</h3>

<p>Paludis ships certain example hooks that many users would find useful, but that
are not suitably general to be enabled by default -- these live in
<code>DATADIR/paludis/hooks/demos/</code>. You may also find the default
hooks useful -- these live in various places in <code>LIBEXECDIR/paludis/hooks/</code>.</p>

<h3>The <code>PALUDIS_CMDLINE</code> Variables</h3>

<p>Sometimes hooks need access to the commandline used to invoke
<code>paludis</code>.  However, manual parsing of the commandline by hooks will
lead to bugs when people forget to emulate certain behaviour (say, short
options, aliases or <code>--</code> support).  To work around this issue,
Paludis provides environment variables prefixed <code>PALUDIS_CMDLINE_</code>
that specify the parsed command line:</p>

<ul>
    <li>The <code>PALUDIS_CMDLINE_PARAMS</code> variable contains the parameters (that is,
    the parts that aren't <code>-x</code> or <code>--blah</code> or values for these).</li>

    <li>For each <code>--param-name</code>, <code>PALUDIS_CMDLINE_param_name</code> (note
    the case and the underscores) is set. If <code>--param-name</code> takes an argument,
    this argument is used for the environment variable's value.</li>

    <li>For short options (<code>-x</code>) and aliases, the appropriate long option's
    variable is set instead.</li>
</ul>

@FOOTER@
</body>
</html>