summaryrefslogtreecommitdiff
path: root/javainstaller2/src/JavaSetup/org/openoffice/setup/InstallerHelper/SolarisHelper.java
blob: a90c2aa230b69d2496c6effd4c5f4045b43ff33d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * 
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: SolarisHelper.java,v $
 * $Revision: 1.7 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

package org.openoffice.setup.InstallerHelper;

import org.openoffice.setup.InstallData;
import org.openoffice.setup.ResourceManager;
import org.openoffice.setup.SetupData.PackageDescription;
import org.openoffice.setup.Util.Controller;
import org.openoffice.setup.Util.Converter;
import org.openoffice.setup.Util.ExecuteProcess;
import org.openoffice.setup.Util.Informer;
import org.openoffice.setup.Util.LogManager;
import org.openoffice.setup.Util.SystemManager;
import java.io.File;
import java.util.HashMap;
import java.util.Vector;

public class SolarisHelper {
    
    public SolarisHelper() {
    }
    
    private void createLocalTempDir() {
        String mktempString = "/usr/bin/mktemp";
        File mktemp = new File(mktempString);
        if ( mktemp.exists() ) {
            // this is Solaris 10
            LogManager.setCommandsHeaderLine("Preparing Solaris 10 user installation");
            InstallData data = InstallData.getInstance();
            String mktempCommand = mktempString + " -d";
            String[] mktempCommandArray = new String[2];
            mktempCommandArray[0] = mktempString;
            mktempCommandArray[1] = "-d";
            Vector returnVector = new Vector();
            Vector returnErrorVector = new Vector();
            int returnValue = ExecuteProcess.executeProcessReturnVector(mktempCommandArray, returnVector, returnErrorVector);
            String uniqueLocalDir = (String) returnVector.get(0);
                        
            data.setLocalTempPath(uniqueLocalDir);
            
            String log = mktempCommand + "<br><b>Returns: " + uniqueLocalDir + "</b><br>";
            LogManager.addCommandsLogfileComment(log);
            
            String installRoot = data.getInstallDir();
            File installRootTemp = new File(installRoot, "tmp");
            
            if ( installRootTemp.exists() ) {
                SystemManager.removeDirectory(installRootTemp);
            }
            
            String linkCommand = "ln -s " + uniqueLocalDir + " " + installRootTemp.getPath();
            String[] linkCommandArray = new String[4];
            linkCommandArray[0] = "ln";
            linkCommandArray[1] = "-s";
            linkCommandArray[2] = uniqueLocalDir;
            linkCommandArray[3] = installRootTemp.getPath();
            
            // Vector returnVector = new Vector();
            returnValue = ExecuteProcess.executeProcessReturnValue(linkCommandArray);

            log = linkCommand + "<br><b>Returns: " + returnValue + "</b><br>";
            LogManager.addCommandsLogfileComment(log);
        }
    }
    
    private void removeLocalTempDir() {
        InstallData data = InstallData.getInstance();
        
        if ( data.getLocalTempPath() != null ) {
            File installRootTemp = new File(data.getInstallDir(), "tmp");
            if ( installRootTemp.exists() ) {
                installRootTemp.delete(); // removing the link
                SystemManager.createDirectory(installRootTemp);
            }            

            File localTemp = new File(data.getLocalTempPath());
            if ( localTemp.exists() ) {
                SystemManager.removeDirectory(localTemp);
            }
        }
    }
    
    private Vector getAdminFileContent(boolean relocatable) {

        Vector adminFile = new Vector();
        InstallData data = InstallData.getInstance();
        
        // if ( relocatable ) {
        //     String installDir =  data.getInstallDir();
        //     // installDir = installDir.replace(" ", "\\ ");
        //     String baseDirLine = "basedir=" + installDir;
        //     adminFile.add(baseDirLine);
        // }

        String conflictLine = "conflict=quit";
        if ( data.isUserInstallation() ) { conflictLine = "conflict=nocheck"; }        
        adminFile.add(conflictLine);

        String runlevelLine = "runlevel=nocheck";
        adminFile.add(runlevelLine);

        String setuidLine = "setuid=quit";
        if ( data.isUserInstallation() ) { setuidLine = "setuid=nocheck"; }        
        adminFile.add(setuidLine);

        String actionLine = "action=nocheck";
        adminFile.add(actionLine);

        String partialLine = "partial=quit";
        if ( data.isUserInstallation() ) { partialLine = "partial=nocheck"; }        
        adminFile.add(partialLine);

        String instanceLine = "instance=unique";
        adminFile.add(instanceLine);
        
        // String idependLine = "idepend=quit";
        String idependLine = "idepend=nocheck";
        // if ( data.isUserInstallation() ) { idependLine = "idepend=nocheck"; }        
        adminFile.add(idependLine);

        // String rdependLine = "rdepend=nocheck";
        String rdependLine = "rdepend=quit";
        if ( data.isUserInstallation() ) { rdependLine = "rdepend=nocheck"; }        
        adminFile.add(rdependLine);

        String spaceLine = "space=quit";
        if ( data.isUserInstallation() ) { spaceLine = "space=nocheck"; }        
        adminFile.add(spaceLine);
        
        return adminFile;
    }

    private String getMainVersion (String version) {
        String mainVersion = null;

        int pos = version.indexOf(",");
        if ( pos > -1 ) {
            mainVersion = version.substring(0, pos);
        }

        return mainVersion;
    }
 
    private String getPackageRevision(String version) {
        String revision = null;

        int pos = version.indexOf("=");
        if ( pos > -1 ) {
            revision = version.substring(pos + 1, version.length() );
        }

        return revision;
    }
    
    private Vector getVectorOfNumbers(String version) {
        Vector numbers = new Vector();
        int pos = -1;
        // getting number from a string in format 2.0.0
        do {
            pos = version.indexOf(".");
            if ( pos > -1 ) {
                String number = version.substring(0, pos);
                version = version.substring(pos + 1, version.length());
                numbers.add(number);
            }
        } while ( pos > -1 );

        numbers.add(version);        
        return numbers;
    }
    
    private int getMinimum(int a, int b) {
        int minimum;

        if ( a < b ) {
             minimum = a;
        } else {
            minimum = b;
        }

        return minimum;
    }
    
    private String compareVersion(String firstVersion, String secondVersion) {
        // comparing strings with syntax 2.0.0
        String comparison = "bothPackagesAreEqual";        
        Vector firstVector = getVectorOfNumbers(firstVersion);
        Vector secondVector = getVectorOfNumbers(secondVersion);

        int firstLength = firstVector.size();
        int secondLength = secondVector.size();
        int minimum = getMinimum(firstLength, secondLength);

        for (int i = 0; i < minimum; i++) {
            String firstS = (String)firstVector.get(i);
            String secondS = (String)secondVector.get(i);

            int first = Integer.parseInt(firstS);
            int second_ = Integer.parseInt(secondS);

            if ( second_ > first ) {
                comparison = "firstPackageIsOlder";
                break;
            } else if ( second_ < first ) {
                comparison = "secondPackageIsOlder";
                break;                
            }
        }

        return comparison;
    }

    public void saveModulesLogFile(InstallData data) {
        if ( data.logModuleStates() ) {
            Vector logContent = LogManager.getModulesLogFile();
            File baseDir = new File(data.getInstallDefaultDir(), data.getProductDir());
            File uninstallDir = new File(baseDir, data.getUninstallDirName());
            File modulesLogFile = new File(uninstallDir, "moduleSettingsLog.txt");        
            // System.err.println("Saving file: " + modulesLogFile.getPath());
            SystemManager.saveCharFileVector(modulesLogFile.getPath(), logContent);
        }    
    }

    public void removeSolarisLockFile() {
        String lockFileName = "/tmp/.ai.pkg.zone.lock-afdb66cf-1dd1-11b2-a049-000d560ddc3e";
        File lockFile = new File(lockFileName);
        
        if ( lockFile.exists() ) {
            // System.err.println("Found file: " + lockFileName);
            boolean deleted = lockFile.delete();
        }        
    }
    
    public String getSolarisDatabasePath(InstallData data) {
        String databasePath = null;
        databasePath = data.getInstallDir();
        return databasePath;
    }

    public void createAdminFile(boolean relocatable) {
        InstallData data = InstallData.getInstance();
        Vector removeFiles = data.getRemoveFiles();
        String adminFileName = "";
        
        if ( relocatable ) {
            adminFileName = "adminFileReloc";
        } else {
            adminFileName = "adminFileNoReloc";            
        }

        Vector fileContent = getAdminFileContent(relocatable);        
        File adminFile = new File(data.getInstallDir(), adminFileName);
        String completeAdminFileName = adminFile.getPath();

        if ( relocatable ) {
            data.setAdminFileNameReloc(completeAdminFileName);
        } else {
            data.setAdminFileNameNoReloc(completeAdminFileName);            
        }
        
        if ( ! adminFile.exists() ) {
            // only saving, if it did not exist
            SystemManager.saveCharFileVector(completeAdminFileName, fileContent);
            // only removing file in aborted installation, if it was created before
            removeFiles.add(completeAdminFileName);
        }

        // File dumpFile = new File(data.getInstallDir(), "dumpFile");
        // String dumpFileName = dumpFile.getPath();
        // SystemManager.dumpFile(adminFileName, dumpFileName);
    }

    // for user installations an environment hashmap is used
    public void setEnvironmentForUserInstall() {
        InstallData data = InstallData.getInstance();
        HashMap env = SystemManager.getEnvironmentHashMap();
        env.put("LD_PRELOAD_32", data.getGetUidPath());
        data.setShellEnvironment(env);
    }
    
    public String getVersionString(Vector returnVector) {
        String versionString = null;
        String versionLine = null;
        
        for (int i = 0; i < returnVector.size(); i++) {
            String line = (String) returnVector.get(i);
            int pos = line.indexOf("REV=");
            if ( pos > -1 ) {
                versionLine = line;
                break;
            }
        }

        if ( versionLine != null ) {
            versionLine = versionLine.trim();
            int pos = versionLine.lastIndexOf(" ");
            versionString = versionLine.substring(pos + 1, versionLine.length());
        }
        
        return versionString;
    }

    public boolean comparePackageVersions(String firstPackageVersion, String secondPackageVersion) {
       // Analyzing strings: version, 2.0.0,REV=106.2005.05.26

        boolean firstPackageIsOlder = false;
        String comparison = null;

        String firstPackageMainVersion = getMainVersion(firstPackageVersion); // 2.0.0
        String secondPackageMainVersion = getMainVersion(secondPackageVersion); // 2.0.0

        if (( firstPackageMainVersion != null ) && ( secondPackageMainVersion != null )) {
            comparison = compareVersion(firstPackageMainVersion, secondPackageMainVersion);
        }
        
        if ( comparison.equals("firstPackageIsOlder") ) {
            firstPackageIsOlder = true;
        } else if ( comparison.equals("secondPackageIsOlder") ) {
            firstPackageIsOlder = false;
        } else if ( comparison.equals("bothPackagesAreEqual") ) {
            String firstPackageRevision = getPackageRevision(firstPackageVersion); // 106.2005.05.26
            String secondPackageRevision = getPackageRevision(secondPackageVersion); // 106.2005.05.26

            if (( firstPackageRevision != null ) && ( secondPackageRevision != null )) {
                comparison = compareVersion(firstPackageRevision, secondPackageRevision);
                if ( comparison.equals("firstPackageIsOlder") ) {
                    firstPackageIsOlder = true;
                } else {                    
                    firstPackageIsOlder = false;
                }
            }
        }

        // If version is equal, the patchlevel has to be analyzed
        // -> pkginfo does not offer this information
        // -> looking into file <root>/opt/var/sadm/pkg/<package>/pkginfo?

        return firstPackageIsOlder;
    }
    
}