Index: /release-kits/shared/linux/wrapper.cpp
===================================================================
--- /release-kits/shared/linux/wrapper.cpp	(revision 19719)
+++ /release-kits/shared/linux/wrapper.cpp	(revision 19720)
@@ -2,9 +2,10 @@
 #include <fstream>
 #include <iomanip>
-#include <cstring>
+#include <string.h>
 #include <cstdlib>
+#include <sstream>
 using namespace std;
 
-#ifdef WEB
+#ifndef CDROM
 #include "wrapper.h"
 #include "libsearch4j.h"
@@ -12,20 +13,70 @@
 #endif
 
+void usage( char* progname, int exitvalue = -1 ) {
+	cerr
+		<< "Usage: " << progname << " [OPTIONS]" << endl
+		<< "OPTIONS: " << endl
+		<< " -h, -help			Display this usage message" << endl
+		<< " -text				Do a non-graphical command line installation" << endl;
+	#ifdef CDROM
+	cerr << " -wd PATH			Look for the CD-ROM at PATH" << endl;
+	#endif
+
+	exit( exitvalue );
+}
+
 int main(int argc, char** argv) {
 
-	char owd[1024];
-	getcwd(owd, sizeof(owd));
+	char wdc[1024];
+	getcwd(wdc, sizeof(wdc));
+	string wd = "";
+	wd.append( wdc );
+	
 	string scratch = (getenv("TMPDIR") == NULL) ? "/tmp" : getenv("TMPDIR");
 	string tempdir = scratch + "/greenstone-installer.tmp"; //temporary directory where we will store extracted files
 	bool succeeded = false;
-	bool textMode = false;
+	bool text_mode = false;
 
 	//parse arguments
-	for ( int i=0; i<argc; i++ ) {
-		if ( strcmp( argv[i], "text" ) == 0 ) {
-			textMode = true;
-		}
-	}
-
+	string a;
+	for ( int i=1; i<argc; i++ ) {
+		a = argv[i];
+		if ( a.compare("-wd") == 0 ) {
+			wd = "";
+			wd.append( argv[++i] );
+		} else if ( a.compare("-h") == 0 || a.compare("-help") == 0 || a.compare("--help") == 0) {
+			usage( argv[0], 0 );
+		} else if ( a.compare("-text") == 0 || a.compare("text") == 0 ) {
+			text_mode = true;
+		} else {
+			cerr << "Unrecognised option '" << a << "'" << endl;
+			usage(argv[0]);
+		}
+	}
+
+	#ifdef CDROM
+	//ensure working directory is correct
+	FILE* pFile;
+	pFile = fopen( (wd+"/Software/core/all/uninst.jar").c_str(), "r");
+	if ( pFile == NULL ) {
+		cerr << "Could not find cdrom at '" << wd << "'." << endl;
+		cerr << "Please enter the path the CDROM [/media/cdrom]: ";
+		getline(cin, wd);
+		if ( wd.compare("") == 0 ) {
+			wd = "/media/cdrom";
+		}
+	} else {
+		fclose(pFile);
+	}
+
+	pFile = fopen( (wd+"/Software/core/all/uninst.jar").c_str(), "r");
+	if ( pFile == NULL ) {
+		cerr << "Could not find cdrom at '"<< wd << "'." << endl;
+		cerr << "Please run the installer again" << endl;
+		exit(-1);
+	} else {
+		fclose(pFile);
+	}
+	#endif
 
 	//create the temp folder
@@ -33,15 +84,13 @@
 	succeeded = ( 0 == system( ("mkdir " + tempdir).c_str() ) );
 	if ( !succeeded ) {
-		cout << "Failed to create the temp directory '" << tempdir << "'. " <<
+		cerr << "Failed to create the temp directory '" << tempdir << "'. " <<
 		 "Check that it does not already exist. Also check that you have write " <<
 		 "permissions to '" << scratch << "', or set the environment variable TMPDIR to " <<
-		 "a directory where you do have write permissions." <<
-		 endl;
-
-		cout << "Exiting" << endl;
+		 "a directory where you do have write permissions." << endl <<
+		"Exiting" << endl;
 		return 1;
 	}
 	
-	#ifdef WEB
+	#ifndef CDROM
 
 	string jarfile = tempdir + "/@installer.name@.jar"; //where we will store the jar file
@@ -59,8 +108,8 @@
 		
 	if ( !succeeded ) {
-		cout << "Failed to extract one or more resources" << endl;
-		cout << "This installer may not have sufficient file permissions to write it to disk" << endl;
-		cout << "Or, the files may be corrupt or missing from this executable" << endl;
-		cout << "Exiting" << endl;
+		cerr << "Failed to extract one or more resources" << endl;
+		cerr << "This installer may not have sufficient file permissions to write it to disk" << endl;
+		cerr << "Or, the files may be corrupt or missing from this executable" << endl;
+		cerr << "Exiting" << endl;
 		return 1;
 	}
@@ -72,5 +121,5 @@
 
 
-	#ifdef WEB
+	#ifndef CDROM
 	#ifdef java_is_bundled
 	succeeded = (system( "/bin/sh -c ./@java.installer@ > /dev/null" ) == 0);
@@ -115,5 +164,5 @@
 		cout << "Launching Installer ..." << endl;
 		int launch_exit_code = 0;
-		launch_exit_code = system( (foundJvm.getExecutable() + " -Xmx85M \"-Dorig.dir=" + owd + "\" -jar @installer.name@.jar" + (textMode?" text":"") ).c_str() );
+		launch_exit_code = system( (foundJvm.getExecutable() + " -Xmx85M -jar @installer.name@.jar" + (text_mode?" text":"") ).c_str() );
 
 		//report how it went
@@ -126,14 +175,6 @@
 
 	}
-	#endif
-
-	#ifdef CDROM
-		string cmd = "";
-		cmd.append( owd );
-		cmd.append( "/Java/Linux/jre/bin/java -Dorig.dir=\"" );
-		cmd.append( owd );
-		cmd.append( "\" -jar " );
-		cmd.append( owd );
-		cmd.append( "/Java/Jars/linux.jar" );
+	#else
+		string cmd = wd + "/Java/Linux/jre/bin/java -Dorig.dir=\"" + wd + "\" -jar " + wd + "/Java/Jars/linux.jar" + (text_mode?" text":"");
 		system( cmd.c_str() );
 	#endif
@@ -149,5 +190,5 @@
 
 }
-#ifdef WEB
+#ifndef CDROM
 bool extract_bundled_file( const char data[], int size, char* filename, bool make_executable) {
 
