Index: 3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/imageis-add-jpg-dir.sh
===================================================================
--- /gs3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/imageis-add-jpg-dir.sh	(revision 21204)
+++ 	(revision )
@@ -1,50 +1,0 @@
-#!/bin/bash
-
-if [ $# != 2 ] ; then
-  echo "Usage: imageis-add-jpg-dir.sh collection jpg-dir"
-  exit
-fi
-
-srcdirname=${2%/}
-srcdirparent=${srcdirname%%/*}
-docid=${dirtail%.*}
-
-
-if [ ! -d "$srcdirname" ] ; then
-  echo "Error: failed to find directory $srcdirname"
-  exit
-fi
-
-col=$1
-srcdirtail=${srcdirname##*/}
-docid=$srcdirtail
-
-# make sure file extension is lowercase .jpg
-
-dstdir=$col:$docid
-dstdirname=/tmp/vsupload/$dstdir
-
-if [ ! -d "$dstdirname" ] ; then
-  echo "Creating $dstdirname"
-  mkdir "$dstdirname"
-fi
-
-
-echo "Copying files in $srcdirname -> $dstdirname"
-
-(cd "$srcdirname" ; tar cf - --transform 's/\.jpg/\.jpg/i' . ) \
-  | (cd "$dstdirname" ; tar xvf -)
-
-echo "Generating add_dir.xml"
-cat "$IMAGEISHOME/templates/add_dir.xml" \
-  | sed "s@\*\*imgdir\*\*@$dstdir@g" \
-  > "/tmp/vsupload/add_dir.xml"
-
-echo "Ingesting $dstdir"
-
-java -jar "$IMAGEISHOME/ImageIS.jar" "/tmp/vsupload/add_dir.xml"
-
-if [ $? == "0" ] ; then
-  /bin/rm "/tmp/vsupload/add_dir.xml"
-fi
-
Index: /gs3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/pharos-imageis-add.pl
===================================================================
--- /gs3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/pharos-imageis-add.pl	(revision 21205)
+++ /gs3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/pharos-imageis-add.pl	(revision 21205)
@@ -0,0 +1,138 @@
+#!/usr/bin/perl -w
+
+###########################################################################
+#
+# pharos-imageis-add.pl --
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the 
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999 New Zealand Digital Library Project
+#
+# 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.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+BEGIN {
+    die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
+    die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
+    die "IMAGEISHOME not set\n" unless defined $ENV{'IMAGEISHOME'};
+    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
+}
+
+use strict;
+no strict 'refs'; # allow filehandles to be variables and vice versa
+no strict 'subs'; # allow barewords (eg STDERR) as function arguments
+
+
+sub main
+{
+    
+    my $ARGC = scalar(@ARGV);
+    
+    
+    if (($ARGC < 2) || ($ARGC>3)) {
+	my ($progname) = ($0 =~ m/^.*[\/|\\](.*?)$/);
+	print STDERR "Usage: $progname collection file.jpg [doc-id]\n";
+	exit 1;
+    }
+
+    # docid might be undefined, in which case later on is is derived from
+    # from col and the file-name tail to srcfilename
+    my ($col,$srcfilename,$docid) = @ARGV;
+    
+    
+    if ( ! -f $srcfilename ) {
+	print STDERR "Error: failed to find $srcfilename\n";
+	exit 1;
+    }
+    
+    if ( $srcfilename =~ m/\.je?pg$/i ) {
+	print STDERR "Error: Unrecognized JPEG filename extension";
+	exit 1;
+    }
+    
+    if (!defined $docid) {
+	my ($fileroot,$dirname_unused,$suffix_unused) 
+	    = fileparse($srcfilename, "\\.[^\\.]+\$");
+	$docid = $fileroot;
+    }
+    
+    # make sure file extension is lowercase .jpg
+    
+    my $dstfile = "$docid.jpg";
+    
+    if ( $col ne "" ) {
+	$dstfile="$col:$dstfile";
+    }
+    
+    my $tmp_dir = &util::get_toplevel_tmp_dir();
+    my $dstfilename=&util::filename_cat($tmp_dir,$dstfile);
+    
+    &util::cp($srcfilename,$dstfilename);
+    
+    print "Generating add_file.xml\n";
+    
+    my $add_template_filename
+	= &util::filename_cat($ENV{'IMAGEISHOME'},"templates","add_file.xml");
+    my $add_this_filename = &util::filename_cat($tmp_dir,"add_file.xml");
+    
+    if (open(FIN,"<$add_template_filename")) {
+	
+	my $add_this_file_content = "";
+	
+	my $line;
+	while (defined ($line=<FIN>)) {
+	    $line =~ s@\*\*imgfile\*\*@$dstfile@g;
+	    
+	    $add_this_file_content .= $line;
+	}
+	
+	close(FIN);
+	
+	if (open(FOUT,">$add_this_filename")) {
+	    print FOUT $add_this_file_content;
+	    close(FOUT);
+	}
+	else {
+	    print STDERR "Error: failed to write out $add_this_filename\n";
+	    print STDERR "$!\n";
+	}
+    }
+    else {
+	print STDERR "Error: failed to read $add_template_filename\n";
+	print STDERR "$!\n";
+    }
+    
+    
+    my $jar_filename = &util::filename_cat($ENV{'IMAGEISHOME'},"ImageIS.jar");
+    my $java_cmd = "java -jar \"$jar_filename\" \"$add_this_filename\"";
+
+    print "Ingesting $dstfile\n";
+    
+    my $status = system($java_cmd);
+    
+    if ($status == 0 ) {
+	&util::rm($add_this_filename);
+    }
+    else {
+	print STDERR "Error: Failed to run:\n";
+	print STDERR "$!\n";
+	exit 1;
+    }
+}
+ 
+
+main();
Index: 3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/pharos-imageis-add.sh
===================================================================
--- /gs3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/pharos-imageis-add.sh	(revision 21204)
+++ 	(revision )
@@ -1,40 +1,0 @@
-#!/bin/bash
-
-if [ $# != 2 ] ; then
-  echo "Usage: imageis-add-jpg-file.sh collection file.jpg"
-  exit
-fi
-
-col=$1
-srcfilename=$2
-
-if [ ! -f "$srcfilename" ] ; then
-  echo "Error: failed to find $srcfilename"
-  exit
-fi
-
-filetail=${srcfilename##*/}
-docid=${filetail%.*}
-
-# make sure file extension is lowercase .jpg
-
-dstfile=$docid.jpg
-if [ "x$col" != "x" ] ; then
-  dstfile="$col:$dstfile"
-fi
-dstfilename=/tmp/vsupload/$dstfile
-
-/bin/cp "$srcfilename" "$dstfilename"
-
-echo "Generating add_file.xml"
-cat "$IMAGEISHOME/templates/add_file.xml" \
-  | sed "s@\*\*imgfile\*\*@$dstfile@g" \
-  > "/tmp/vsupload/add_file.xml"
-
-echo "Ingesting $dstfile"
-
-java -jar "$IMAGEISHOME/ImageIS.jar" "/tmp/vsupload/add_file.xml"
-
-if [ $? == "0" ] ; then
-  /bin/rm "/tmp/vsupload/add_file.xml"
-fi
Index: /gs3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/pharos-imageis-delete.pl
===================================================================
--- /gs3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/pharos-imageis-delete.pl	(revision 21205)
+++ /gs3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/pharos-imageis-delete.pl	(revision 21205)
@@ -0,0 +1,115 @@
+#!/usr/bin/perl -w
+
+###########################################################################
+#
+# pharos-imageis-delete.pl --
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the 
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999 New Zealand Digital Library Project
+#
+# 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.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+BEGIN {
+    die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
+    die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
+    die "IMAGEISHOME not set\n" unless defined $ENV{'IMAGEISHOME'};
+    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
+}
+
+
+use strict;
+no strict 'refs'; # allow filehandles to be variables and vice versa
+no strict 'subs'; # allow barewords (eg STDERR) as function arguments
+
+
+sub main
+{
+    
+    my $ARGC = scalar(@ARGV);
+    
+    
+    if ($ARGC != 2) {
+	my ($progname) = ($0 =~ m/^.*[\/|\\](.*?)$/);
+	print STDERR "Usage: $progname collection doc-id\n";
+	exit 1;
+    }
+
+    my ($col,$id) = @ARGV;
+            
+    my $docid = $id;
+    if ( $col ne "" ) {
+	$docid="$col:$docid";
+    }
+    
+    my $tmp_dir = &util::get_toplevel_tmp_dir();
+    
+    print "Generating del_id.xml\n";
+    
+    my $del_template_filename
+	= &util::filename_cat($ENV{'IMAGEISHOME'},"templates","del_id.xml");
+    my $del_this_filename = &util::filename_cat($tmp_dir,"del_id.xml");
+    
+    if (open(FIN,"<$del_template_filename")) {
+	
+	my $del_this_file_content = "";
+	
+	my $line;
+	while (defined ($line=<FIN>)) {
+	    $line =~ s@\*\*docid\*\*@$docid@g;
+	    
+	    $del_this_file_content .= $line;
+	}
+	
+	close(FIN);
+	
+	if (open(FOUT,">$del_this_filename")) {
+	    print FOUT $del_this_file_content;
+	    close(FOUT);
+	}
+	else {
+	    print STDERR "Error: failed to write out $del_this_filename\n";
+	    print STDERR "$!\n";
+	}
+    }
+    else {
+	print STDERR "Error: failed to read $del_template_filename\n";
+	print STDERR "$!\n";
+    }
+    
+    
+    my $jar_filename = &util::filename_cat($ENV{'IMAGEISHOME'},"ImageIS.jar");
+    my $java_cmd = "java -jar \"$jar_filename\" \"$del_this_filename\"";
+
+    print "Deleting $docid\n";
+    
+    my $status = system($java_cmd);
+    
+    if ($status == 0 ) {
+	&util::rm($del_this_filename);
+    }
+    else {
+	print STDERR "Error: Failed to run:\n";
+	print STDERR "$!\n";
+	exit 1;
+    }
+}
+ 
+
+main();
+
Index: 3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/pharos-imageis-delete.sh
===================================================================
--- /gs3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/pharos-imageis-delete.sh	(revision 21204)
+++ 	(revision )
@@ -1,28 +1,0 @@
-#!/bin/bash
-
-if [ $# != 2 ] ; then
-  echo "Usage: imageis-del-id.sh col id"
-  exit
-fi
-
-col=$1
-id=$2
-
-docid=$id
-if [ "x$col" != "x" ] ; then
-  docid="$col:$docid"
-fi
-
-
-echo "Generating del_id.xml"
-cat "$IMAGEISHOME/templates/del_id.xml" \
-  | sed "s@\*\*docid\*\*@$docid@g" \
-  > "/tmp/vsupload/del_id.xml"
-
-echo "Deleting $docid"
-
-java -jar "$IMAGEISHOME/ImageIS.jar" "/tmp/vsupload/del_id.xml"
-
-if [ $? == "0" ] ; then
-  /bin/rm "/tmp/vsupload/del_id.xml"
-fi
Index: /gs3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/pharos-imageis-identify.pl
===================================================================
--- /gs3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/pharos-imageis-identify.pl	(revision 21205)
+++ /gs3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/pharos-imageis-identify.pl	(revision 21205)
@@ -0,0 +1,44 @@
+#!/usr/bin/perl -w
+
+###########################################################################
+#
+# pharos-imageis-add.pl --
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the 
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999 New Zealand Digital Library Project
+#
+# 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.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+BEGIN {
+    die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
+    die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
+    die "IMAGEISHOME not set\n" unless defined $ENV{'IMAGEISHOME'};
+    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
+}
+
+
+
+print "\n";
+print "****\n";
+print "* Pharos-Greenstone3 Bridge\n";
+print "*   - Image Similarity Search\n";
+print "****\n";
+print "\n";
+
+exit 0;
Index: /gs3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/pharos-imageis-query.pl
===================================================================
--- /gs3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/pharos-imageis-query.pl	(revision 21205)
+++ /gs3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/pharos-imageis-query.pl	(revision 21205)
@@ -0,0 +1,156 @@
+#!/usr/bin/perl -w
+
+###########################################################################
+#
+# pharos-imageis-query.pl --
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the 
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999 New Zealand Digital Library Project
+#
+# 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.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+BEGIN {
+    die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
+    die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
+    die "IMAGEISHOME not set\n" unless defined $ENV{'IMAGEISHOME'};
+    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
+}
+
+
+use strict;
+no strict 'refs'; # allow filehandles to be variables and vice versa
+no strict 'subs'; # allow barewords (eg STDERR) as function arguments
+
+
+sub main
+{
+    
+    my $ARGC = scalar(@ARGV);
+    
+    
+    if ($ARGC != 2) {
+	my ($progname) = ($0 =~ m/^.*[\/|\\](.*?)$/);
+	print STDERR "Usage: $progname collection doc-id\n";
+	exit 1;
+    }
+
+    my ($col,$id) = @ARGV;
+            
+    my $docid = $id;
+    if ( $col ne "" ) {
+	$docid="$col:$docid";
+    }
+    
+    my $tmp_dir = &util::get_toplevel_tmp_dir();
+    
+    print "Generating query_id.xml\n";
+    
+    my $query_template_filename
+	= &util::filename_cat($ENV{'IMAGEISHOME'},"templates","query_id.xml");
+    my $query_this_filename = &util::filename_cat($tmp_dir,"query_id.xml");
+    
+    if (open(FIN,"<$query_template_filename")) {
+	
+	my $query_this_file_content = "";
+	
+	my $line;
+	while (defined ($line=<FIN>)) {
+	    $line =~ s@\*\*docid\*\*@$docid@g;
+	    
+	    $query_this_file_content .= $line;
+	}
+	
+	close(FIN);
+	
+	if (open(FOUT,">$query_this_filename")) {
+	    print FOUT $query_this_file_content;
+	    close(FOUT);
+	}
+	else {
+	    print STDERR "Error: failed to write out $query_this_filename\n";
+	    print STDERR "$!\n";
+	}
+    }
+    else {
+	print STDERR "Error: failed to read $query_template_filename\n";
+	print STDERR "$!\n";
+    }
+    
+    
+    my $jar_filename = &util::filename_cat($ENV{'IMAGEISHOME'},"ImageIS.jar");
+    my $java_cmd = "java -jar \"$jar_filename\" \"$query_this_filename\"";
+
+
+    print "Querying $docid\n";
+    
+    chdir($tmp_dir);
+    my $status = system($java_cmd);
+    
+    if ($status == 0 ) {
+	&util::rm($query_this_filename);
+    }
+    else {
+	print STDERR "Error: Failed to run:\n";
+	print STDERR "$!\n";
+	exit 1;
+    }
+
+    my $result_filename = &util::filename_cat($tmp_dir,"image_cbs_result.xml");
+    
+    if ( ! -f $result_filename ) {
+	print STDERR "\n";
+	print STDERR "Error: Failed to generate $result_filename.xml\n";
+	print STDERR "       Check Tomcat's catalina.out for server-side error messages\n";
+	print STDERR "\n";
+	exit 1;
+    }
+    elsif ( -s $result_filename == 0) {
+	print STDERR "\n";
+	print STDERR "Warning: Server returned zero sized file image_cbs_result.xml\n";
+	print STDERR "         Check that the doc-id used is valid\n";
+	print STDERR "\n";
+	&util::rm($result_filename);
+    }
+    else {
+	
+	if (open(FIN,"<$result_filename")) {
+	
+	    my $line;
+	    while (defined ($line=<FIN>)) {
+		print $line;
+	    }
+	    
+	    close(FIN);
+	}
+	else {
+	    print STDERR "Error: failed to read $result_filename\n";
+	    print STDERR "$!\n";
+	}
+
+	print "\n";
+	&util::rm($result_filename);
+    }
+}
+ 
+
+main();
+
+
+
+
Index: 3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/pharos-imageis-query.sh
===================================================================
--- /gs3-extensions/pharos/trunk/cmdline-api-srcpack/bin/script/pharos-imageis-query.sh	(revision 21204)
+++ 	(revision )
@@ -1,42 +1,0 @@
-#!/bin/bash
-
-if [ $# != 2 ] ; then
-  echo "Usage: imageis-query-by-id.sh col id"
-  exit
-fi
-
-col=$1
-id=$2
-
-docid=$col:$id
-
-echo "Generating query_id.xml"
-cat "$IMAGEISHOME/templates/query_id.xml" \
-  | sed "s@\*\*docid\*\*@$docid@g" \
-  > "/tmp/vsupload/query_id.xml"
-
-echo "Querying by $docid"
-
-java -jar "$IMAGEISHOME/ImageIS.jar" "/tmp/vsupload/query_id.xml"
-
-if [ $? == "0" ] ; then
-  /bin/rm "/tmp/vsupload/query_id.xml"
-fi
-
-if [ ! -f image_cbs_result.xml ] ; then
-  echo ""
-  echo "Error: Failed to generate image_cbs_result.xml"
-  echo "       Check catalina.out for server-side error messages"
-  echo ""
-  exit 1
-elif [ ! -s image_cbs_result.xml ] ; then
-  echo ""
-  echo "Warning: Server returned zero sized file image_cbs_result.xml"
-  echo "         Check that the doc-id used is valid"
-  echo ""
-else
-  cat image_cbs_result.xml
-  echo ""
-  /bin/rm image_cbs_result.xml
-fi
-
