#include #include #include #include using namespace std; #include "wrapper.h" #include "libsearch4j.h" bool extract_bundled_file( const char[], int, char*, bool ); int main(int argc, char** argv) { char owd[1024]; getcwd(owd, sizeof(owd)); string scratch = (getenv("TMPDIR") == NULL) ? "/tmp" : getenv("TMPDIR"); string tempdir = scratch + "/@installer.name@.tmp"; //temporary directory where we will store extracted files string jarfile = tempdir + "/@installer.name@.jar"; //where we will store the jar file string javafile = tempdir + "/@java.installer@"; //where we will store the java tar file bool succeeded = false; bool textMode = false; //parse arguments for ( int i=0; i /dev/null" ) == 0); succeeded = succeeded && ( system( "tar -xf jre.tar" ) == 0 ); if ( !succeeded ) { cout << "Failed to extract the bundled java archive to the temp directory" << endl; cout << "You need the tar program on your PATH" << endl; cout << "Exiting" << endl; return 1; } #endif //check if an appropriate java is found Jvm minimum; minimum.setVersionFromString( "@java.min.version@" ); string phint = "./@java.extracted@"; string hint = ""; Jvm foundJvm; bool jvmFound = find( foundJvm, true, minimum, false, false, phint, hint, false ); //if the jvm was not found, report not found if ( !jvmFound ) { //did not find a good java cout << "Greenstone requires java @java.min.version@ or greater." << endl; //tell them if java is absent or just too old Jvm tmpJvm; if ( find( tmpJvm, false, minimum, false, false, phint, hint, false ) ) { cout << "You have java, but it is too old." << endl; } else { cout << "Could not find java on your system." << endl; } cout << "Install java (@java.min.version@ or greater) and set JAVA_HOME or JRE_HOME, and try again" << endl; #ifndef java_is_bundled cout << "Or, download a greentsone3 installer with bundled java and use that instead of this one" << endl; #endif //if we have found it, launch the installer } else { 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() ); //report how it went if ( launch_exit_code == 0 ) { cout << "Setup complete" << endl; } else { cout << "The installer exited with an error" << endl; cout << "Greenstone may not be correctly installed" << endl; } } //change to the scratch dir for the following operation chdir(scratch.c_str()); //delete the temp files cout << "Deleting the temp directory" << endl; system( ("rm -rf " + tempdir).c_str() ); return 0; } bool extract_bundled_file( const char data[], int size, char* filename, bool make_executable) { if ( size == 0 ) return false; //delete the file if it exists remove( filename ); //open the file fstream binary_file( filename, ios::out|ios::binary ); if ( !binary_file.good() ) { binary_file.close(); return false; } //write the file binary_file.write( data, size ); if ( !binary_file.good() ) { binary_file.close(); return false; } //close the file binary_file.close(); if ( !binary_file.good() ) { binary_file.close(); return false; } if ( make_executable ) { string command = "chmod a+x " + string(filename); system( command.c_str() ); } return true; }