Install and Uninstall Scripts

Michael A. Chase mchase@ix.netcom.com
Mon Jul 9 09:37:00 GMT 2001


The current postinstall.cc attempts to execute everything in
/etc/postinstall/ with either ash or bash (.sh) or the MSDOS shell (.bat)
after all installation activity is complete.

For uninstalls, I think it would probably work better if we agreed on a
naming convention for a script or batch file that would be executed before
any packages are deleted.  Maybe something like
/etc/preuninstall/package-version.{sh,bat}.  Then setup.exe could execute
any such scripts it finds for packages that are queued for removal before it
starts uninstalling packages.

--
Mac :})
** I normally forward private questions to the appropriate mail list. **
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.
----- Original Message -----
From: "Christopher Faylor" <cgf@redhat.com>
To: <cygwin@cygwin.com>
Cc: <cygwin-developers@cygwin.com>; <janneke@gnu.org>
Sent: Monday, July 09, 2001 07:55
Subject: Re: would love it if more people made contributions?


> This kind of functionality has always been something that we've been
> interested in adding to setup.exe.  I've Cc'ed cygwin-developers with
> this message in the hopes that it will generate a discussion on how
> to proceed with this kind of functionality.
>
> On Mon, Jul 09, 2001 at 12:41:27PM +0200, Jan Nieuwenhuizen wrote:
> >
> >About three weeks ago I `tried my luck' as you suggest, and sent a
> >previous version of below patch to the general cygwin mailing list.
> >
> >We had complaints that setup leaves stuff behind when uninstalling
> >[LilyPond] or related packages
> >
> >    http://mail.gnu.org/pipermail/gnu-music-discuss/2001-June/001987.html
> >
> >but we can't fix any of that until setup has some notion of removal
> >scripts.
> >
> >Below is a patch with a fairly simplistic approach.  It's untested,
> >main purpose is to find out how you want to attack this problem.  I've
> >got more than a bit ambiguous feelings about this; setup would have to
> >do more and be more intelligent/fool prove, otoh, setup could be
> >enhanced until it's another rpm, dpkg, whatnot (Red Carpet plugins,
> >anyone?).
> >
> >(I'm not on this list)
> >
> >diff -urpN --exclude=*~ ../cinstall.orig/ChangeLog ./ChangeLog
> >--- ../cinstall.orig/ChangeLog Fri Jun  1 05:56:01 2001
> >+++ ./ChangeLog Thu Jun 21 15:47:22 2001
> >@@ -1,3 +1,11 @@
> >+2001-06-21  Jan Nieuwenhuizen  <janneke@gnu.org>
> >+
> >+ * postinstall.h: New file.
> >+ * postinstall.cc (init_run_script): New function, share shell init.
> >+ (run_script):  New function, more generic run-script functionality.
> >+ * install.cc (uninstall_one): Added handling of /etc/postremove
> >+ scripts.
> >+
> > 2001-05-31  Michael Chase mchase@ix.netcom.com
> >
> > * main.cc (WinMain): Add setup version to starting setup.log entry
> >diff -urpN --exclude=*~ ../cinstall.orig/install.cc ./install.cc
> >--- ../cinstall.orig/install.cc Tue May 29 05:55:40 2001
> >+++ ./install.cc Mon Jul  9 12:15:25 2001
> >@@ -46,6 +46,7 @@ static char *cvsid = "\n%%% $Id: install
> > #include "log.h"
> > #include "hash.h"
> > #include "mount.h"
> >+#include "postinstall.h"
> >
> > #include "port.h"
> >
> >@@ -217,6 +218,15 @@ exists (char *file)
> >   return 0;
> > }
> >
> >+static void
> >+try_run_script (char *dir, char *fname)
> >+{
> >+  if (exists (concat (dir, "/", fname, ".sh", 0)))
> >+    run_script (dir, concat (fname, ".sh"));
> >+  else if (exists (concat (dir, "/", fname, ".bat", 0)))
> >+    run_script (dir, concat (fname, ".bat"));
> >+}
> >+
> > static int num_installs, num_uninstalls;
> >
> > static void
> >@@ -266,6 +276,10 @@ uninstall_one (char *name, int action)
> > }
> >       num_uninstalls++;
> >     }
> >+
> >+  /* What about remove vs. purge; multiple installed versions; versioned
> >+     remove? */
> >+  try_run_script ("/etc/postremove", name);
> > }
> >
> >
> >@@ -389,6 +403,9 @@ do_install (HINSTANCE h)
> >   create_mount ("/usr/lib", cygpath ("/lib", 0), istext, issystem);
> >   set_cygdrive_flags (istext, issystem);
> >
> >+  /* Let's hope people won't uninstall packages before installing [b]ash
*/
> >+  init_run_script ();
> >+
> >   LOOP_PACKAGES
> >     {
> >       if (package[i].action != ACTION_SRC_ONLY)
> >diff -urpN --exclude=*~ ../cinstall.orig/postinstall.cc ./postinstall.cc
> >--- ../cinstall.orig/postinstall.cc Tue May 29 05:55:41 2001
> >+++ ./postinstall.cc Thu Jun 21 14:57:03 2001
> >@@ -57,8 +57,8 @@ run (char *sh, char *args, char *file)
> >     WaitForSingleObject (pi.hProcess, INFINITE);
> > }
> >
> >-static void
> >-each (char *fname, unsigned int size)
> >+void
> >+run_script (char *dir, char *fname)
> > {
> >   char *ext = strrchr (fname, '.');
> >   if (!ext)
> >@@ -66,21 +66,26 @@ each (char *fname, unsigned int size)
> >
> >   if (sh && strcmp (ext, ".sh") == 0)
> >     {
> >-      char *f2 = concat ("/etc/postinstall/", fname, 0);
> >+      char *f2 = concat (dir, fname, 0);
> >       run (sh, "-c", f2);
> >       free (f2);
> >     }
> >   else if (cmd && strcmp (ext, ".bat") == 0)
> >     {
> >-      char *f2 = backslash (cygpath ("/etc/postinstall/", fname, 0));
> >+      char *f2 = backslash (cygpath (dir, fname, 0));
> >       run (cmd, "/c", f2);
> >       free (f2);
> >     }
> >   else
> >     return;
> >
> >-  rename (cygpath ("/etc/postinstall/", fname, 0),
> >-   cygpath ("/etc/postinstall/", fname, ".done", 0));
> >+  rename (cygpath (dir, fname, 0), cygpath (dir, fname, ".done", 0));
> >+}
> >+
> >+static void
> >+run_script_in_etc_postinstall (char *fname, unsigned int size)
> >+{
> >+  run_script ("/etc/postinstall", fname);
> > }
> >
> > static char *shells [] = {
> >@@ -92,11 +97,9 @@ static char *shells [] = {
> > };
> >
> > void
> >-do_postinstall (HINSTANCE h)
> >+init_run_script ()
> > {
> >-  next_dialog = 0;
> >-  int i;
> >-  for (i=0; shells[i]; i++)
> >+  for (int i=0; shells[i]; i++)
> >     {
> >       sh = backslash (cygpath (shells[i], 0));
> >       if (_access (sh, 0) == 0)
> >@@ -104,7 +107,7 @@ do_postinstall (HINSTANCE h)
> >       free (sh);
> >       sh = 0;
> >     }
> >-
> >+
> >   char old_path[_MAX_PATH];
> >   GetEnvironmentVariable ("PATH", old_path, sizeof (old_path));
> >   SetEnvironmentVariable ("PATH",
> >@@ -130,6 +133,12 @@ do_postinstall (HINSTANCE h)
> >       cmd = "command.com";
> >       break;
> >     }
> >+}
> >
> >-  find (cygpath ("/etc/postinstall", 0), each);
> >+void
> >+do_postinstall (HINSTANCE h)
> >+{
> >+  next_dialog = 0;
> >+  init_run_script ();
> >+  find (cygpath ("/etc/postinstall", 0), run_script_in_etc_postinstall);
> > }
> >diff -urpN --exclude=*~ ../cinstall.orig/postinstall.h ./postinstall.h
> >--- ../cinstall.orig/postinstall.h Thu Jan  1 01:00:00 1970
> >+++ ./postinstall.h Thu Jun 21 14:57:57 2001
> >@@ -0,0 +1,28 @@
> >+/*
> >+ * Copyright (c) 2001, Jan Nieuwenhuizen.
> >+ *
> >+ *     This program is free software; you can redistribute it and/or
modify
> >+ *     it under the terms of the GNU General Public License as published
by
> >+ *     the Free Software Foundation; either version 2 of the License, or
> >+ *     (at your option) any later version.
> >+ *
> >+ *     A copy of the GNU General Public License can be found at
> >+ *     http://www.gnu.org/
> >+ *
> >+ * Written by Jan Nieuwenhuizen <janneke@gnu.org>
> >+ *
> >+ */
> >+#ifndef POSTINSTALL_H
> >+#define POSTINSTALL_H
> >+
> >+/* Run the script fname, found in dir.  If fname has suffix .sh, and
> >+   we have a Bourne shell, execute it using sh.  Otherwise, if fname
> >+   has suffix .bat, execute using cmd */
> >+
> >+void run_script (char *dir, char *fname);
> >+
> >+/* Initialisation stuff for run_script: sh, cmd, CYGWINROOT and PATH */
> >+void init_run_script ();
> >+
> >+#endif /* POSTINSTALL_H */
> >+
> >
> >
> >
> >--
> >Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond - The music
> >typesetter http://www.xs4all.nl/~jantien | http://www.lilypond.org
> >
> >
> >--
> >Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> >Bug reporting:         http://cygwin.com/bugs.html
> >Documentation:         http://cygwin.com/docs.html
> >FAQ:                   http://cygwin.com/faq/
>
> --
> cgf@cygnus.com                        Red Hat, Inc.
> http://sources.redhat.com/            http://www.redhat.com/
>



More information about the Cygwin-developers mailing list