source: release-kits/lirk3/wrapper/mywrapper.c@ 15205

Last change on this file since 15205 was 15205, checked in by oranfry, 16 years ago

some updates to make the release kit produce nicer installers

File size: 4.7 KB
RevLine 
[14982]1#include <iostream>
2#include <fstream>
3#include <iomanip>
[15142]4
[14982]5using namespace std;
6
7#include "mywrapper.h"
8
[15142]9bool extract_bundled_file( const char[], int, char*, bool );
[14982]10
11int main(int argc, char** argv) {
12
13 string tempdir = (string)argv[0] + ".tmp"; //temporary directory where we will store extracted files
14 string jarfile = tempdir + "/greenstone3.jar"; //where we will store the jar file
[15142]15 string search4jfile = tempdir + "/search4j"; //where we will store the jar file
[14982]16 bool succeeded = false;
17
18 //create the temp folder
19 cout << "Creating temp directory" << endl;
20 succeeded = ( 0 == system( ("mkdir " + tempdir).c_str() ) );
21 if ( !succeeded ) {
22 cout << "Failed to write to create the temp directory '" << tempdir << "'" << endl;
23 cout << "Check that it does not already exist and try again" << endl;
24 cout << "Exiting" << endl;
25 return 1;
26 }
27
28 //extract files
[15142]29 cout << "Extracting installer jar..." << endl;
30 succeeded = extract_bundled_file( greenstone3jar, sizeof(greenstone3jar), (char*)jarfile.c_str(), false);
[14982]31 if ( !succeeded ) {
32 cout << "failed" << endl;
33 cout << "Failed to extract the JAR file to '" << jarfile << "'" << endl;
[15142]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;
[14982]36 cout << "Exiting" << endl;
37 return 1;
38 }
39
[15142]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 }
[14982]50
[15142]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 {
[15205]68 cout << "Could not find java on your system." << endl;
[15142]69 }
70
71 //is this an installer with the bundled JRE?
72
73 #ifdef java_is_bundled
74 //yes, JRE is bundled
[15205]75 /*
[15142]76 cout
77 << "This installer comes bundled with a suitible version of java: " << endl
78 << " @java.installer@" << endl
79 << "Do you want to install this java? (y/n)" << endl;
80 char r[1024]; cin >> r;
81 if ( strcmp( r, "y" ) == 0 || strcmp( r, "Y" ) == 0) {
[15205]82 */
83
84 cout << "Using bundled java." << endl;
85 extract_bundled_file( java, sizeof(java), (char*)"@java.installer@", true );
86 system( "tar -xzf @java.installer@" );
87 jvmFound = true; //assume the java installation went well
88
89 /*}*/
[15142]90 #endif
91
92 #ifndef java_is_bundled
93 //no, JRE is not bundled
94 cout << "Install java (@java.min.version@ or greater) and set JAVA_HOME or JRE_HOME, and try again" << endl;
95 cout << "Or, download a greentsone3 installer with bundled java and use that instead of this one" << endl;
96 #endif
97 }
98
99 //if we have found it by now, launch the installer
100 if ( jvmFound ) {
101 cout << "Launching Installer ..." << endl;
102 int launch_exit_code = 0;
103 launch_exit_code = system("./search4j -m @java.min.version@ -l greenstone3.jar -h ./@java.extracted@");
104
105 //report how it went
106 if ( launch_exit_code == 0 ) {
107 cout << "Setup complete" << endl;
108 } else {
109 cout << "Still could not find a suitible version of java" << endl;
110 cout << "Please install java, set JAVA_HOME or JRE_HOME, and try again" << endl;
111 }
112
113 }
114
115 //change back to the original directory
116 chdir("..");
117
[14982]118 //delete the temp files
119 cout << "Deleting the temp directory" << endl;
120 system( ("rm -rf " + tempdir).c_str() );
121
122
123 return 0;
124
125}
126
[15142]127bool extract_bundled_file( const char data[], int size, char* filename, bool make_executable) {
[14982]128
[15142]129 if ( size == 0 ) return false;
130
[14982]131 //delete the file if it exists
132 remove( filename );
133
134 //open the file
135 fstream binary_file( filename, ios::out|ios::binary );
136 if ( !binary_file.good() ) {
137 binary_file.close();
138 return false;
139 }
140
141 //write the file
142 binary_file.write( data, size );
143 if ( !binary_file.good() ) {
144 binary_file.close();
145 return false;
146 }
147
148 //close the file
149 binary_file.close();
150 if ( !binary_file.good() ) {
151 binary_file.close();
152 return false;
153 }
154
[15142]155 if ( make_executable ) {
156 string command = "chmod a+x " + string(filename);
157 system( command.c_str() );
158 }
159
[14982]160 return true;
161
162}
Note: See TracBrowser for help on using the repository browser.