Rpm

在使用 RPM/DNF 下載或安裝軟體包之前執行命令

  • May 10, 2020

使用 apt-get,我可以使用Pre-Invoke 或 Post-Invoke鉤子

Pre-Invoke, Post-Invoke

這是在呼叫 dpkg(1) 之前/之後執行的 shell 命令列表。與選項一樣,這必須在列表符號中指定。使用 /bin/sh 依次呼叫命令;如果任何失敗的 APT 將中止。

另請參閱將腳本掛鉤到 apt-get

在使用 RPM 或 DNF安裝每個軟體包之前和之後是否有類似的方法來執行命令?

將 rpm 或 dnf 命令包裝在另一個腳本中當然是一種方式,但我寧願有一些配置選項。

對於 yum(RHEL/CentOS 7 及以下),有yum-plugin-pre-transaction-actionsyum-plugin-post-transaction-actions軟體包。有關如何將其用於交易前和交易範例,但這裡也有一個範例文件:

#action_key:transaction_state:command
# action_key can be: pkgglob, /path/to/file (wildcards allowed)
# transaction_state can be: install,update,remove,any
# command can be: any shell command
#  the following variables are allowed to be passed to any command:
#   $name - package name
#   $arch - package arch
#   $ver - package version
#   $rel - package release
#   $epoch - package epoch
#   $repoid - package repository id
#   $state - text string of state of the package in the transaction set
#
# file matches cannot be used with removes b/c we don't have the info available

*:install:touch /tmp/$name-installed
zsh:remove:touch /tmp/zsh-removed
zsh:install:touch /tmp/zsh-installed-also
/bin/z*h:install:touch /tmp/bin-zsh-installed
z*h:any:touch /tmp/bin-zsh-any

# each action is expanded once for each matching package, and no action is
# executed twice per transaction, for example
*:install:echo $repoid >>/tmp/repos
# will write each repo only once to /tmp/repos, even if multiple packages from
# the same repo were installed

對於 dnf(RHEL/CentOS 8 及更高版本),在https://github.com/rpm-software-management/dnf-plugins-core/blob/master/plugins/post-transaction-actions.py>有一個外掛用於發布-transaction,但沒有用於預交易。<https://bugzilla.redhat.com/show_bug.cgi?id=967264>和<https://bugzilla.redhat.com/show_bug.cgi?id=1788574有更多資訊。RHEL 8.2 應該具有事務後功能。如果您確實需要交易前,您可以修改交易後程式碼以創建您自己的交易前外掛(並將其作為 PR 送出)。

引用自:https://unix.stackexchange.com/questions/585748