[MacPorts] #1068: Pre/Post-install and Post-removal scripts

MacPorts trac at macosforge.org
Wed Nov 28 21:51:22 PST 2007


#1068: Pre/Post-install and Post-removal scripts
-----------------------------------+----------------------------------------
  Reporter:  jdputsch at comcast.net  |       Owner:  macports-tickets at lists.macosforge.org
      Type:  enhancement           |      Status:  new                                  
  Priority:  Normal                |   Milestone:  MacPorts base enhancements           
 Component:  base                  |     Version:                                       
Resolution:                        |    Keywords:                                       
-----------------------------------+----------------------------------------
Old description:

> It seems to me that Darwin Ports needs to have a script that runs after
> the install action. Let me
> explain why:
>
> Take, for example, a port that installs info files into
> /opt/local/share/info using the "install-info"
> script. This script copies the info files to destination AND modifies the
> info directory file (/opt/
> local/share/info/dir).
> Now the normal flow goes something like this:
>
>     port build
>     port destroot # info files goto
> ..../work/destroot/opt/local/share/info
>                   # and the .../work/destroot/opt/local/share/info/dir
> file
>                   # is modified to add the entries.
>     port install
>
> After the "port install" step the "dir" file containing ONLY entries for
> the newly built/installed port
> is copied to /opt/local/share/info/dir. This wipes out any entries that
> may have previously been
> there. I don't think this is the behavior we want.
>
> In addition if "port package" is run during this process a package is
> built that will install a "dir" file
> that only knows about the info files for that package. I don't believe
> this is proper behavior either.
>
> I believe in both cases the proper thing to have happen is to have a post
> install action take place
> that makes sure the proper "dir" file is in place.
> If packages were never built this could be taken care of entirely in the
> Portfile. Unfortunately, I feel
> packages should do the right thing too and only add their info files to
> /opt/local/share/info/dir
> and not replace that file with their idea of what that file should be. I
> don't see any way to
> accomplish that without taking advantage of the "postinstall" or
> "postflight" scripts that Apple
> allows packages to have. See
> http://developer.apple.com/documentation/DeveloperTools/Conceptual/SoftwareDistribution/
> Concepts/sd_pre_post_processing.html
> for more information.
>
> In fact, I'd like to propose two files be added to ports directories:
> "files/preinstall" and "files/
> postinstall". These files, if present, are run just before the "port
> install" action and just after it
> respectively. When building packages, these scripts would be put into the
> proper place in the
> package so they can achieve the same results as they would if run via the
> "port ..." command.
>
> Basically, the port directory with these files would look like this:
>
>      Portfile
>      files/postinstall
>      files/preinstall
>
> I believe that, when combined with actions such as post-destroot, these
> scripts would be allow
> ports to be constructed that do the right thing regardless of their
> installation order AND build
> packages that do the right thing regardless of their installation order.
>
> I realize I've stressed the "info" files here, they are a concrete
> example of why I feel this feature
> needs to be added and supported. I'm sure others will be found.
>
> I also realized that a "postremove" (and maybe) a "preremove" script are
> needed to so packages
> clean up after themselves when removed. Sticking with the earlier "info"
> example ${prefix}/share/
> info/dir is edited by the "postinstall" script. When a package is
> removed, those edits need to be
> undone.
>
> It was very easy to add a "postremove" script to the package DarwinPorts
> builds and modify the
> uninstall.tcl script used by the Uninstaller.app. I don't know how to do
> the same thing with the
> current receipts system for "port install"/"port remove". I know I can
> put tcl code to be executed
> post-remove in there, but I think it's better to have one source for
> these actions and any package
> built by DarwinPorts needs to have scripts since they become decoupled
> from the ports system
> itself.

New description:

 It seems to me that Darwin Ports needs to have a script that runs after
 the install action. Let me
 explain why:

 Take, for example, a port that installs info files into
 /opt/local/share/info using the "install-info"
 script. This script copies the info files to destination AND modifies the
 info directory file (/opt/
 local/share/info/dir).
 Now the normal flow goes something like this:

     port build
     port destroot # info files goto
 ..../work/destroot/opt/local/share/info
                   # and the .../work/destroot/opt/local/share/info/dir
 file
                   # is modified to add the entries.
     port install

 After the "port install" step the "dir" file containing ONLY entries for
 the newly built/installed port
 is copied to /opt/local/share/info/dir. This wipes out any entries that
 may have previously been
 there. I don't think this is the behavior we want.

 In addition if "port package" is run during this process a package is
 built that will install a "dir" file
 that only knows about the info files for that package. I don't believe
 this is proper behavior either.

 I believe in both cases the proper thing to have happen is to have a post
 install action take place
 that makes sure the proper "dir" file is in place.
 If packages were never built this could be taken care of entirely in the
 Portfile. Unfortunately, I feel
 packages should do the right thing too and only add their info files to
 /opt/local/share/info/dir
 and not replace that file with their idea of what that file should be. I
 don't see any way to
 accomplish that without taking advantage of the "postinstall" or
 "postflight" scripts that Apple
 allows packages to have. See
 http://developer.apple.com/documentation/DeveloperTools/Conceptual/SoftwareDistribution/
 Concepts/sd_pre_post_processing.html
 for more information.

 In fact, I'd like to propose two files be added to ports directories:
 "files/preinstall" and "files/
 postinstall". These files, if present, are run just before the "port
 install" action and just after it
 respectively. When building packages, these scripts would be put into the
 proper place in the
 package so they can achieve the same results as they would if run via the
 "port ..." command.

 Basically, the port directory with these files would look like this:

      Portfile
      files/postinstall
      files/preinstall

 I believe that, when combined with actions such as post-destroot, these
 scripts would be allow
 ports to be constructed that do the right thing regardless of their
 installation order AND build
 packages that do the right thing regardless of their installation order.

 I realize I've stressed the "info" files here, they are a concrete example
 of why I feel this feature
 needs to be added and supported. I'm sure others will be found.

 I also realized that a "postremove" (and maybe) a "preremove" script are
 needed to so packages
 clean up after themselves when removed. Sticking with the earlier "info"
 example ${prefix}/share/
 info/dir is edited by the "postinstall" script. When a package is removed,
 those edits need to be
 undone.

 It was very easy to add a "postremove" script to the package DarwinPorts
 builds and modify the
 uninstall.tcl script used by the Uninstaller.app. I don't know how to do
 the same thing with the
 current receipts system for "port install"/"port remove". I know I can put
 tcl code to be executed
 post-remove in there, but I think it's better to have one source for these
 actions and any package
 built by DarwinPorts needs to have scripts since they become decoupled
 from the ports system
 itself.

Comment (by jmpp at macports.org):

 This ticket is sorely out of date and many thing have changed since,
 specially with respect to the info files which we've been pruning from our
 destroots for a long while already. I'm nevertheless going to leave the
 ticket open, as it does contain some interesting suggestions for pre/post-
 installation/uninstallation scripts.

 -jmpp

-- 
Ticket URL: <http://trac.macosforge.org/projects/macports/ticket/1068#comment:4>
MacPorts </projects/macports>
Ports system for Mac OS


More information about the macports-tickets mailing list