diff -urpN --exclude=*~ --exclude=ChangeLog ../cinstall.orig/install.cc ./install.cc
--- ../cinstall.orig/install.cc	Tue Jul 10 20:45:41 2001
+++ ./install.cc	Tue Jul 10 22:39:14 2001
@@ -47,6 +47,7 @@ static char *cvsid = "\n%%% $Id: install
 #include "hash.h"
 #include "mount.h"
 #include "filemanip.h"
+#include "postinstall.h"
 
 #include "port.h"
 
@@ -218,6 +219,15 @@ exists (const 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", 0));
+  if (exists (concat (dir, fname, ".bat", 0)))
+    run_script (dir, concat (fname, ".bat", 0));
+}
+
 static int num_installs, num_uninstalls;
 
 static void
@@ -226,6 +236,10 @@ uninstall_one (Package *pkg, bool src)
   hash dirs;
   char line[_MAX_PATH];
 
+  /* What about remove vs. purge; multiple installed versions; versioned
+     remove?  Assume simple preremove for now. */
+  try_run_script ("/etc/preremove/", pkg->name);
+
   gzFile lst = gzopen (cygpath ("/etc/setup/", pkg->name,
 				(src ? "-src.lst.gz" : ".lst.gz"), 0), "rb");
   if (lst)
@@ -470,6 +484,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 ();
+  
   for (Package *pkg = package; pkg->name; pkg++)
     {
       Info *pi = pkg->info + pkg->trust;
diff -urpN --exclude=*~ --exclude=ChangeLog ../cinstall.orig/postinstall.cc ./postinstall.cc
--- ../cinstall.orig/postinstall.cc	Tue May 29 05:55:41 2001
+++ ./postinstall.cc	Tue Jul 10 22:19:42 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=*~ --exclude=ChangeLog ../cinstall.orig/postinstall.h ./postinstall.h
--- ../cinstall.orig/postinstall.h	Thu Jan  1 01:00:00 1970
+++ ./postinstall.h	Tue Jul 10 22:19:42 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 */
+
diff -urpN --exclude=*~ --exclude=ChangeLog ../cinstall.orig/version.c ./version.c
--- ../cinstall.orig/version.c	Thu Jan  1 01:00:00 1970
+++ ./version.c	Tue Jul 10 22:19:42 2001
@@ -0,0 +1,2 @@
+char *version = "2.90";
+static char *id = "\n%%% setup-version 2.90\n";

