Index: /gsdl/trunk/bin/script/build
===================================================================
--- /gsdl/trunk/bin/script/build	(revision 14924)
+++ /gsdl/trunk/bin/script/build	(revision 14925)
@@ -93,5 +93,14 @@
 
 my $cdir = $collectdir;
-$cdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect") unless $collectdir =~ /\w/;
+if (defined $site)
+{
+    die "GSDL3HOME not set." unless $ENV{'GSDL3HOME'};
+    $cdir = &util::filename_cat ($ENV{'GSDL3HOME'}, "sites", $site, "collect") unless $collectdir =~ /\w/;
+}
+else
+{
+    $cdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect") unless $collectdir =~ /\w/;
+}
+
 my $importdir = &util::filename_cat ($cdir, $collection, "import");
 my $archivedir = &util::filename_cat ($cdir, $collection, "archives");
@@ -177,5 +186,8 @@
     print STDOUT "                           a -download option is supplied\n";
     print STDOUT "   -collectdir directory   Collection directory (defaults to " .
-	&util::filename_cat ($ENV{'GSDLHOME'}, "collect") . ")\n";
+	&util::filename_cat($ENV{'GSDLHOME'}). "collect for Greenstone2;\n";
+    print STDOUT"                            for Greenstone3 use -site option and then collectdir default will be\n";
+    print STDOUT "                            set to the collect folder within that site.)\n";
+    print STDOUT "   -site                   Specify the site within a Greenstone3 installation to use.\n";
     print STDOUT "   -dontinstall            Only applicable if -collectdir is set to something\n";
     print STDOUT "                           other than the default. -dontinstall will suppress\n";
@@ -297,7 +309,15 @@
 		    my $download_cmd = "perl -S filecopy.pl";
 		    $download_cmd .= " -collectdir \"$collectdir\"" if $collectdir =~ /\w/;
+		    $download_cmd .= " -site \"$site\"" if $site =~ /\w/;
 		    $download_cmd .= " -out \"$outfile.download\"" if $use_out;
 		    $download_cmd .= " \"" . $download_dir . "\" " . $collection;
-		    system ($download_cmd);
+
+		    my $download_status = system ($download_cmd);
+		    if ($download_status > 0) 
+		    {
+			die "Failed to execute: $download_cmd\n";
+		    }
+
+
 		    # if using output directory append the file download output to it
 		    &append_file ($out, "$outfile.download");
@@ -308,4 +328,6 @@
 	}
     }
+
+    `echo $importdir ; ls $importdir `;
 
     if (-e &util::filename_cat ($archivedir, "archives.inf")) {
@@ -355,5 +377,27 @@
 
     if ($collectdir ne "" && !$dontinstall) {
-	my $install_collectdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect");
+	
+	my $install_collectdir;
+	if (defined $ENV{'GSDL3HOME'})
+	{
+	    
+	    if ((defined $site) && ($site ne ""))
+	    {
+		$install_collectdir = &util::filename_cat ($ENV{'GSDL3HOME'}, "sites", $site, "collect");
+	    }
+	    else 
+	    {
+		my $msg = "build: ERROR: Need to specify the site within the Greenstone3 installation.";
+		print $out $msg;
+		&log_event ($msg);
+		&final_out (6) if $use_out;
+		die "\n";
+	    }
+	}
+	else
+	{
+	    $install_collectdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect");
+	}
+
 	if (!&util::filenames_equal ($collectdir, $install_collectdir)) {
 	    
@@ -403,4 +447,5 @@
 
     $import_cmd .= " -manifest manifest.xml" if ($manifest);
+    $import_cmd .= " -site \"$site\"" if $site =~ /\w/;
     $import_cmd .= " -collectdir \"$collectdir\"" if $collectdir =~ /\w/;
     $import_cmd .= " -statsfile \"$statsfile\"" if $statsfile =~ /\w/;
@@ -447,4 +492,5 @@
 
     $build_cmd .= " -out \"$outfile.build\"" if $use_out;
+    $build_cmd .= " -site \"$site\"" if $site =~ /\w/;
     $build_cmd .= " -collectdir \"$collectdir\"" if $collectdir =~ /\w/;
     $build_cmd .= " $maxdocs $collection";
@@ -503,4 +549,5 @@
 	}
     }
+
     return 0;
 }
@@ -605,4 +652,5 @@
 			 'download/.+', \@download,
 			 'collectdir/.*/', \$collectdir,
+			 'site/.*/', \$site,
 			 'dontinstall', \$dontinstall,
 			 'save_archives', \$save_archives,
Index: /gsdl/trunk/bin/script/buildcol.pl
===================================================================
--- /gsdl/trunk/bin/script/buildcol.pl	(revision 14924)
+++ /gsdl/trunk/bin/script/buildcol.pl	(revision 14925)
@@ -99,4 +99,10 @@
 	'reqd' => "no",
         'hiddengli' => "yes" },
+      { 'name' => "site",
+	'desc' => "{buildcol.site}",
+	'type' => "string",
+	'deft' => "",
+	'reqd' => "no",
+        'hiddengli' => "yes" },
       { 'name' => "create_images",
 	'desc' => "{buildcol.create_images}",
@@ -269,5 +275,5 @@
 {
     # command line args
-    my ($verbosity, $archivedir, $cachedir, $builddir, $maxdocs, 
+    my ($verbosity, $archivedir, $cachedir, $builddir, $site, $maxdocs, 
 	$debug, $mode, $indexname, $removeold, $keepold, $incremental, 
 	$remove_empty_classifications,
@@ -332,5 +338,5 @@
 
     # get and check the collection
-    if (($collection = &util::use_collection(@ARGV, $collectdir)) eq "") {
+    if (($collection = &colcfg::use_collection($site, @ARGV, $collectdir)) eq "") {
 	&PrintUsage::print_txt_usage($options, "{buildcol.params}");
 	die "\n";
Index: /gsdl/trunk/bin/script/export.pl
===================================================================
--- /gsdl/trunk/bin/script/export.pl	(revision 14924)
+++ /gsdl/trunk/bin/script/export.pl	(revision 14925)
@@ -117,9 +117,16 @@
 	'reqd' => "no",
         'hiddengli' => "yes" },
+      { 'name' => "site",
+	'desc' => "{import.site}",
+	'type' => "string",
+	'deft' => "",
+	'reqd' => "no",
+        'hiddengli' => "yes" },
       { 'name' => "collectdir",
 	'desc' => "{export.collectdir}",
 	'type' => "string",
-	'deft' => &util::filename_cat ($ENV{'GSDLHOME'}, "collect"),
-	'reqd' => "no",
+	# parsearg left "" as default
+	#'deft' => &util::filename_cat ($ENV{'GSDLHOME'}, "collect"),
+        'reqd' => "no",
         'hiddengli' => "yes" },
       { 'name' => "listall",
@@ -247,7 +254,7 @@
 sub main {
     # params
-    my ($language, $verbosity, $importdir, $exportdir, $keepold, $listall,
+    my ($language, $verbosity, $importdir, $exportdir, $site, $keepold, $listall,
 	$removeold, $saveas, $saveas_version, $debug, $OIDtype, $OIDmetadata,
-	$maxdocs, $statsfile, $xsltfile, $mapping_file, $out, $faillog, 
+	$maxdocs, $statsfile, $xsltfile, $mapping_file, $out, $faillog, $gs_mode, $collectcfg,
 	$collectdir, $gli,$xslt_mets,$xslt_txt,$group_marc);
     my $xml = 0;
@@ -334,5 +341,6 @@
 	eval {
 	    # get and check the collection name
-	    if (($collection = &util::use_collection($collect_name, $collectdir)) eq "") {
+	    print STDERR "**** site = $site\n";
+	    if (($collection = &colcfg::use_collection($site, $collect_name, $collectdir)) eq "") {
 		&PrintUsage::print_txt_usage($options, "{export.params}");
 		die "\n";
@@ -365,10 +373,13 @@
 	    my @global_opts = ();
 	    
-	    $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc", "collect.cfg");
-	    if (!-e $configfilename) {
-		(&gsprintf($out, "{common.cannot_find_cfg_file}\n", $configfilename) && die);
-	    }
-	    
-	    my $collectcfg = &colcfg::read_collect_cfg ($configfilename);
+	    # Read in the collection configuration file.
+	    ($configfilename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
+	    
+	    if ($gs_mode eq "gs2") {
+		$collectcfg = &colcfg::read_collect_cfg ($configfilename);
+	    } elsif ($gs_mode eq "gs3") {
+		$collectcfg = &colcfg::read_collection_cfg_xml ($configfilename);
+	    }
+
 	    if (defined $collectcfg->{'plugin'}) {
 		$plugins = $collectcfg->{'plugin'};
Index: /gsdl/trunk/bin/script/filecopy.pl
===================================================================
--- /gsdl/trunk/bin/script/filecopy.pl	(revision 14924)
+++ /gsdl/trunk/bin/script/filecopy.pl	(revision 14925)
@@ -48,6 +48,9 @@
     print STDERR "   -follow_links           Follow symbolic links when recursing directory\n";
     print STDERR "                           structure\n";
-    print STDERR "   -collectdir directory   Collection directory (defaults to " .
-	&util::filename_cat ($ENV{'GSDLHOME'}, "collect") . ")\n";
+    print STDOUT "   -collectdir directory   Collection directory (defaults to " .
+	&util::filename_cat($ENV{'GSDLHOME'}). "collect for Greenstone2;\n";
+    print STDOUT"                            for Greenstone3 use -site option and then collectdir default will be\n";
+    print STDOUT "                            set to the collect folder within that site.)\n";
+    print STDOUT "   -site                   Specify the site within a Greenstone3 installation to use.\n";
     print STDERR "   -out                    Filename or handle to print output status to.\n";
     print STDERR "                           The default is STDERR\n\n";
@@ -116,4 +119,5 @@
 			 'follow_links', \$follow_links,
 			 'collectdir/.*/', \$collectdir,
+			 'site/.*/', \$site,
 			 'out/.*/STDERR', \$out)) {
 	&print_usage();
@@ -121,6 +125,13 @@
     }
 
-    if ($collectdir !~ /\w/) {
-	$collectdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect");
+
+    if (defined $site)
+    {
+	die "GSDL3HOME not set." unless $ENV{'GSDL3HOME'};
+	$collectdir = &util::filename_cat ($ENV{'GSDL3HOME'}, "sites", $site, "collect") unless $collectdir =~ /\w/;
+    }
+    else
+    {
+	$collectdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect") unless $collectdir =~ /\w/;
     }
 
Index: /gsdl/trunk/bin/script/import.pl
===================================================================
--- /gsdl/trunk/bin/script/import.pl	(revision 14924)
+++ /gsdl/trunk/bin/script/import.pl	(revision 14925)
@@ -99,4 +99,10 @@
 	'reqd' => "no",
         'hiddengli' => "yes" },
+      { 'name' => "site",
+	'desc' => "{import.site}",
+	'type' => "string",
+	'deft' => "",
+	'reqd' => "no",
+        'hiddengli' => "yes" },
       { 'name' => "manifest",
 	'desc' => "{import.manifest}",
@@ -239,5 +245,5 @@
 
 sub main {
-    my ($verbosity, $importdir, $archivedir, $manifest, $incremental, $keepold, 
+    my ($verbosity, $importdir, $archivedir, $site, $manifest, $incremental, $keepold, 
 	$removeold, $saveas, $version,
 	$gzip, $groupsize, $OIDtype, $OIDmetadata, $debug, 
@@ -302,5 +308,5 @@
 
     # get and check the collection name
-    if (($collection = &util::use_collection(@ARGV, $collectdir)) eq "") {
+    if (($collection = &colcfg::use_collection($site, @ARGV, $collectdir)) eq "") {
 	&PrintUsage::print_txt_usage($options, "{import.params}");
 	die "\n";
@@ -325,4 +331,5 @@
     # Read in the collection configuration file.
     ($configfilename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
+
     if ($gs_mode eq "gs2") {
         $collectcfg = &colcfg::read_collect_cfg ($configfilename);
