About Pacman Hooks

Source: Internet
Author: User

About Pacman Hooks

Pacman 5.0 supports Hooks, but before large-scale applications, we have set aside more than a month for users to upgrade to Pacman 5.0 first (because upgrading pacman and having a defined hooks package will lead to failure to execute these hooks ). It has been a month since Hooks was officially put into use. I think it is time to introduce Hooks and how to use it.

Let's take a look at a simple Hook:

[Trigger]Type = FileOperation = InstallOperation = UpgradeTarget = usr/lib/tmpfiles.d/*.conf[Action]Description = Creating temporary files...When = PostTransactionExec = /bin/sh -c 'while read -r f; do /usr/bin/systemd-tmpfiles --create "/$f"; done'NeedsTargets

The function of this Hook is: when the installed or updated package file is detected to existusr/lib/tmpfiles.d/*.confAfter the updatesystemd-tmpfiles --createMethod. The previous detection section is defined in[Trigger]And the subsequent operations are defined in[Action]. Next, let's take a look at these two parts.

I. [Trigger] Section

First, you need to know the Type of the condition that can be triggered ). In the preceding example, a File is used, which is triggered when the corresponding File exists in the Operation package. Another optional Type is the Package name, which directly matches the Package name in the operation.

Next, the Operation Option limits the Operation categories for the software package. You can choose to Install, update, and delete ). When a Hook needs to be executed in multiple operations, just write multiple rows as in the example. There are three common combinations: Write (update cache, database, etc.), write Install + Upgrade (one-time operation during installation) and the corresponding Upgrade + Remove (one-time operation during uninstallation ).

Finally, we need to define a specific Target ). If the target is a file, you need to write the complete path of its relative root directory, but you need to remove the start/character. Wildcard (*,?) Yes. The fnmatch method is used for matching. Similarly, multiple targets can be defined in a Hook, and multiple rows can be written like Operation in the example.

Ii. [Action]

Let's take a look at the execution time of Hooks:

We can see that there are two significantly different Hooks: Pre-transaction Hooks and Post-transaction Hooks.

The Pre-transaction Hook is executed before a specific operation occurs. At this time, the software packages to be upgraded have not been upgraded, and the software packages to be deleted have not been deleted, so that they can finally shine. Therefore, this Hook is usually used together with the Upgrade and Remove operations in the [Trigger] section above. For example, the gconf-remove Hook of the gconf package will be called before the gconf schema is deleted.gconfpkg --uninstallCommand to uninstall the corresponding schema.

The Post-transaction Hook is opposite to it, and is executed after the operation is complete. The above tmpfiles Hook.

These two different types are defined in the When option, respectively writingPreTransactionAndPostTransaction.

The Description option contains only one Description for humans to read. The common practice is to start with the verb entry and end with an ellipsis. The display in the terminal will be as follows:

(1/1) Creating temporary files...

The Exec option defines the specific command to be executed. Unlike the Target option above, you must not only write the complete path of the command to be executed, but also keep the forward/character. If you need to use the specific result obtained by the previous Trigger in the Command (for example, in the preceding example ), you also need to write a line of NeedsTargets in the [Action] to make the matched target the stdin input of the Exec option, one row. It is worth noting that if the matched object is a file, we also need to add the forward/character before performing operations on it, as shown in the example above."/$f".

In addition, the [Action] section has some other options:

  • Depends option: defines the dependencies required for the Hook operation. If the corresponding dependency does not meet the trigger condition, the Hook rejects the operation. It can be defined multiple times.
  • AbortOnFail option: Terminate the entire operation when the Hook fails to be executed. This is only valid for the Pre-transaction Hook. After all, the Post-transaction option is meaningless after the operation. This option does not require any parameters like the NeedsTargets option.

Summary

The late Hooks function replaces many of the original functions. the operations defined in the install file greatly reduce the trouble of re-writing these operations in each package, and save a lot of time for repeated operations. Currently, many common operations have adopted Hooks, but many of them are still being improved. If you have not used these Hooks in the AUR package, do not hesitate to change it to the defender's face!

For details about which common operations have adopted Hooks, refer to this Wiki page. In addition, if you want to find more Hooks examples to study, you can open the local/usr/share/libalpm/hooks/Directory. The installed Hooks are all in this directory.

Reference: The above Wiki page and the pacman source code.

→ Felix Yan

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.