Dpkg 環境変数 DPKG_HOOK_ACTION がフックスクリプトに設定されていません。

Dpkg 環境変数 DPKG_HOOK_ACTION がフックスクリプトに設定されていません。

によると、現在のdpkgジョブが私のdpkgフックスクリプトで実行されていることを確認するためにman dpkg使用できます。DPKG_HOOK_ACTION

--pre-invoke=command
--post-invoke=command
      Set an invoke hook command to be run via “sh -c” before or after the dpkg run for the unpack, configure, install, triggers-only, remove  and  purge  dpkg  actions.  This
      option  can be specified multiple times. The order the options are specified is preserved, with the ones from the configuration files taking precedence.  The environment
      variable DPKG_HOOK_ACTION is set for the hooks to the current dpkg action. Note: front-ends might call dpkg several times per invocation, which might run the hooks  more
      times than expected.

しかし、このフックコマンドでは機能しないようです。ここで何が起こっているのかご存知ですか?

$ cat /etc/apt/apt.conf.d/99testhook
DPkg::Pre-Invoke {"echo This is testhook. Current action is $DPKG_HOOK_ACTION; exit 0";};

$ sudo apt-get install screen
...
Fetched 628 kB in 0s (4,366 kB/s)
This is testhook. Current action is
Selecting previously unselected package screen.

ベストアンサー1

--pre-invokeこれはオプションで指定されたコマンドにのみ適用され、--post-invokeそのコマンドが設定で設定されている場合は適用されません。

これはechoコマンドをスクリプトに入れることによって実証することができます。

# cat > /tmp/pre-invoke.sh <<'EOF'
#!/bin/sh
echo This is testhook. Current action is $DPKG_HOOK_ACTION; exit 0
EOF
# chmod +x /tmp/pre-invoke.sh
# dpkg --pre-invoke=/tmp/pre-invoke.sh -i /var/cache/apt/archives/rsync_3.1.1-2+b1_amd64.deb
This is testhook. Current action is install
(Reading database ... 113857 files and directories currently installed.)
Preparing to unpack .../rsync_3.1.1-2+b1_amd64.deb ...
Unpacking rsync (3.1.1-2+b1) over (3.1.1-2+b1) ...
Setting up rsync (3.1.1-2+b1) ...
Restarting rsync daemon: rsync.
Processing triggers for man-db (2.6.7.1-1) ...

おすすめ記事