Changeset 19720


Ignore:
Timestamp:
2009-06-02T15:50:42+12:00 (12 years ago)
Author:
oranfry
Message:

changed the linux wrapper to default to web installer wrapper, and added commandline options and usage screen

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release-kits/shared/linux/wrapper.cpp

    r19594 r19720  
    22#include <fstream>
    33#include <iomanip>
    4 #include <cstring>
     4#include <string.h>
    55#include <cstdlib>
     6#include <sstream>
    67using namespace std;
    78
    8 #ifdef WEB
     9#ifndef CDROM
    910#include "wrapper.h"
    1011#include "libsearch4j.h"
     
    1213#endif
    1314
     15void 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
    1428int main(int argc, char** argv) {
    1529
    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   
    1835    string scratch = (getenv("TMPDIR") == NULL) ? "/tmp" : getenv("TMPDIR");
    1936    string tempdir = scratch + "/greenstone-installer.tmp"; //temporary directory where we will store extracted files
    2037    bool succeeded = false;
    21     bool textMode = false;
     38    bool text_mode = false;
    2239
    2340    //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
    3081
    3182    //create the temp folder
     
    3384    succeeded = ( 0 == system( ("mkdir " + tempdir).c_str() ) );
    3485    if ( !succeeded ) {
    35         cout << "Failed to create the temp directory '" << tempdir << "'. " <<
     86        cerr << "Failed to create the temp directory '" << tempdir << "'. " <<
    3687         "Check that it does not already exist. Also check that you have write " <<
    3788         "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;
    4291        return 1;
    4392    }
    4493   
    45     #ifdef WEB
     94    #ifndef CDROM
    4695
    4796    string jarfile = tempdir + "/@installer.name@.jar"; //where we will store the jar file
     
    59108       
    60109    if ( !succeeded ) {
    61         cout << "Failed to extract one or more resources" << endl;
    62         cout << "This installer may not have sufficient file permissions to write it to disk" << endl;
    63         cout << "Or, the files may be corrupt or missing from this executable" << endl;
    64         cout << "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;
    65114        return 1;
    66115    }
     
    72121
    73122
    74     #ifdef WEB
     123    #ifndef CDROM
    75124    #ifdef java_is_bundled
    76125    succeeded = (system( "/bin/sh -c ./@java.installer@ > /dev/null" ) == 0);
     
    115164        cout << "Launching Installer ..." << endl;
    116165        int launch_exit_code = 0;
    117         launch_exit_code = system( (foundJvm.getExecutable() + " -Xmx85M \"-Dorig.dir=" + owd + "\" -jar @installer.name@.jar" + (textMode?" text":"") ).c_str() );
     166        launch_exit_code = system( (foundJvm.getExecutable() + " -Xmx85M -jar @installer.name@.jar" + (text_mode?" text":"") ).c_str() );
    118167
    119168        //report how it went
     
    126175
    127176    }
    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":"");
    138179        system( cmd.c_str() );
    139180    #endif
     
    149190
    150191}
    151 #ifdef WEB
     192#ifndef CDROM
    152193bool extract_bundled_file( const char data[], int size, char* filename, bool make_executable) {
    153194
Note: See TracChangeset for help on using the changeset viewer.