Hi All,
This is a reposting of a mail I sent to [email protected] - more
appropriate to cygwin-apps.
On Mon, 6 Mar 2006, Dr. F. Lee wrote:
I deploy cygwin using unattended (http://unattended.sf.net/) and wpkg
(http://www.wpkg.org/). It's useful for me to be able to specify additional
packages to be installed on the command line. The attached file is a patch
to
provide this: call "setup -p package1,package2,package3,...,packageN" to
have
packages1-N artificially included in the 'Base' part of the distribution
and
hence automatically included.
No doubt there are many better ways of doing this (I'm not a C++ programmer
and had to go with 'what I could do' rather than 'the best way') but
perhaps
this will be useful.
First off, thanks for the patch -- it's always nice seeing someone
actually try to solve the problem himself, whatever the eventual outcome.
However, patches to setup should generally be sent to cygwin-apps (you'd
have to subscribe). FWIW, I've looked at the patch, and it seems to be
doing what it promises to do (with two minor nits: the global
packages_option seems superfluous, since you don't need to use it outside
of package_meta.cc, and there is probably no reason to make a distinction
on whether something was added via the command line or the user's
selection)... Further discussion of this should happen on cygwin-apps.
I'm a novice at C++, so I'm quite likely to have declared something
incorrectly. I also couldn't see how to make the command line option set
the default selection - which would be a more elegant method.
But, more importantly, you don't have to do *any* C++ programming at all
to achieve what you want. Simply set up a local package server with one
empty package, which is in Base and "requires:" all the packages you need
installed. But I agree that a command-line approach might be more
comfortable in some cases.
Had thought about that, but I didn't see how to specify two repositories
on the command line - and I didn't fancy having to run an httpd to serve
a few files when it seemed like a useful thing for setup to do from the
command line.
(As an aside, I've installed a dozen or so machines with this setup now,
silently and with all the packages I need - I find the patch useful so I
hope someone would be willing to polish / advise me how to polish it so it
could be included in the 'official' version).
Yours,
Frank
diff -u --strip-trailing-cr setup/package_db.cc setup-new/package_db.cc
--- setup/package_db.cc 2005-10-14 05:10:26.000000000 +0100
+++ setup-new/package_db.cc 2006-03-06 13:35:31.279477400 +0000
@@ -399,9 +399,16 @@
#endif
}
+void
+packagedb::addFromCmdLine ()
+{
+ for_each(packages.begin(), packages.end(),
mem_fun(&packagemeta::addToCategoryBase));
+}
+
void
packagedb::fillMissingCategory ()
{
+ for_each(packages.begin(), packages.end(),
visit_if(mem_fun(&packagemeta::addToCategoryBase),
mem_fun(&packagemeta::isManuallyWanted)));
for_each(packages.begin(), packages.end(),
visit_if(mem_fun(&packagemeta::setDefaultCategories),
mem_fun(&packagemeta::hasNoCategories)));
for_each(packages.begin(), packages.end(),
mem_fun(&packagemeta::addToCategoryAll));
}
diff -u --strip-trailing-cr setup/package_db.h setup-new/package_db.h
--- setup/package_db.h 2003-07-29 11:07:22.000000000 +0100
+++ setup-new/package_db.h 2006-03-06 13:38:21.148123000 +0000
@@ -47,6 +47,7 @@
PackageDBConnectedIterator connectedEnd();
void fillMissingCategory();
void markUnVisited();
+ void addFromCmdLine();
void setExistence();
/* all seen binary packages */
static std::vector < packagemeta *> packages;
diff -u --strip-trailing-cr setup/package_meta.cc setup-new/package_meta.cc
--- setup/package_meta.cc 2005-09-11 15:45:54.000000000 +0100
+++ setup-new/package_meta.cc 2006-03-06 15:02:16.480086200 +0000
@@ -43,6 +43,7 @@
#include "script.h"
#include "package_version.h"
+#include "getopt++/StringOption.h"
#include "cygpackage.h"
#include "package_db.h"
@@ -53,6 +54,8 @@
/*****************/
+static StringOption PackageOption ("", 'p', "package", "Packages to include");
+
const
packagemeta::_actions
packagemeta::Default_action (0);
@@ -654,6 +657,25 @@
return categories.size() == 0;
}
+bool
+packagemeta::isManuallyWanted() const
+{
+ string packages_option = PackageOption;
+ string tname;
+ /* Split the packages listed in the option up */
+ string::size_type loc = packages_option.find( ",", 0 );
+ bool breturn=false;
+ while ( loc != string::npos ) {
+ tname=packages_option.substr(0,loc);
+ packages_option=packages_option.substr(loc+1);
+ breturn = breturn || (name.compare(tname)==0);
+ loc = packages_option.find( ",", 0 );
+ }
+ /* At this point, no "," exists */
+ breturn=breturn || (name.compare(packages_option)==0);
+ return breturn;
+}
+
void
packagemeta::setDefaultCategories()
{
@@ -665,3 +687,9 @@
{
add_category ("All");
}
+
+void
+packagemeta::addToCategoryBase()
+{
+ add_category ("Base");
+}
diff -u --strip-trailing-cr setup/package_meta.h setup-new/package_meta.h
--- setup/package_meta.h 2005-05-03 22:55:08.000000000 +0100
+++ setup-new/package_meta.h 2006-03-06 13:37:39.642747800 +0000
@@ -54,8 +54,10 @@
void visited(bool const &);
bool visited() const;
bool hasNoCategories() const;
+ bool isManuallyWanted() const;
void setDefaultCategories();
void addToCategoryAll();
+ void addToCategoryBase();
class _actions
{
diff -u --strip-trailing-cr setup/setup_version.c setup-new/setup_version.c
--- setup/setup_version.c 2006-03-06 12:24:59.154337800 +0000
+++ setup-new/setup_version.c 2006-03-06 13:05:52.788225000 +0000
@@ -1,3 +1,3 @@
#define VERSION_PREFIX "%%% setup-version"
-static const char version_store[] = VERSION_PREFIX " 2.524";
+static const char version_store[] = VERSION_PREFIX " 2.524RFL";
const char *setup_version = version_store + sizeof (VERSION_PREFIX);
diff -u --strip-trailing-cr setup/state.cc setup-new/state.cc
--- setup/state.cc 2005-05-04 15:52:34.000000000 +0100
+++ setup-new/state.cc 2006-03-06 14:27:05.103281400 +0000
@@ -23,6 +23,7 @@
#include "state.h"
bool unattended_mode;
+String packages_option;
int source;
diff -u --strip-trailing-cr setup/state.h setup-new/state.h
--- setup/state.h 2005-05-04 15:52:34.000000000 +0100
+++ setup-new/state.h 2006-03-06 14:26:55.125727000 +0000
@@ -33,6 +33,8 @@
extern bool unattended_mode;
+extern String packages_option;
+
extern int source;
extern String local_dir;