The following commit has been merged in the master branch:
commit 246cf59f8cb555bdaddd36e01d4b57a5e5ac3c7f
Author: Raphaël Hertzog <[email protected]>
Date:   Mon Apr 12 12:06:01 2010 +0200

    dpkg: export DPKG_MAINTSCRIPT_NAME to tell what kind of script we're running
    
    The idea is that specialized hooks can benefit from this information to
    do the right thing. The same call would be put in the various maintainer
    scripts but the actions taken would be different depending on the script
    nevertheless.

diff --git a/debian/changelog b/debian/changelog
index 08abe03..4e22316 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -31,6 +31,9 @@ dpkg (1.15.6.2) UNRELEASED; urgency=low
     This is a temporary work-around so that dselect doesn't try to reinstall
     packages of priority > standard that were removed or not installed. Thanks
     to Robert Luderda for the patch. Closes: #559519, #556889
+  * dpkg now exports DPKG_MAINTSCRIPT_NAME to maintainer scripts with the
+    type of maintainer script currently running (preinst, postinst, prerm,
+    postrm). Closes: #546577
 
   [ Colin Watson ]
   * Modern tar files typically use NormalFile1 rather than NormalFile0 for
diff --git a/lib/dpkg/dpkg.h b/lib/dpkg/dpkg.h
index 7f94417..d730923 100644
--- a/lib/dpkg/dpkg.h
+++ b/lib/dpkg/dpkg.h
@@ -80,6 +80,7 @@ DPKG_BEGIN_DECLS
 
 #define MAINTSCRIPTPKGENVVAR "DPKG_MAINTSCRIPT_PACKAGE"
 #define MAINTSCRIPTARCHENVVAR "DPKG_MAINTSCRIPT_ARCH"
+#define MAINTSCRIPTNAMEENVVAR "DPKG_MAINTSCRIPT_NAME"
 #define MAINTSCRIPTDPKGENVVAR "DPKG_RUNNING_VERSION"
 
 #define SHELLENV            "SHELL"
diff --git a/man/dpkg.1 b/man/dpkg.1
index 0f6b337..1073be6 100644
--- a/man/dpkg.1
+++ b/man/dpkg.1
@@ -651,6 +651,10 @@ package name being handled.
 .B DPKG_MAINTSCRIPT_ARCH
 Defined by \fBdpkg\fP on the maintainer script environment to the
 architecture the package got built for.
+.TP
+.B DPKG_MAINTSCRIPT_NAME
+Defined by \fBdpkg\fP on the maintainer script environment to the
+name of the script running (preinst, postinst, prerm, postrm).
 .
 .SH EXAMPLES
 To list packages related to the editor \fBvi\fP(1):
diff --git a/src/help.c b/src/help.c
index 9d35b90..fb5ec93 100644
--- a/src/help.c
+++ b/src/help.c
@@ -258,13 +258,13 @@ do_script(struct pkginfo *pkg, struct pkginfoperfile *pif,
 
   c1 = subproc_fork();
   if (!c1) {
-    cmd->argv[0] = preexecscript(cmd);
-
     if (setenv(MAINTSCRIPTPKGENVVAR, pkg->name, 1) ||
         setenv(MAINTSCRIPTARCHENVVAR, pif->architecture, 1) ||
+        setenv(MAINTSCRIPTNAMEENVVAR, cmd->argv[0], 1) ||
         setenv(MAINTSCRIPTDPKGENVVAR, PACKAGE_VERSION, 1))
       ohshite(_("unable to setenv for maintainer script"));
 
+    cmd->argv[0] = preexecscript(cmd);
     command_exec(cmd);
   }
   subproc_signals_setup(cmd->name); /* This does a push_cleanup() */

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to