Changeset 19720 for release-kits/shared/linux/wrapper.cpp
- Timestamp:
- 2009-06-02T15:50:42+12:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
release-kits/shared/linux/wrapper.cpp
r19594 r19720 2 2 #include <fstream> 3 3 #include <iomanip> 4 #include < cstring>4 #include <string.h> 5 5 #include <cstdlib> 6 #include <sstream> 6 7 using namespace std; 7 8 8 #if def WEB9 #ifndef CDROM 9 10 #include "wrapper.h" 10 11 #include "libsearch4j.h" … … 12 13 #endif 13 14 15 void usage( char* progname, int exitvalue = -1 ) { 16 cerr 17 << "Usage: " << progname << " [OPTIONS]" << endl 18 << "OPTIONS: " << endl 19 << " -h, -help Display this usage message" << endl 20 << " -text Do a non-graphical command line installation" << endl; 21 #ifdef CDROM 22 cerr << " -wd PATH Look for the CD-ROM at PATH" << endl; 23 #endif 24 25 exit( exitvalue ); 26 } 27 14 28 int main(int argc, char** argv) { 15 29 16 char owd[1024]; 17 getcwd(owd, sizeof(owd)); 30 char wdc[1024]; 31 getcwd(wdc, sizeof(wdc)); 32 string wd = ""; 33 wd.append( wdc ); 34 18 35 string scratch = (getenv("TMPDIR") == NULL) ? "/tmp" : getenv("TMPDIR"); 19 36 string tempdir = scratch + "/greenstone-installer.tmp"; //temporary directory where we will store extracted files 20 37 bool succeeded = false; 21 bool text Mode = false;38 bool text_mode = false; 22 39 23 40 //parse arguments 24 for ( int i=0; i<argc; i++ ) { 25 if ( strcmp( argv[i], "text" ) == 0 ) { 26 textMode = true; 27 } 28 } 29 41 string a; 42 for ( int i=1; i<argc; i++ ) { 43 a = argv[i]; 44 if ( a.compare("-wd") == 0 ) { 45 wd = ""; 46 wd.append( argv[++i] ); 47 } else if ( a.compare("-h") == 0 || a.compare("-help") == 0 || a.compare("--help") == 0) { 48 usage( argv[0], 0 ); 49 } else if ( a.compare("-text") == 0 || a.compare("text") == 0 ) { 50 text_mode = true; 51 } else { 52 cerr << "Unrecognised option '" << a << "'" << endl; 53 usage(argv[0]); 54 } 55 } 56 57 #ifdef CDROM 58 //ensure working directory is correct 59 FILE* pFile; 60 pFile = fopen( (wd+"/Software/core/all/uninst.jar").c_str(), "r"); 61 if ( pFile == NULL ) { 62 cerr << "Could not find cdrom at '" << wd << "'." << endl; 63 cerr << "Please enter the path the CDROM [/media/cdrom]: "; 64 getline(cin, wd); 65 if ( wd.compare("") == 0 ) { 66 wd = "/media/cdrom"; 67 } 68 } else { 69 fclose(pFile); 70 } 71 72 pFile = fopen( (wd+"/Software/core/all/uninst.jar").c_str(), "r"); 73 if ( pFile == NULL ) { 74 cerr << "Could not find cdrom at '"<< wd << "'." << endl; 75 cerr << "Please run the installer again" << endl; 76 exit(-1); 77 } else { 78 fclose(pFile); 79 } 80 #endif 30 81 31 82 //create the temp folder … … 33 84 succeeded = ( 0 == system( ("mkdir " + tempdir).c_str() ) ); 34 85 if ( !succeeded ) { 35 c out<< "Failed to create the temp directory '" << tempdir << "'. " <<86 cerr << "Failed to create the temp directory '" << tempdir << "'. " << 36 87 "Check that it does not already exist. Also check that you have write " << 37 88 "permissions to '" << scratch << "', or set the environment variable TMPDIR to " << 38 "a directory where you do have write permissions." << 39 endl; 40 41 cout << "Exiting" << endl; 89 "a directory where you do have write permissions." << endl << 90 "Exiting" << endl; 42 91 return 1; 43 92 } 44 93 45 #if def WEB94 #ifndef CDROM 46 95 47 96 string jarfile = tempdir + "/@[email protected]"; //where we will store the jar file … … 59 108 60 109 if ( !succeeded ) { 61 c out<< "Failed to extract one or more resources" << endl;62 c out<< "This installer may not have sufficient file permissions to write it to disk" << endl;63 c out<< "Or, the files may be corrupt or missing from this executable" << endl;64 c out<< "Exiting" << endl;110 cerr << "Failed to extract one or more resources" << endl; 111 cerr << "This installer may not have sufficient file permissions to write it to disk" << endl; 112 cerr << "Or, the files may be corrupt or missing from this executable" << endl; 113 cerr << "Exiting" << endl; 65 114 return 1; 66 115 } … … 72 121 73 122 74 #if def WEB123 #ifndef CDROM 75 124 #ifdef java_is_bundled 76 125 succeeded = (system( "/bin/sh -c ./@java.installer@ > /dev/null" ) == 0); … … 115 164 cout << "Launching Installer ..." << endl; 116 165 int launch_exit_code = 0; 117 launch_exit_code = system( (foundJvm.getExecutable() + " -Xmx85M \"-Dorig.dir=" + owd + "\" -jar @[email protected]" + (textMode?" text":"") ).c_str() );166 launch_exit_code = system( (foundJvm.getExecutable() + " -Xmx85M -jar @[email protected]" + (text_mode?" text":"") ).c_str() ); 118 167 119 168 //report how it went … … 126 175 127 176 } 128 #endif 129 130 #ifdef CDROM 131 string cmd = ""; 132 cmd.append( owd ); 133 cmd.append( "/Java/Linux/jre/bin/java -Dorig.dir=\"" ); 134 cmd.append( owd ); 135 cmd.append( "\" -jar " ); 136 cmd.append( owd ); 137 cmd.append( "/Java/Jars/linux.jar" ); 177 #else 178 string cmd = wd + "/Java/Linux/jre/bin/java -Dorig.dir=\"" + wd + "\" -jar " + wd + "/Java/Jars/linux.jar" + (text_mode?" text":""); 138 179 system( cmd.c_str() ); 139 180 #endif … … 149 190 150 191 } 151 #if def WEB192 #ifndef CDROM 152 193 bool extract_bundled_file( const char data[], int size, char* filename, bool make_executable) { 153 194
Note:
See TracChangeset
for help on using the changeset viewer.