Ignore:
Timestamp:
2008-03-28T12:43:46+13:00 (16 years ago)
Author:
oranfry
Message:

changes to the wrapper and installer logic, and a few changes to init and compile stuff

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release-kits/lirk3/wrapper/mywrapper.c

    r14982 r15142  
    22#include <fstream>
    33#include <iomanip>
     4
    45using namespace std;
    56
    67#include "mywrapper.h"
    78
    8 bool extract_bundled_file( const char[], int, char* );
     9bool extract_bundled_file( const char[], int, char*, bool );
    910
    1011int main(int argc, char** argv) {
     
    1213    string tempdir = (string)argv[0] + ".tmp"; //temporary directory where we will store extracted files
    1314    string jarfile = tempdir + "/greenstone3.jar"; //where we will store the jar file
     15    string search4jfile = tempdir + "/search4j"; //where we will store the jar file
    1416    bool succeeded = false;
    1517
     
    2527
    2628    //extract files
    27     cout << "Extracting JAR file..." << endl;
    28     succeeded = extract_bundled_file( greenstone3jar, sizeof(greenstone3jar), (char*)jarfile.c_str() );
     29    cout << "Extracting installer jar..." << endl;
     30    succeeded = extract_bundled_file( greenstone3jar, sizeof(greenstone3jar), (char*)jarfile.c_str(), false);
    2931    if ( !succeeded ) {
    3032        cout << "failed" << endl;
    3133        cout << "Failed to extract the JAR file to '" << jarfile << "'" << endl;
    32         cout << "The JAR file may have been bundled with this executable incorrectly" << endl;
    33         cout << "Or this program may not have sufficient file permissions to write it to disk" << endl;
     34        cout << "The file may be corrupt or missing" << endl;
     35        cout << "Or this installer may not have sufficient file permissions to write it to disk" << endl;
    3436        cout << "Exiting" << endl;
    3537        return 1;
    3638    }
    3739
    38     //run the jar
    39     cout << "Running the jar" << endl;
    40     system( ("java -jar " + jarfile).c_str() );
     40    cout << "Extracting search4j tool..." << endl;
     41    succeeded = extract_bundled_file( search4j, sizeof(search4j), (char*)search4jfile.c_str(), true );
     42    if ( !succeeded ) {
     43        cout << "failed" << endl;
     44        cout << "Failed to extract the search4j tool to '" << jarfile << "'" << endl;
     45        cout << "The file may be corrupt or missing" << endl;
     46        cout << "Or this installer may not have sufficient file permissions to write it to disk" << endl;
     47        cout << "Exiting" << endl;
     48        return 1;
     49    }
     50
     51
     52    //change to the temp directory
     53    chdir( tempdir.c_str() );
     54
     55
     56    //check if an appropriate java is found
     57    bool jvmFound = (system( "./search4j -m @java.min.version@ -h ./@java.extracted@" ) == 0);
     58
     59    //if the jvm was not found, try to fix it and find it
     60    if ( !jvmFound ) {
     61        //did not find a good java
     62        cout << "Greenstone requires java @java.min.version@ or greater" << endl;
     63       
     64        //tell them if java is absent or just too old
     65        if ( system( "./search4j -h ./@java.extracted@" ) == 0 ) {
     66            cout << "Your java is too old." << endl;
     67        } else {
     68            cout << "Could not find java." << endl;
     69        }
     70       
     71        //is this an installer with the bundled JRE?
     72       
     73        #ifdef java_is_bundled
     74            //yes, JRE is bundled
     75            cout
     76                << "This installer comes bundled with a suitible version of java: " << endl
     77                << "   @java.installer@" << endl
     78                << "Do you want to install this java? (y/n)" << endl;
     79            char r[1024]; cin >> r;
     80            if ( strcmp( r, "y" ) == 0 || strcmp( r, "Y" ) == 0) {
     81                extract_bundled_file( java, sizeof(java), (char*)"@java.installer@", true );
     82                system( "./@java.installer@" );
     83                jvmFound = true; //assume the java installation went well
     84            }
     85        #endif
     86
     87        #ifndef java_is_bundled
     88            //no, JRE is not bundled
     89            cout << "Install java (@java.min.version@ or greater) and set JAVA_HOME or JRE_HOME, and try again" << endl;
     90            cout << "Or, download a greentsone3 installer with bundled java and use that instead of this one" << endl;
     91        #endif
     92    }
     93
     94    //if we have found it by now, launch the installer
     95    if ( jvmFound ) {
     96        cout << "Launching Installer ..." << endl;
     97        int launch_exit_code = 0;
     98        launch_exit_code = system("./search4j -m @java.min.version@ -l greenstone3.jar -h ./@java.extracted@");
     99
     100        //report how it went
     101        if ( launch_exit_code == 0 ) {
     102            cout << "Setup complete" << endl;
     103        } else {
     104            cout << "Still could not find a suitible version of java" << endl;
     105            cout << "Please install java, set JAVA_HOME or JRE_HOME, and try again" << endl;
     106        }
     107
     108    }
     109
     110    //change back to the original directory
     111    chdir("..");
    41112
    42113    //delete the temp files
    43114    cout << "Deleting the temp directory" << endl;
    44115    system( ("rm -rf " + tempdir).c_str() );
    45     system( "rm ant.install.log" );
    46116
    47117
     
    50120}
    51121
    52 bool extract_bundled_file( const char data[], int size, char* filename ) {
     122bool extract_bundled_file( const char data[], int size, char* filename, bool make_executable) {
     123
     124    if ( size == 0 ) return false;
    53125
    54126    //delete the file if it exists
     
    76148    }
    77149
     150    if ( make_executable ) {
     151        string command = "chmod a+x " + string(filename);
     152        system( command.c_str() );
     153    }
     154
    78155    return true;
    79156
Note: See TracChangeset for help on using the changeset viewer.