0

I just got inspired of this project:

http://www.opendesktop.org/content/show.php?content=145633

Well , i wanted to do a similar thing , after dpkg places something new in /usr/share/applications directory , but where should my script point to , and the parameter to pass in ?

2 Answers 2

5

If the script do not takes parameters, add a file in /etc/apt/apt.conf.d/, for example 92local (numbers are used to force execution order of scripts in that directory), with the following content:

DPkg::Post-Invoke { "/path-to/my-script"; };

and remember to make it executable.

Cannot find right now information on how to pass parameter or input to the script.
If can be of help, when running apt on command line, you should find the command line in the environment variable SUDO_COMMAND.

1
  • i modified that script to find all the .desktop files automatically , so far my problem is resolved , thanks !
    – daisy
    Sep 30, 2011 at 23:44
3

I have found a way to get the commandline of the APT command executed:

Create a file /etc/apt/apt.conf.d/90my_dpkg_post_invoke with content

DPkg::Post-Invoke { "/usr/local/lib/my_dpkg_post_invoke.sh"; }

Create an executable file /usr/local/lib/my_dpkg_post_invoke.sh with content

#!/bin/bash
APTPID=$( ps -ho ppid "${PPID}" )
APTPID="${APTPID## }"   # trim leading spaces
APTCMD=$( ps -ho args "${APTPID}" )
APTCMD="${APTCMD## }"   # trim leading spaces
echo "#### APT Command: ${APTCMD}"

Now you can extend the executable file with a test if the ${APTCMD} contains a string you want to trigger an action for.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .