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) ...

답변2

이 동작은 다음 방법을 사용하여 구성할 수도 있습니다 DPKg::Options::(wurtel이 이것이 DPkg::Pre-Invoke잘못된 이유를 설명합니다):

apt.conf다음은 데모 스크립트의 예입니다.

DPKg::Options:: "--pre-invoke=/tmp/pre-invoke.sh";

결과 예:

After this operation, 17.4 kB disk space will be freed.
This is testhook. Current action is remove
This is testhook. Current action is remove
(Reading database ... 60383 files and directories currently installed.)

댓글을 달 수 없기 때문에 새로운 답변입니다. [그러나 평판으로 인해]

관련 정보