1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.setup.InstallerHelper; 25 26 import org.openoffice.setup.InstallData; 27 import org.openoffice.setup.ResourceManager; 28 import org.openoffice.setup.SetupData.PackageDescription; 29 import org.openoffice.setup.Util.Controller; 30 import org.openoffice.setup.Util.Converter; 31 import org.openoffice.setup.Util.ExecuteProcess; 32 import org.openoffice.setup.Util.Informer; 33 import org.openoffice.setup.Util.LogManager; 34 import org.openoffice.setup.Util.SystemManager; 35 import java.io.File; 36 import java.util.HashMap; 37 import java.util.Vector; 38 39 public class SolarisHelper { 40 SolarisHelper()41 public SolarisHelper() { 42 } 43 createLocalTempDir()44 private void createLocalTempDir() { 45 String mktempString = "/usr/bin/mktemp"; 46 File mktemp = new File(mktempString); 47 if ( mktemp.exists() ) { 48 // this is Solaris 10 49 LogManager.setCommandsHeaderLine("Preparing Solaris 10 user installation"); 50 InstallData data = InstallData.getInstance(); 51 String mktempCommand = mktempString + " -d"; 52 String[] mktempCommandArray = new String[2]; 53 mktempCommandArray[0] = mktempString; 54 mktempCommandArray[1] = "-d"; 55 Vector returnVector = new Vector(); 56 Vector returnErrorVector = new Vector(); 57 int returnValue = ExecuteProcess.executeProcessReturnVector(mktempCommandArray, returnVector, returnErrorVector); 58 String uniqueLocalDir = (String) returnVector.get(0); 59 60 data.setLocalTempPath(uniqueLocalDir); 61 62 String log = mktempCommand + "<br><b>Returns: " + uniqueLocalDir + "</b><br>"; 63 LogManager.addCommandsLogfileComment(log); 64 65 String installRoot = data.getInstallDir(); 66 File installRootTemp = new File(installRoot, "tmp"); 67 68 if ( installRootTemp.exists() ) { 69 SystemManager.removeDirectory(installRootTemp); 70 } 71 72 String linkCommand = "ln -s " + uniqueLocalDir + " " + installRootTemp.getPath(); 73 String[] linkCommandArray = new String[4]; 74 linkCommandArray[0] = "ln"; 75 linkCommandArray[1] = "-s"; 76 linkCommandArray[2] = uniqueLocalDir; 77 linkCommandArray[3] = installRootTemp.getPath(); 78 79 // Vector returnVector = new Vector(); 80 returnValue = ExecuteProcess.executeProcessReturnValue(linkCommandArray); 81 82 log = linkCommand + "<br><b>Returns: " + returnValue + "</b><br>"; 83 LogManager.addCommandsLogfileComment(log); 84 } 85 } 86 removeLocalTempDir()87 private void removeLocalTempDir() { 88 InstallData data = InstallData.getInstance(); 89 90 if ( data.getLocalTempPath() != null ) { 91 File installRootTemp = new File(data.getInstallDir(), "tmp"); 92 if ( installRootTemp.exists() ) { 93 installRootTemp.delete(); // removing the link 94 SystemManager.createDirectory(installRootTemp); 95 } 96 97 File localTemp = new File(data.getLocalTempPath()); 98 if ( localTemp.exists() ) { 99 SystemManager.removeDirectory(localTemp); 100 } 101 } 102 } 103 getAdminFileContent(boolean relocatable, boolean rdepends)104 private Vector getAdminFileContent(boolean relocatable, boolean rdepends) { 105 106 Vector adminFile = new Vector(); 107 InstallData data = InstallData.getInstance(); 108 109 // if ( relocatable ) { 110 // String installDir = data.getInstallDir(); 111 // // installDir = installDir.replace(" ", "\\ "); 112 // String baseDirLine = "basedir=" + installDir; 113 // adminFile.add(baseDirLine); 114 // } 115 116 String mailLine = "mail="; 117 adminFile.add(mailLine); 118 119 String conflictLine = "conflict=nochange"; 120 if ( data.isUserInstallation() ) { conflictLine = "conflict=nochange"; } 121 adminFile.add(conflictLine); 122 123 String runlevelLine = "runlevel=nocheck"; 124 adminFile.add(runlevelLine); 125 126 String setuidLine = "setuid=quit"; 127 if ( data.isUserInstallation() ) { setuidLine = "setuid=nocheck"; } 128 adminFile.add(setuidLine); 129 130 String actionLine = "action=nocheck"; 131 adminFile.add(actionLine); 132 133 String partialLine = "partial=quit"; 134 if ( data.isUserInstallation() ) { partialLine = "partial=nocheck"; } 135 adminFile.add(partialLine); 136 137 String instanceLine = "instance=unique"; 138 adminFile.add(instanceLine); 139 140 // String idependLine = "idepend=quit"; 141 String idependLine = "idepend=nocheck"; 142 // if ( data.isUserInstallation() ) { idependLine = "idepend=nocheck"; } 143 adminFile.add(idependLine); 144 145 // String rdependLine = "rdepend=nocheck"; 146 String rdependLine = "rdepend=quit"; 147 if ( ! rdepends ) { rdependLine = "rdepend=nocheck"; } 148 if ( data.isUserInstallation() ) { rdependLine = "rdepend=nocheck"; } 149 adminFile.add(rdependLine); 150 151 String spaceLine = "space=quit"; 152 if ( data.isUserInstallation() ) { spaceLine = "space=nocheck"; } 153 adminFile.add(spaceLine); 154 155 return adminFile; 156 } 157 getMainVersion(String version)158 private String getMainVersion (String version) { 159 String mainVersion = null; 160 161 int pos = version.indexOf(","); 162 if ( pos > -1 ) { 163 mainVersion = version.substring(0, pos); 164 } 165 166 return mainVersion; 167 } 168 getPackageRevision(String version)169 private String getPackageRevision(String version) { 170 String revision = null; 171 172 int pos = version.indexOf("="); 173 if ( pos > -1 ) { 174 revision = version.substring(pos + 1, version.length() ); 175 } 176 177 return revision; 178 } 179 getVectorOfNumbers(String version)180 private Vector getVectorOfNumbers(String version) { 181 Vector numbers = new Vector(); 182 int pos = -1; 183 // getting number from a string in format 2.0.0 184 do { 185 pos = version.indexOf("."); 186 if ( pos > -1 ) { 187 String number = version.substring(0, pos); 188 version = version.substring(pos + 1, version.length()); 189 numbers.add(number); 190 } 191 } while ( pos > -1 ); 192 193 numbers.add(version); 194 return numbers; 195 } 196 getMinimum(int a, int b)197 private int getMinimum(int a, int b) { 198 int minimum; 199 200 if ( a < b ) { 201 minimum = a; 202 } else { 203 minimum = b; 204 } 205 206 return minimum; 207 } 208 compareVersion(String firstVersion, String secondVersion)209 private String compareVersion(String firstVersion, String secondVersion) { 210 // comparing strings with syntax 2.0.0 211 String comparison = "bothPackagesAreEqual"; 212 Vector firstVector = getVectorOfNumbers(firstVersion); 213 Vector secondVector = getVectorOfNumbers(secondVersion); 214 215 int firstLength = firstVector.size(); 216 int secondLength = secondVector.size(); 217 int minimum = getMinimum(firstLength, secondLength); 218 219 for (int i = 0; i < minimum; i++) { 220 String firstS = (String)firstVector.get(i); 221 String secondS = (String)secondVector.get(i); 222 223 int first = Integer.parseInt(firstS); 224 int second_ = Integer.parseInt(secondS); 225 226 if ( second_ > first ) { 227 comparison = "firstPackageIsOlder"; 228 break; 229 } else if ( second_ < first ) { 230 comparison = "secondPackageIsOlder"; 231 break; 232 } 233 } 234 235 return comparison; 236 } 237 saveModulesLogFile(InstallData data)238 public void saveModulesLogFile(InstallData data) { 239 if ( data.logModuleStates() ) { 240 Vector logContent = LogManager.getModulesLogFile(); 241 File baseDir = new File(data.getInstallDefaultDir(), data.getProductDir()); 242 File uninstallDir = new File(baseDir, data.getUninstallDirName()); 243 File modulesLogFile = new File(uninstallDir, "moduleSettingsLog.txt"); 244 // System.err.println("Saving file: " + modulesLogFile.getPath()); 245 SystemManager.saveCharFileVector(modulesLogFile.getPath(), logContent); 246 } 247 } 248 removeSolarisLockFile()249 public void removeSolarisLockFile() { 250 String lockFileName = "/tmp/.ai.pkg.zone.lock-afdb66cf-1dd1-11b2-a049-000d560ddc3e"; 251 File lockFile = new File(lockFileName); 252 253 if ( lockFile.exists() ) { 254 // System.err.println("Found file: " + lockFileName); 255 boolean deleted = lockFile.delete(); 256 } 257 } 258 getSolarisDatabasePath(InstallData data)259 public String getSolarisDatabasePath(InstallData data) { 260 String databasePath = null; 261 databasePath = data.getInstallDir(); 262 return databasePath; 263 } 264 createAdminFile(boolean relocatable, boolean rdepends)265 public void createAdminFile(boolean relocatable, boolean rdepends) { 266 InstallData data = InstallData.getInstance(); 267 Vector removeFiles = data.getRemoveFiles(); 268 String adminFileName = ""; 269 270 if ( relocatable ) { 271 if ( rdepends ) { 272 adminFileName = "adminFileReloc"; 273 } else { 274 adminFileName = "adminFileRelocNoDepends"; 275 } 276 } else { 277 if ( rdepends ) { 278 adminFileName = "adminFileNoReloc"; 279 } else { 280 adminFileName = "adminFileNoRelocNoDepends"; 281 } 282 } 283 284 Vector fileContent = getAdminFileContent(relocatable, rdepends); 285 File adminFile = new File(data.getInstallDir(), adminFileName); 286 String completeAdminFileName = adminFile.getPath(); 287 288 if ( relocatable ) { 289 if ( rdepends ) { 290 data.setAdminFileNameReloc(completeAdminFileName); 291 } else { 292 data.setAdminFileNameRelocNoDepends(completeAdminFileName); 293 } 294 } else { 295 if ( rdepends ) { 296 data.setAdminFileNameNoReloc(completeAdminFileName); 297 } else { 298 data.setAdminFileNameNoRelocNoDepends(completeAdminFileName); 299 } 300 } 301 302 if ( ! adminFile.exists() ) { 303 // only saving, if it did not exist 304 SystemManager.saveCharFileVector(completeAdminFileName, fileContent); 305 // only removing file in aborted installation, if it was created before 306 removeFiles.add(completeAdminFileName); 307 } 308 309 // File dumpFile = new File(data.getInstallDir(), "dumpFile"); 310 // String dumpFileName = dumpFile.getPath(); 311 // SystemManager.dumpFile(adminFileName, dumpFileName); 312 } 313 314 // for user installations an environment hashmap is used setEnvironmentForUserInstall()315 public void setEnvironmentForUserInstall() { 316 InstallData data = InstallData.getInstance(); 317 HashMap env = SystemManager.getEnvironmentHashMap(); 318 env.put("LD_PRELOAD_32", data.getGetUidPath()); 319 data.setShellEnvironment(env); 320 } 321 getVersionString(Vector returnVector)322 public String getVersionString(Vector returnVector) { 323 String versionString = null; 324 String versionLine = null; 325 326 for (int i = 0; i < returnVector.size(); i++) { 327 String line = (String) returnVector.get(i); 328 int pos = line.indexOf("REV="); 329 if ( pos > -1 ) { 330 versionLine = line; 331 break; 332 } 333 } 334 335 if ( versionLine != null ) { 336 versionLine = versionLine.trim(); 337 int pos = versionLine.lastIndexOf(" "); 338 versionString = versionLine.substring(pos + 1, versionLine.length()); 339 } 340 341 return versionString; 342 } 343 getInstalledMinor(String version)344 public int getInstalledMinor(String version) { 345 346 int minor = 0; 347 348 int pos = version.indexOf("."); 349 if ( pos > -1 ) { 350 String reduced = version.substring(pos + 1, version.length()); 351 352 pos = reduced.indexOf("."); 353 if ( pos > -1 ) { 354 reduced = reduced.substring(0, pos); 355 minor = Integer.parseInt(reduced); 356 } 357 } 358 359 return minor; 360 } 361 comparePackageVersions(String firstPackageVersion, String secondPackageVersion)362 public boolean comparePackageVersions(String firstPackageVersion, String secondPackageVersion) { 363 // Analyzing strings: version, 2.0.0,REV=106.2005.05.26 364 365 boolean firstPackageIsOlder = false; 366 String comparison = null; 367 368 String firstPackageMainVersion = getMainVersion(firstPackageVersion); // 2.0.0 369 String secondPackageMainVersion = getMainVersion(secondPackageVersion); // 2.0.0 370 371 if (( firstPackageMainVersion != null ) && ( secondPackageMainVersion != null )) { 372 comparison = compareVersion(firstPackageMainVersion, secondPackageMainVersion); 373 } 374 375 if ( comparison.equals("firstPackageIsOlder") ) { 376 firstPackageIsOlder = true; 377 } else if ( comparison.equals("secondPackageIsOlder") ) { 378 firstPackageIsOlder = false; 379 } else if ( comparison.equals("bothPackagesAreEqual") ) { 380 String firstPackageRevision = getPackageRevision(firstPackageVersion); // 106.2005.05.26 381 String secondPackageRevision = getPackageRevision(secondPackageVersion); // 106.2005.05.26 382 383 if (( firstPackageRevision != null ) && ( secondPackageRevision != null )) { 384 comparison = compareVersion(firstPackageRevision, secondPackageRevision); 385 if ( comparison.equals("firstPackageIsOlder") ) { 386 firstPackageIsOlder = true; 387 } else { 388 firstPackageIsOlder = false; 389 } 390 } 391 } 392 393 // If version is equal, the patchlevel has to be analyzed 394 // -> pkginfo does not offer this information 395 // -> looking into file <root>/opt/var/sadm/pkg/<package>/pkginfo? 396 397 return firstPackageIsOlder; 398 } 399 400 } 401