source: release-kits/shared/linux/wrapper.cpp@ 17464

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

a more compressed jre for linux releases

File size: 4.1 KB
Line 
1#include <iostream>
2#include <fstream>
3#include <iomanip>
4
5using namespace std;
6
7#include "wrapper.h"
8#include "libsearch4j.h"
9
10bool extract_bundled_file( const char[], int, char*, bool );
11
12int main(int argc, char** argv) {
13
14 string tempdir = "@[email protected]"; //temporary directory where we will store extracted files
15 string jarfile = tempdir + "/@[email protected]"; //where we will store the jar file
16 string javafile = tempdir + "/@java.installer@"; //where we will store the java tar file
17 bool succeeded = false;
18
19 //create the temp folder
20 cout << "Creating temp directory..." << endl;
21 succeeded = ( 0 == system( ("mkdir " + tempdir).c_str() ) );
22 if ( !succeeded ) {
23 cout << "Failed to write to create the temp directory '" << tempdir << "'" << endl;
24 cout << "Check that it does not already exist and try again" << endl;
25 cout << "Exiting" << endl;
26 return 1;
27 }
28
29 //extract files
30 cout << "Extracting installer jar..." << endl;
31 succeeded = extract_bundled_file( @installer.name@jar, sizeof(@installer.name@jar), (char*)jarfile.c_str(), false);
32
33 #ifdef java_is_bundled
34 cout << "Extracting bundled java..." << endl;
35 succeeded = extract_bundled_file( java, sizeof(java), (char*)javafile.c_str(), true ) && succeeded;
36 #endif
37
38 if ( !succeeded ) {
39 cout << "Failed to extract one or more resources" << endl;
40 cout << "This installer may not have sufficient file permissions to write it to disk" << endl;
41 cout << "Or, the files may be corrupt or missing from this executable" << endl;
42 cout << "Exiting" << endl;
43 return 1;
44 }
45
46 //change to the temp directory
47 chdir( tempdir.c_str() );
48
49 #ifdef java_is_bundled
50 succeeded = (system( "./@java.installer@" ) == 0);
51 if ( !succeeded ) {
52 cout << "Failed to extract the bundled java archive to the temp directory" << endl;
53 cout << "You need the tar program on your PATH" << endl;
54 cout << "Exiting" << endl;
55 return 1;
56 }
57 #endif
58
59 //check if an appropriate java is found
60 Jvm minimum; minimum.setVersionFromString( "@java.min.version@" );
61 string phint = "./@java.extracted@";
62 string hint = "";
63 Jvm foundJvm;
64 bool jvmFound = find( foundJvm, true, minimum, phint, hint, false );
65
66 //if the jvm was not found, report not found
67 if ( !jvmFound ) {
68
69 //did not find a good java
70 cout << "Greenstone requires java @java.min.version@ or greater." << endl;
71
72 //tell them if java is absent or just too old
73 Jvm tmpJvm;
74 if ( find( tmpJvm, false, minimum, phint, hint, false ) ) {
75 cout << "You have java, but it is too old." << endl;
76 } else {
77 cout << "Could not find java on your system." << endl;
78 }
79
80 cout << "Install java (@java.min.version@ or greater) and set JAVA_HOME or JRE_HOME, and try again" << endl;
81 #ifndef java_is_bundled
82 cout << "Or, download a greentsone3 installer with bundled java and use that instead of this one" << endl;
83 #endif
84
85 //if we have found it, launch the installer
86 } else {
87
88 cout << "Launching Installer ..." << endl;
89 int launch_exit_code = 0;
90 launch_exit_code = system( (foundJvm.getExecutable() + " -Xmx85M -jar @[email protected]").c_str() );
91
92 //report how it went
93 if ( launch_exit_code == 0 ) {
94 cout << "Setup complete" << endl;
95 } else {
96 cout << "The installer exited with an error" << endl;
97 cout << "Greenstone may not be correctly installed" << endl;
98 }
99
100 }
101
102 //change back to the original directory
103 chdir("..");
104
105 //delete the temp files
106 cout << "Deleting the temp directory" << endl;
107 system( ("rm -rf " + tempdir).c_str() );
108
109 return 0;
110
111}
112
113bool extract_bundled_file( const char data[], int size, char* filename, bool make_executable) {
114
115 if ( size == 0 ) return false;
116
117 //delete the file if it exists
118 remove( filename );
119
120 //open the file
121 fstream binary_file( filename, ios::out|ios::binary );
122 if ( !binary_file.good() ) {
123 binary_file.close();
124 return false;
125 }
126
127 //write the file
128 binary_file.write( data, size );
129 if ( !binary_file.good() ) {
130 binary_file.close();
131 return false;
132 }
133
134 //close the file
135 binary_file.close();
136 if ( !binary_file.good() ) {
137 binary_file.close();
138 return false;
139 }
140
141 if ( make_executable ) {
142 string command = "chmod a+x " + string(filename);
143 system( command.c_str() );
144 }
145
146 return true;
147
148}
Note: See TracBrowser for help on using the repository browser.