Index: choose.cc
===================================================================
RCS file: /cvs/src/src/winsup/cinstall/choose.cc,v
retrieving revision 2.88
diff -p -u -w -r2.88 choose.cc
--- choose.cc	2002/01/22 06:43:55	2.88
+++ choose.cc	2002/01/24 12:50:03
@@ -753,7 +753,7 @@ do_choose_thread (void *p)
 }
 
 bool
-ChooserPage::Create ()
+ChooserPage::Create (bool all_new)
 {
   return PropertyPage::Create (IDD_CHOOSER);
 }
Index: choose.h
===================================================================
RCS file: /cvs/src/src/winsup/cinstall/choose.h,v
retrieving revision 2.14
diff -p -u -w -r2.14 choose.h
--- choose.h	2002/01/22 06:36:35	2.14
+++ choose.h	2002/01/24 12:50:06
@@ -35,7 +35,7 @@ public:
 
   virtual bool OnMessageApp (UINT uMsg, WPARAM wParam, LPARAM lParam);
 
-  bool Create ();
+  bool Create (bool all_new);
   virtual void OnActivate ();
 };
 
Index: desktop.cc
===================================================================
RCS file: /cvs/src/src/winsup/cinstall/desktop.cc,v
retrieving revision 2.22
diff -p -u -w -r2.22 desktop.cc
--- desktop.cc	2002/01/20 13:31:04	2.22
+++ desktop.cc	2002/01/24 12:50:09
@@ -448,9 +448,12 @@ dialog_cmd (HWND h, int id, HWND hwndctl
   return 0;
 }
 
+static bool skip_desktop;
+
 bool
-DesktopSetupPage::Create ()
+DesktopSetupPage::Create (bool skip)
 {
+  skip_desktop = skip;
   return PropertyPage::Create (NULL, dialog_cmd, IDD_DESKTOP);
 }
 
Index: desktop.h
===================================================================
RCS file: /cvs/src/src/winsup/cinstall/desktop.h,v
retrieving revision 2.2
diff -p -u -w -r2.2 desktop.h
--- desktop.h	2002/01/03 11:27:11	2.2
+++ desktop.h	2002/01/24 12:50:09
@@ -31,7 +31,7 @@ public:
   {
   };
 
-  bool Create ();
+  bool Create (bool skip_desktop);
 
   virtual void OnInit ();
   virtual bool OnFinish ();
Index: ini.cc
===================================================================
RCS file: /cvs/src/src/winsup/cinstall/ini.cc,v
retrieving revision 2.18
diff -p -u -w -r2.18 ini.cc
--- ini.cc	2002/01/20 13:31:04	2.18
+++ ini.cc	2002/01/24 12:50:10
@@ -207,6 +207,67 @@ do_ini_thread (HINSTANCE h, HWND owner)
   next_dialog = IDD_CHOOSER;
 }
 
+void
+do_ini_nowindow ()
+{
+  size_t ini_count = 0;
+  if (source != IDC_SOURCE_CWD)
+  {
+    fprintf(stderr, "Command line processing error. Sorry!\n");
+    exit_setup(1);
+  }
+  ini_count = do_local_ini (NULL);
+
+  if (ini_count == 0)
+    return;
+
+  if (get_root_dir ())
+    {
+      io_stream::mkpath_p (PATH_TO_DIR, "cygfile:///etc/setup");
+
+      unsigned int old_timestamp = 0;
+      io_stream *ots =
+	io_stream::open ("cygfile:///etc/setup/timestamp", "rt");
+      if (ots)
+	{
+	  char temp[20];
+	  memset (temp, '\0', 20);
+	  if (ots->read (temp, 19))
+	    sscanf (temp, "%u", &old_timestamp);
+	  delete ots;
+	  if (old_timestamp && setup_timestamp
+	      && (old_timestamp > setup_timestamp))
+	    fprintf(stderr, "Timestamp problem...\n");
+	    exit_setup (1);
+	}
+      if (setup_timestamp)
+	{
+	  io_stream *nts =
+	    io_stream::open ("cygfile:///etc/setup/timestamp", "wt");
+	  if (nts)
+	    {
+	      char temp[20];
+	      sprintf (temp, "%u", setup_timestamp);
+	      nts->write (temp, strlen (temp));
+	      delete nts;
+	    }
+	}
+    }
+
+  msg ("setup_version is %s, our_version is %s", setup_version ? : "(null)",
+       version);
+  if (setup_version)
+    {
+      char *ini_version = canonicalize_version (setup_version);
+      char *our_version = canonicalize_version (version);
+      if (strcmp (our_version, ini_version) < 0)
+      {
+	fprintf(stderr, "setup_version is %s, our_version is %s\n", setup_version ? : "(null)", version);
+	exit_setup(1);
+      }
+    }
+}
+
 static void
 do_ini_thread_reflector(void* p)
 {
Index: localdir.cc
===================================================================
RCS file: /cvs/src/src/winsup/cinstall/localdir.cc,v
retrieving revision 2.7
diff -p -u -w -r2.7 localdir.cc
--- localdir.cc	2002/01/20 13:31:04	2.7
+++ localdir.cc	2002/01/24 12:50:11
@@ -137,9 +137,19 @@ dialog_cmd (HWND h, int id, HWND hwndctl
   return 0;
 }
 
+void do_ini_nowindow();
+
 bool
-LocalDirPage::Create ()
+LocalDirPage::Create (bool packagedir, char *localdir)
 {
+  if (packagedir) {
+    local_dir = strdup (localdir);
+    save_local_dir();
+    do_ini (GetInstance (), GetHWND ());
+    if (source == IDC_SOURCE_CWD)
+      do_fromcwd (GetInstance (), GetHWND ());
+    return false;
+  }
   return PropertyPage::Create (NULL, dialog_cmd, IDD_LOCAL_DIR);
 }
 
Index: localdir.h
===================================================================
RCS file: /cvs/src/src/winsup/cinstall/localdir.h,v
retrieving revision 2.2
diff -p -u -w -r2.2 localdir.h
--- localdir.h	2002/01/03 11:27:11	2.2
+++ localdir.h	2002/01/24 12:50:11
@@ -32,7 +32,7 @@ public:
   {
   };
 
-  bool Create ();
+  bool Create (bool packagedir, char *localdir);
 
   virtual void OnActivate ();
   virtual void OnInit ();
Index: main.cc
===================================================================
RCS file: /cvs/src/src/winsup/cinstall/main.cc,v
retrieving revision 2.11
diff -p -u -w -r2.11 main.cc
--- main.cc	2002/01/20 13:31:04	2.11
+++ main.cc	2002/01/24 12:50:13
@@ -33,6 +33,7 @@ static const char *cvsid =
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <getopt.h>
 #include "resource.h"
 #include "dialog.h"
 #include "state.h"
@@ -137,6 +138,53 @@ out:
   FreeSid (sid);
 }
 
+static void
+usage (void)
+{
+  fprintf (stderr, "Usage: %s [OPTION]\n"
+      "-v, --version		show splash screen\n"
+      "-n, --netinstall		install from the internet\n"
+      "-d, --netdownload		download from the internet\n"
+      "-l, --localinstall		install from a local directory\n"
+      "-p, --packagedir path	specify the location to store the packages\n"
+      "-r, --rootdir path		specify the cygwin root directory\n"
+      "-D, --dos			use text mode mounts\n"
+      "-u, --unix (default) 		use binary mode mounts\n"
+      "-a, --allusers (default)	use system mounts\n"
+      "-m, --justme		use user mounts\n"
+      "-o, --noproxy		use direct connection to internet\n"
+      "-X, --ie			use Internet Explorer\'s internet settings\n"
+      "-x, --proxy proxy		specify a proxy of the form proxy:port\n"
+      "-f, --ftpsite URL		specify the ftpsite to use\n"
+      "-e, --allnew		download all new packages\n"
+      "-s, --skipdesktop		don't create icon and shortcut\n"
+      "-h, --help			show this window\n",
+      __argv[0]);
+  ExitProcess(1);
+}
+
+namespace CommandLineOptions {
+  enum {
+    version,
+    netinstall,
+    netdownload,
+    localinstall,
+    packagedir,
+    rootdir,
+    dos,
+    unix,
+    all_users,
+    justme,
+    noproxy,
+    ie,
+    proxy,
+    ftpsite,
+    allnew,
+    skipdesktop,
+    option_count // Must be the last element
+  };
+}
+
 // Other threads talk to this page, so we need to have it externable.
 ThreeBarProgressPage Progress;
 
@@ -150,6 +198,38 @@ WinMain (HINSTANCE h,
 
   log (LOG_TIMESTAMP, "Starting cygwin install, version %s", version);
 
+  static struct option long_options[] = {
+    {"dos",		no_argument,		NULL, 'D'},
+    {"ie",		no_argument,		NULL, 'X'},
+    {"allusers",	no_argument,		NULL, 'a'},
+    {"netdownload",	no_argument,		NULL, 'd'},
+    {"allnew",		no_argument,		NULL, 'e'},
+    {"ftpsite",		required_argument,	NULL, 'f'},
+    {"help",		no_argument,		NULL, 'h'},
+    {"localinstall",	no_argument,		NULL, 'l'},
+    {"justme",		no_argument,		NULL, 'm'},
+    {"netinstall",	no_argument,		NULL, 'n'},
+    {"noproxy",		no_argument,		NULL, 'o'},
+    {"packagedir",	required_argument,	NULL, 'p'},
+    {"rootdir",		required_argument,	NULL, 'r'},
+    {"skipdesktop",	no_argument,		NULL, 's'},
+    {"unix",		no_argument,		NULL, 'u'},
+    {"version",		no_argument,		NULL, 'v'},
+    {"proxy",		required_argument,	NULL, 'x'},
+    {0, 0, 0, 0}
+  };
+  int option_index;
+  char options[] = "DXadef:hlmnop:r:suvx:";
+
+  char *root_dir = 0;
+  char *mirror_site = 0;
+  char *proxy_host = 0;
+  char *colon = 0;
+  int proxy_port = 0;
+  using namespace CommandLineOptions;
+  bool clops[option_count] = {false};
+  int i;
+
   SplashPage Splash;
   SourcePage Source;
   RootPage Root;
@@ -167,6 +247,7 @@ WinMain (HINSTANCE h,
   strcpy (local_dir, cwd);
   log (0, "Current Directory: %s", cwd);
 
+  /* Parse the commandline into a argc, argv pair */
   char **argv;
   int argc;
   log (LOG_TIMESTAMP, "Command line parameters\n");
@@ -174,6 +255,89 @@ WinMain (HINSTANCE h,
     log (LOG_TIMESTAMP, "%d - '%s'\n", argc++, *argv);
   log (LOG_TIMESTAMP, "%d parameters passed\n", argc);
 
+  argv = __argv;
+  if (argc > 1)
+    clops[CommandLineOptions::version] = false;
+  opterr = 0;
+  while ((i = getopt_long (argc, argv, options, long_options, &option_index)) != EOF)
+    switch(i)
+    {
+      case 'v':
+	clops[CommandLineOptions::version] = true;
+	break;
+      case 'D':
+	clops[dos] = true;
+	root_text = IDC_ROOT_TEXT;
+	break;
+      case 'X':
+	clops[noproxy] = false;
+	clops[ie] = true;
+	clops[proxy] = false;
+	break;
+      case 'a':
+	clops[all_users] = true;
+	root_scope = IDC_ROOT_SYSTEM;
+	break;
+      case 'd':
+	clops[netinstall] = false;
+	clops[netdownload] = true;
+	clops[localinstall] = false;
+	break;
+      case 'e':
+	clops[allnew] = true;
+	break;
+      case 'f':
+	clops[ftpsite] = true;
+	mirror_site = strdup(optarg);
+	break;
+      case 'l':
+	clops[netinstall] = false;
+	clops[netdownload] = false;
+	clops[localinstall] = true;
+	break;
+      case 'm':
+	clops[justme] = true;
+	root_scope = IDC_ROOT_USER;
+	break;
+      case 'n':
+	clops[netinstall] = true;
+	clops[netdownload] = false;
+	clops[localinstall] = false;
+	break;
+      case 'o':
+	clops[noproxy] = true;
+	clops[ie] = false;
+	clops[proxy] = false;
+	break;
+      case 'p':
+	clops[packagedir] = true;
+	local_dir = strdup(optarg);
+	break;
+      case 'r':
+	clops[rootdir] = true;
+	root_dir = strdup(optarg);
+	break;
+      case 's':
+	clops[skipdesktop] = true;
+	break;
+      case 'u':
+	clops[unix] = true;
+	root_text = IDC_ROOT_BINARY;
+	break;
+      case 'x':
+	clops[noproxy] = false;
+	clops[ie] = false;
+	clops[proxy] = true;
+	proxy_host = strdup(optarg);
+	colon = proxy_host;
+	while (*colon && (*colon != ':')) colon++;
+	*colon++ = 0;
+	proxy_port = atoi(colon);
+	break;
+      default:
+	usage();
+    }
+
   /* Set the default DACL only on NT/W2K. 9x/ME has no idea of access
      control lists and security at all. */
   if (iswinnt)
@@ -184,27 +348,25 @@ WinMain (HINSTANCE h,
 
   // Init window class lib
   Window::SetAppInstance (h);
-
-  // Create pages
-  Splash.Create ();
-  Source.Create ();
-  Root.Create ();
-  LocalDir.Create ();
-  Net.Create ();
-  Site.Create ();
-  Chooser.Create ();
-  Progress.Create ();
-  Desktop.Create ();
 
-  // Add pages to sheet
+  // Check command line options, create necessary pages and add to sheet
+  if (Splash.Create(clops[CommandLineOptions::version]))
   MainWindow.AddPage (&Splash);
+  if (Source.Create(clops[netinstall], clops[netdownload], clops[localinstall]))
   MainWindow.AddPage (&Source);
+  if (Root.Create(clops[netdownload], clops[rootdir], root_dir))
   MainWindow.AddPage (&Root);
+  if (LocalDir.Create (clops[packagedir], local_dir))
   MainWindow.AddPage (&LocalDir);
+  if (Net.Create (clops[localinstall], clops[noproxy], clops[ie], clops[proxy], proxy_host, proxy_port))
   MainWindow.AddPage (&Net);
+  if (Site.Create (clops[localinstall], clops[ftpsite], mirror_site))
   MainWindow.AddPage (&Site);
+  if (Chooser.Create (clops[allnew]))
   MainWindow.AddPage (&Chooser);
+  if (Progress.Create ())
   MainWindow.AddPage (&Progress);
+  if (Desktop.Create (clops[skipdesktop]))
   MainWindow.AddPage (&Desktop);
 
   // Create the PropSheet main window
Index: net.cc
===================================================================
RCS file: /cvs/src/src/winsup/cinstall/net.cc,v
retrieving revision 2.9
diff -p -u -w -r2.9 net.cc
--- net.cc	2002/01/03 11:27:11	2.9
+++ net.cc	2002/01/24 12:50:13
@@ -84,8 +84,23 @@ save_dialog (HWND h)
 }
 
 bool
-NetPage::Create ()
+NetPage::Create (bool localinstall, bool noproxy, bool ie, bool proxy, char *proxy_host, int proxy_port)
 {
+  if (localinstall) return false;
+  if (noproxy) {
+    net_method = IDC_NET_DIRECT;
+    return false;
+  }
+  if (ie) {
+    net_method = IDC_NET_IE5;
+    return false;
+  }
+  if (proxy) {
+    net_method = IDC_NET_PROXY;
+    net_proxy_host = proxy_host;
+    net_proxy_port = proxy_port;
+    return false;
+  }
   return PropertyPage::Create (IDD_NET);
 }
 
Index: net.h
===================================================================
RCS file: /cvs/src/src/winsup/cinstall/net.h,v
retrieving revision 2.2
diff -p -u -w -r2.2 net.h
--- net.h	2002/01/03 11:27:11	2.2
+++ net.h	2002/01/24 12:50:13
@@ -34,7 +34,7 @@ public:
   {
   };
 
-  bool Create ();
+  bool Create (bool localinstall, bool noproxy, bool ie, bool proxy, char *proxy_host, int proxy_port);
 
   virtual void OnInit ();
   virtual long OnNext ();
Index: root.cc
===================================================================
RCS file: /cvs/src/src/winsup/cinstall/root.cc,v
retrieving revision 2.8
diff -p -u -w -r2.8 root.cc
--- root.cc	2001/12/23 12:13:29	2.8
+++ root.cc	2002/01/24 12:50:14
@@ -149,8 +149,15 @@ dialog_cmd (HWND h, int id, HWND hwndctl
 }
 
 bool
-RootPage::Create ()
+RootPage::Create (bool netdownload, bool rootdir, char *root_dir)
 {
+  if (netdownload) return false;
+  if (rootdir) {
+    if (!get_root_dir ())
+      read_mounts ();
+    set_root_dir(root_dir);
+    return false;
+  }
   return PropertyPage::Create (NULL, dialog_cmd, IDD_ROOT);
 }
 
Index: root.h
===================================================================
RCS file: /cvs/src/src/winsup/cinstall/root.h,v
retrieving revision 2.2
diff -p -u -w -r2.2 root.h
--- root.h	2002/01/03 11:27:11	2.2
+++ root.h	2002/01/24 12:50:14
@@ -13,7 +13,7 @@ public:
   {
   };
 
-  bool Create ();
+  bool Create (bool netdownload, bool rootdir, char *root_dir);
 
   virtual void OnInit ();
   virtual long OnNext ();
Index: site.cc
===================================================================
RCS file: /cvs/src/src/winsup/cinstall/site.cc,v
retrieving revision 2.13
diff -p -u -w -r2.13 site.cc
--- site.cc	2002/01/20 13:31:04	2.13
+++ site.cc	2002/01/24 12:50:16
@@ -291,8 +291,20 @@ do_download_site_info (HINSTANCE hinst, 
 
 }
 
-bool SitePage::Create ()
+bool SitePage::Create (bool localinstall, bool ftpsite, char *site)
 {
+  if (localinstall) return false;
+  if (ftpsite)
+  {
+    site_list_type *newsite = new site_list_type (site);
+    site_list_type &listobj = all_site_list.registerbyobject (*newsite);
+    if (&listobj != newsite)
+      /* That site was already registered */
+      delete newsite;
+    site_list.registerbyobject (listobj);
+
+    return false;
+  }
   return PropertyPage::Create (IDD_SITE);
 }
 
Index: site.h
===================================================================
RCS file: /cvs/src/src/winsup/cinstall/site.h,v
retrieving revision 2.4
diff -p -u -w -r2.4 site.h
--- site.h	2002/01/20 13:31:04	2.4
+++ site.h	2002/01/24 12:50:16
@@ -33,7 +33,7 @@ public:
   {
   };
 
-  bool Create ();
+  bool Create (bool localinstall, bool ftpsite, char *mirror_site);
 
   virtual void OnInit ();
   virtual void OnActivate ();
Index: source.cc
===================================================================
RCS file: /cvs/src/src/winsup/cinstall/source.cc,v
retrieving revision 2.10
diff -p -u -w -r2.10 source.cc
--- source.cc	2001/12/23 12:13:29	2.10
+++ source.cc	2002/01/24 12:50:16
@@ -70,8 +70,20 @@ dialog_cmd (HWND h, int id, HWND hwndctl
 }
 
 bool
-SourcePage::Create ()
+SourcePage::Create (bool netinstall, bool netdownload, bool localinstall)
 {
+  if (netinstall) {
+    source = IDC_SOURCE_NETINST;
+    return false;
+  }
+  if (netdownload) {
+    source = IDC_SOURCE_DOWNLOAD;
+    return false;
+  }
+  if (localinstall) {
+    source = IDC_SOURCE_CWD; 
+    return false;
+  }
   return PropertyPage::Create (NULL, dialog_cmd, IDD_SOURCE);
 }
 
Index: source.h
===================================================================
RCS file: /cvs/src/src/winsup/cinstall/source.h,v
retrieving revision 2.2
diff -p -u -w -r2.2 source.h
--- source.h	2002/01/03 11:27:11	2.2
+++ source.h	2002/01/24 12:50:16
@@ -32,7 +32,7 @@ public:
   {
   };
 
-  bool Create ();
+  bool Create (bool netinstall, bool netdownload, bool localinstall);
 
   virtual void OnActivate ();
   virtual void OnDeactivate ();
Index: splash.cc
===================================================================
RCS file: /cvs/src/src/winsup/cinstall/splash.cc,v
retrieving revision 2.8
diff -p -u -w -r2.8 splash.cc
--- splash.cc	2002/01/03 11:27:11	2.8
+++ splash.cc	2002/01/24 12:50:17
@@ -23,8 +23,9 @@
 #include "splash.h"
 
 bool
-SplashPage::Create ()
+SplashPage::Create (bool version)
 {
+  if (!version) return false;
   return PropertyPage::Create (IDD_SPLASH);
 }
 
Index: splash.h
===================================================================
RCS file: /cvs/src/src/winsup/cinstall/splash.h,v
retrieving revision 2.2
diff -p -u -w -r2.2 splash.h
--- splash.h	2002/01/03 11:27:11	2.2
+++ splash.h	2002/01/24 12:50:17
@@ -31,7 +31,7 @@ public:
   {
   };
 
-  bool Create ();
+  bool Create (bool version);
   virtual void OnInit ();
 };
 
