Line 0
Link Here
|
|
|
1 |
<chapter id='config-hooks'> |
2 |
<title>Hooks Configuration</title> |
3 |
<sect1 id='config-hooks-locations'> |
4 |
<title>Hooks Locations</title> |
5 |
<para> |
6 |
If a hook directory exists, the bash scripts within each one |
7 |
wil either be executed before or after that particular stage, in |
8 |
alphabetical order. Each one will receive the environment of an |
9 |
ebuild, so they are capable of inherit, einfo, and other common |
10 |
commands (if you find them useful). Avoid commands that may |
11 |
trigger changes in the filesystem! |
12 |
</para> |
13 |
|
14 |
<para> |
15 |
All hooks are not allowed to directly alter portage's execution, |
16 |
but they can accomplish certain extra tasks at various points, |
17 |
which might indrectly alter portage's execution. Since hooks |
18 |
execute in a bash environment, they are told the parent process |
19 |
ID, which can be used to kill portage if absolutely needed. This |
20 |
might be useful if a hook handled the rest of a certain job, |
21 |
such as syncing, and portage's default behavior is undesired, or |
22 |
if a hook caught potential problems with the rest of portage's |
23 |
execution. |
24 |
</para> |
25 |
|
26 |
<para> |
27 |
A hook script is expected to understand the following usage: |
28 |
<cmdsynopsis> |
29 |
<command>/bin/bash <replaceable>...</replaceable></command><sbr/> |
30 |
|
31 |
<arg>--opt <replaceable>portage arguments, always translated to long form, given by user at the prompt, such as "--verbose" or "--newuse"</replaceable></arg><sbr/> |
32 |
|
33 |
<arg>--action <replaceable>a single action being performed by portage, such as "depclean", "sync", or an ebuild phase</replaceable></arg><sbr/> |
34 |
|
35 |
<arg>--target <replaceable>the thing to perform the action with or on</replaceable></arg> |
36 |
</cmdsynopsis> |
37 |
</para> |
38 |
|
39 |
<para> |
40 |
The following hook directories are supported. The standard hook |
41 |
script usage applies, except wherever described differently. |
42 |
</para> |
43 |
|
44 |
<itemizedlist> |
45 |
<listitem><para><filename>/etc/portage/hooks/pre-ebuild.d/</filename> - executed before every ebuild execution. Never receives --opt, and --target is set to the full path of the ebuild.</para></listitem> |
46 |
<listitem><para><filename>/etc/portage/hooks/post-ebuild.d/</filename> - executed after every ebuild execution. Never receives --opt, and --target is set to the full path of the ebuild.</para></listitem> |
47 |
<listitem><para><filename>/etc/portage/hooks/pre-run.d/</filename> - executed before portage considers most things, including proper permissions and validity of arguments.</para></listitem> |
48 |
<listitem><para><filename>/etc/portage/hooks/post-run.d/</filename> - executed after portage is done. It should run regardless of any errors or signals sent, but this cannot be guaranteed for certain scenarios (such as when the KILL signal is received). No information is available concerning the reason portage is exiting. This is a limitation of python itself.</para></listitem> |
49 |
<listitem><para><filename>/etc/portage/hooks/pre-sync.d/</filename> - executed before portage synchronizes the portage tree.</para></listitem> |
50 |
<listitem><para><filename>/etc/portage/hooks/post-sync.d/</filename> - executed after portage has successfully synchronized the portage tree. Presently you must use a combination of pre-sync and post-run to catch sync failures if desired.</para></listitem> |
51 |
</itemizedlist> |
52 |
</sect1> |
53 |
<sect1 id='config-hooks-skeleton-hook'> |
54 |
<title>Skeleton Hook</title> |
55 |
<para> |
56 |
Most hooks will parse the options at the beginning and look for |
57 |
specific things. This skeleton hook provides that functionality |
58 |
to get you started. Replace the colons with actual code where |
59 |
desired. |
60 |
</para> |
61 |
<para> |
62 |
It's highly recommended that --verbose, --debug, and --quiet be |
63 |
utilized for suppressing or adding to "regular" output. The |
64 |
following skeleton hook already has example code in place to |
65 |
handle these flags. |
66 |
</para> |
67 |
<programlisting> |
68 |
#!/bin/bash |
69 |
|
70 |
verbose_redirect="/dev/null" |
71 |
debug_redirect="/dev/null" |
72 |
while [[ "$1" != "" ]]; do |
73 |
if [[ "$1" == "--opt" ]]; then |
74 |
if [[ "$2" == "--verbose" ]]; then |
75 |
verbose_redirect="/dev/tty" |
76 |
fi |
77 |
if [[ "$2" == "--debug" ]]; then |
78 |
debug_redirect="/dev/tty" |
79 |
fi |
80 |
if [[ "$2" == "--quiet" ]]; then |
81 |
verbose_redirect="/dev/null" |
82 |
debug_redirect="/dev/null" |
83 |
fi |
84 |
elif [[ "$1" == "--action" ]]; then |
85 |
: |
86 |
elif [[ "$1" == "--target" ]]; then |
87 |
: |
88 |
else |
89 |
ewarn "Unknown hook option: $1 $2" > "${verbose_redirect}" 2>&1 |
90 |
fi |
91 |
shift 2 |
92 |
done |
93 |
einfo "This is an example hook." > "${verbose_redirect}" 2>&1 |
94 |
einfo "This is debug output." > "${debug_redirect}" 2>&1 |
95 |
</programlisting> |
96 |
</sect1> |
97 |
</chapter> |