1LIBDNF5-ACTIONS(8)                   dnf5                   LIBDNF5-ACTIONS(8)
2
3
4

NAME

6       libdnf5-actions - Actions plugin
7

DESCRIPTION

9       This  plugin  allows  defining  actions to be executed throught libdnf5
10       callbacks hooks.  Each action is hooked to one specific  callback.  Ac‐
11       tions  for  pre_transaction and post_transaction callbacks may define a
12       (glob-like) filtering rule on the package NEVRA or  package  files,  as
13       well as whether the package is incoming or outgoing.
14

CONFIGURATION

16       The  plugin  does  not  extend  the standard configuration. However, it
17       reads "actions" files.
18
19       The actions files are read from <libdnf5_plugins_config_dir>/actions.d/
20       directory. Only files with ".actions" extension are read.
21

ACTIONS FILE FORMAT

23       Empty  lines  and  lines that start with a '#' character (comment line)
24       are ignored.
25
26       Each non-comment line defines an action and consists of five items sep‐
27       arated  by  colons: callback_name:package_filter:direction:options:com‐
28       mand.
29
30       callback_name
31
32pre_base_setup
33
34post_base_setup
35
36pre_transaction
37
38post_transaction
39
40       package_filter
41              A (glob-like) filtering rule aplied on the package  NEVRA  (also
42              in the shortened forms) or package files.
43
44              Empty  filter  means executing the command once with no informa‐
45              tion about the package.  The "*" filter means executing the com‐
46              mand for each package in the transaction that matches the direc‐
47              tion filter.  The filter can be non-empty only for  pre_transac‐
48              tion and post_transaction callbacks.
49
50       direction
51              Filters  packages by their direction (coming into the system/go‐
52              ing out of the system) in a transaction.  If empty,  the  filter
53              is  not applied.  The filter can only be non-empty when combined
54              with a non-empty package_filter.
55
56in - packages coming to the system (downgrade, install,  rein‐
57                stall, upgrade)
58
59out  - packages going out of the system (upgraded, downgraded,
60                reinstalled, removed, replaced/obsoleted)
61
62       options
63              Options are separated by spaces. A space within an option can be
64              written using escaping.
65
66enabled=<value>  -  the value specifies when the action is en‐
67                abled (added in version 0.3.0)
68
691 - action is always enabled
70
71host-only - the action is only enabled for operations  on
72                     the host
73
74installroot-only  - the action is only enabled for opera‐
75                     tions in the alternative "installroot"
76
77       command
78              Any executable file with arguments.
79
80              Arguments are separated by spaces. A space  within  an  argument
81              can  be  written  using  escaping.  Escaping can also be used to
82              prevent substitution and to pass special characters \a, \b,  \f,
83              \n, \r, \t, \v.  Unescaping of arguments is done after substitu‐
84              tion.
85
86              The following variables in the command will be substituted:
87
88${pid} - process ID
89
90${plugin.version} - version of the actions  plugin  (added  in
91                version 0.3.0)
92
93${conf.<option_name>} - option from base configuration
94
95${var.<variable_name>} - variable
96
97${tmp.<actions_plugin_variable_name>}  -  variable exists only
98                in actions plugin context
99
100${pkg.<package_attribute_name>} - value of the package  attri‐
101                bute
102
103${pkg.name} - package name
104
105${pkg.arch} - package arch
106
107${pkg.version} - package version
108
109${pkg.release} - package release
110
111${pkg.epoch} - package epoch
112
113${pkg.na} - package name.architecture
114
115${pkg.evr} - package epoch-version-release
116
117${pkg.nevra} - package nevra (0 epoch is hidden)
118
119${pkg.full_nevra}  -  package full nevra (epoch is always
120                     present) ${name}-${epoch}:${ver}-${rel}.${arch}
121
122${pkg.repo_id} - package repository id
123
124${pkg.license} - package license
125
126${pkg.location} - the change  of  package  state  in  the
127                     transaction:
128
129${pkg.vendor} - package vendor
130
131${pkg.action} - action performed on the package:
132
133                         • I - newly installed package
134
135                         • U - package installed as an upgrade
136
137                         • D - package installed as an downgrade
138
139                         • R - package used for reinstallation
140
141                         • E  -  erased (removed) package from the system (was
142                           upgraded/downgraded/reinstalled/removed)
143
144                         • O - replaced (obsoleted) package
145
146              The command will be evaluated for each package that matched  the
147              package_filter  and  the direction. However, after variable sub‐
148              stitution, any duplicate commands will be removed and each  com‐
149              mand  will  only be executed once per transaction.  The commands
150              are executed in sequence. There is no parallelism. Argument sub‐
151              stitution is performed after the previous command has completed.
152              This allows the substitution to use the results of the  previous
153              commands.   The  order  of execution of the commands follows the
154              order in the action files, but may  differ  from  the  order  of
155              packages  in  the  transaction.  In other words, when you define
156              several action lines for the same package_filter  and  direction
157              these  lines  will be executed in the order they were defined in
158              the action file when the package_filter and direction matches  a
159              package.  However, the order of when a particular package_filter
160              is invoked depends on the position of the corresponding  package
161              in the transaction.
162

ACTION STANDARD OUTPUT FORMAT

164       The  standard  output of each executed action (command) is captured and
165       processed.  Each line of output can set the value or unset one  actions
166       plugin  variable.  It  can  also change the value of an option from the
167       base configuration or a variable.
168
169   Output line format
170       • tmp.<actions_plugin_variable_name>=<value> - sets the value of action
171         plugins variable <actions_plugin_variable_name>
172
173       • tmp.<actions_plugin_variable_name> - removes the action plugins vari‐
174         able if it exists
175
176       • conf.<option_name>=<value> -  sets the value of option  <option_name>
177         in the base configuration
178
179       • var.<variable_name>=<value>  -  sets  value  of  the  vatiable <vari‐
180         able_name>
181

AN EXAMPLE ACTIONS FILE:

183          # Prints header with process id
184          pre_base_setup::::/usr/bin/sh -c echo\ -------------------------------------\ >>/tmp/actions-trans.log
185          pre_base_setup::::/usr/bin/sh -c date\ >>/tmp/actions-trans.log
186          pre_base_setup::::/usr/bin/sh -c echo\ libdnf5\ pre_base_setup\ was\ called.\ Process\ ID\ =\ '${pid}'.\ >>/tmp/actions-trans.log
187          pre_base_setup:::enabled=installroot-only:/usr/bin/sh -c echo\ run\ in\ alternative\ "installroot":\ installroot\ =\ '${conf.installroot}'\ >>/tmp/actions-trans.log
188
189          # Prints the value of the configuration option "defaultyes".
190          pre_base_setup::::/bin/sh -c echo\ 'pre_base_setup:\ conf.defaultyes=${{conf.defaultyes}}'\ >>\ {context.dnf.installroot}/actions.log
191
192          # Prints a message that the "post_base_setup" callback was called.
193          post_base_setup::::/usr/bin/sh -c echo\ libdnf5\ post_base_setup\ was\ called.\ >>/tmp/actions-trans.log
194
195          # Prints the information about the start of the transaction.
196          # Since package_filter is empty, it executes the commands once.
197          pre_transaction::::/usr/bin/sh -c echo\ Transaction\ start.\ Packages\ in\ transaction:\ >>/tmp/actions-trans.log
198
199          # Logs all packages (package action, full_nevra, repo id) in transaction into a file.
200          # Uses the shell command "echo" and redirection to a file.
201          pre_transaction:*:::/usr/bin/sh -c echo\ '${pkg.action}'\ '${pkg.full_nevra}'\ '${pkg.repo_id}'\ >>/tmp/actions-trans.log
202
203          # Prints the date and time and information about the end of the transaction.
204          # Since package_filter is empty, it executes the commands once.
205          post_transaction::::/usr/bin/sh -c date\ >>/tmp/actions-trans.log
206          post_transaction::::/usr/bin/sh -c echo\ Transaction\ end.\ Repositories\ used\ in\ the\ transaction:\ >>/tmp/actions-trans.log
207
208          # Logs all the repositories from which packages were used in the transaction to install on the system.
209          # Each repository will be listed only once, even if multiple packages from the same repository were used.
210          # The same command (after variables substitution) is executed only once per transaction.
211          post_transaction:*:in::/usr/bin/sh -c echo\ '${pkg.repo_id}'\ >>/tmp/actions-trans.log
212
213          # ==============================================================================================
214          # The next two actions emulate the DNF4 snapper plugin. It uses the "snapper" command-line proram.
215
216          # Creates pre snapshot before the transaction and stores the snapshot number in the "tmp.snapper_pre_number" variable.
217          pre_transaction::::/usr/bin/sh -c echo\ "tmp.snapper_pre_number=$(snapper\ create\ -t\ pre\ -p)"
218
219          # If the variable "tmp.snapper_pre_number" exists, it creates post snapshot after the transaction and removes the variable "tmp.snapper_pre_number".
220          post_transaction::::/usr/bin/sh -c [\ -n\ "${tmp.snapper_pre_number}"\ ]\ &&\ snapper\ create\ -t\ post\ --pre-number\ "${tmp.snapper_pre_number}"\ ;\ echo\ tmp.snapper_pre_number
221

AUTHOR

223       See AUTHORS.md in dnf5 source distribution.
224
226       Contributors to the dnf5 project.
227
228
229
230
231                                 Nov 24, 2023               LIBDNF5-ACTIONS(8)
Impressum