19a1eeea9SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 39a1eeea9SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 49a1eeea9SAndrew Rist * or more contributor license agreements. See the NOTICE file 59a1eeea9SAndrew Rist * distributed with this work for additional information 69a1eeea9SAndrew Rist * regarding copyright ownership. The ASF licenses this file 79a1eeea9SAndrew Rist * to you under the Apache License, Version 2.0 (the 89a1eeea9SAndrew Rist * "License"); you may not use this file except in compliance 99a1eeea9SAndrew Rist * with the License. You may obtain a copy of the License at 109a1eeea9SAndrew Rist * 119a1eeea9SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 129a1eeea9SAndrew Rist * 139a1eeea9SAndrew Rist * Unless required by applicable law or agreed to in writing, 149a1eeea9SAndrew Rist * software distributed under the License is distributed on an 159a1eeea9SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 169a1eeea9SAndrew Rist * KIND, either express or implied. See the License for the 179a1eeea9SAndrew Rist * specific language governing permissions and limitations 189a1eeea9SAndrew Rist * under the License. 199a1eeea9SAndrew Rist * 209a1eeea9SAndrew Rist *************************************************************/ 219a1eeea9SAndrew Rist 229a1eeea9SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package org.openoffice.setup.Util; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import java.io.File; 27cdf0e10cSrcweir import java.util.Vector; 28cdf0e10cSrcweir import org.openoffice.setup.InstallData; 29cdf0e10cSrcweir import org.openoffice.setup.ResourceManager; 30cdf0e10cSrcweir import org.openoffice.setup.SetupData.SetupDataProvider; 31cdf0e10cSrcweir import org.openoffice.setup.Util.LogManager; 32cdf0e10cSrcweir 33cdf0e10cSrcweir public class Controller { 34cdf0e10cSrcweir Controller()35cdf0e10cSrcweir private Controller() { 36cdf0e10cSrcweir } 37cdf0e10cSrcweir checkPackagePathExistence(InstallData installData)38cdf0e10cSrcweir static public void checkPackagePathExistence(InstallData installData) { 39cdf0e10cSrcweir String packagePath = installData.getPackagePath(); 40cdf0e10cSrcweir if (( packagePath == null ) || ( packagePath.equals(""))) { 41cdf0e10cSrcweir String message = ResourceManager.getString("String_InstallationOngoing_PackagePath_Not_Found"); 42cdf0e10cSrcweir String title = ResourceManager.getString("String_Error"); 43cdf0e10cSrcweir Informer.showErrorMessage(message, title); 44cdf0e10cSrcweir System.exit(1); 45cdf0e10cSrcweir } 46cdf0e10cSrcweir } 47cdf0e10cSrcweir checkPackageFormat(InstallData installData)48cdf0e10cSrcweir static public void checkPackageFormat(InstallData installData) { 49cdf0e10cSrcweir String packageFormat = installData.getPackageFormat(); 50cdf0e10cSrcweir String os = installData.getOSType(); 51cdf0e10cSrcweir 52cdf0e10cSrcweir boolean notSupportedPackageFormat = true; 53cdf0e10cSrcweir 54cdf0e10cSrcweir // Show warnings for currently not supported combinations of OS and package format. 55cdf0e10cSrcweir // This has to be adapted if further OS or package formats are supported. 56cdf0e10cSrcweir 57cdf0e10cSrcweir if (( os.equalsIgnoreCase("SunOS") ) && ( packageFormat.equalsIgnoreCase("pkg") )) { 58cdf0e10cSrcweir notSupportedPackageFormat = false; 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir if (( os.equalsIgnoreCase("Linux") ) && ( packageFormat.equalsIgnoreCase("rpm") )) { 62cdf0e10cSrcweir notSupportedPackageFormat = false; 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir // Inform user about not supported package format and exit program 66cdf0e10cSrcweir 67cdf0e10cSrcweir if ( notSupportedPackageFormat ) { 68cdf0e10cSrcweir System.err.println("Error: Package format not supported by this OS!"); 69cdf0e10cSrcweir String mainmessage = ResourceManager.getString("String_Packageformat_Not_Supported"); 70cdf0e10cSrcweir String osstring = ResourceManager.getString("String_Operating_System"); 71cdf0e10cSrcweir String formatstring = ResourceManager.getString("String_Packageformat"); 72cdf0e10cSrcweir String message = mainmessage + "\n" + osstring + ": " + os + "\n" + formatstring + ": " + packageFormat; 73cdf0e10cSrcweir String title = ResourceManager.getString("String_Error"); 74cdf0e10cSrcweir Informer.showErrorMessage(message, title); 75cdf0e10cSrcweir System.exit(1); 76cdf0e10cSrcweir } 77cdf0e10cSrcweir } 78cdf0e10cSrcweir collectSystemLanguages(InstallData installData)79cdf0e10cSrcweir static public void collectSystemLanguages(InstallData installData) { 80cdf0e10cSrcweir String pkgCommand = ""; 81cdf0e10cSrcweir String[] pkgCommandArray; 82cdf0e10cSrcweir String adminFileName = ""; 83cdf0e10cSrcweir String log = ""; 84cdf0e10cSrcweir Vector returnVector = new Vector(); 85cdf0e10cSrcweir Vector returnErrorVector = new Vector(); 86cdf0e10cSrcweir int returnValue; 87cdf0e10cSrcweir 88cdf0e10cSrcweir pkgCommand = "locale -a"; 89cdf0e10cSrcweir pkgCommandArray = new String[2]; 90cdf0e10cSrcweir pkgCommandArray[0] = "locale"; 91cdf0e10cSrcweir pkgCommandArray[1] = "-a"; 92cdf0e10cSrcweir returnValue = ExecuteProcess.executeProcessReturnVector(pkgCommandArray, returnVector, returnErrorVector); 93cdf0e10cSrcweir 94cdf0e10cSrcweir if ( returnValue == 0 ) { 95cdf0e10cSrcweir log = pkgCommand + "<br><b>Returns: " + returnValue + " Successful command</b><br>"; 96cdf0e10cSrcweir LogManager.addCommandsLogfileComment(log); 97cdf0e10cSrcweir 98cdf0e10cSrcweir // System.err.println("Available languages 1: "); 99cdf0e10cSrcweir // for (int i = 0; i < returnVector.size(); i++) { 100cdf0e10cSrcweir // System.err.println(returnVector.get(i)); 101cdf0e10cSrcweir // } 102cdf0e10cSrcweir 103cdf0e10cSrcweir // Collecting "en-US" instead of "en-US.UTF8" 104cdf0e10cSrcweir Vector realVector = new Vector(); 105cdf0e10cSrcweir 106cdf0e10cSrcweir for (int i = 0; i < returnVector.size(); i++) { 107cdf0e10cSrcweir String oneLang = (String)returnVector.get(i); 108cdf0e10cSrcweir int position = oneLang.indexOf("."); 109cdf0e10cSrcweir if ( position > -1 ) { 110cdf0e10cSrcweir oneLang = oneLang.substring(0, position); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir if ( ! realVector.contains(oneLang)) { 113cdf0e10cSrcweir realVector.add(oneLang); 114cdf0e10cSrcweir } 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir // System.err.println("Available languages 2: "); 118cdf0e10cSrcweir // for (int i = 0; i < realVector.size(); i++) { 119cdf0e10cSrcweir // System.err.println(realVector.get(i)); 120cdf0e10cSrcweir // } 121cdf0e10cSrcweir 122cdf0e10cSrcweir installData.setSystemLanguages(realVector); 123*a893be29SPedro Giffuni } else { // an error occurred 124*a893be29SPedro Giffuni log = pkgCommand + "<br><b>Returns: " + returnValue + " An error occurred</b><br>"; 125cdf0e10cSrcweir LogManager.addCommandsLogfileComment(log); 126cdf0e10cSrcweir System.err.println("Error in command: " + pkgCommand); 127cdf0e10cSrcweir for (int i = 0; i < returnErrorVector.size(); i++) { 128cdf0e10cSrcweir LogManager.addCommandsLogfileComment((String)returnErrorVector.get(i)); 129cdf0e10cSrcweir System.err.println(returnErrorVector.get(i)); 130cdf0e10cSrcweir } 131cdf0e10cSrcweir } 132cdf0e10cSrcweir } 133cdf0e10cSrcweir createdSubDirectory(String dir)134cdf0e10cSrcweir static public boolean createdSubDirectory(String dir) { 135cdf0e10cSrcweir boolean createdDirectory = false; 136cdf0e10cSrcweir boolean errorShown = false; 137cdf0e10cSrcweir String subDirName = "testdir"; 138cdf0e10cSrcweir File testDir = new File(dir, subDirName); 139cdf0e10cSrcweir try { 140cdf0e10cSrcweir createdDirectory = SystemManager.create_directory(testDir.getPath()); 141cdf0e10cSrcweir } 142cdf0e10cSrcweir catch (SecurityException ex) { 143cdf0e10cSrcweir String message = ResourceManager.getString("String_ChooseDirectory_No_Write_Access") + ": " + dir; 144cdf0e10cSrcweir String title = ResourceManager.getString("String_Error"); 145cdf0e10cSrcweir Informer.showErrorMessage(message, title); 146cdf0e10cSrcweir errorShown = true; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir if (( ! createdDirectory ) && ( ! errorShown )) { 150cdf0e10cSrcweir String message = ResourceManager.getString("String_ChooseDirectory_No_Write_Access") + ": " + dir; 151cdf0e10cSrcweir String title = ResourceManager.getString("String_Error"); 152cdf0e10cSrcweir Informer.showErrorMessage(message, title); 153cdf0e10cSrcweir errorShown = true; 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir if ( SystemManager.exists_directory(testDir.getPath()) ) { 157cdf0e10cSrcweir testDir.delete(); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir return createdDirectory; 161cdf0e10cSrcweir } 162cdf0e10cSrcweir createdDirectory(String dir)163cdf0e10cSrcweir static public boolean createdDirectory(String dir) { 164cdf0e10cSrcweir boolean createdDirectory = false; 165cdf0e10cSrcweir try { 166cdf0e10cSrcweir createdDirectory = SystemManager.create_directory(dir); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir catch (SecurityException ex) { 169cdf0e10cSrcweir // message = ResourceManager.getString("String_ChooseDirectory_Not_Allowed") + ": " + dir; 170cdf0e10cSrcweir // title = ResourceManager.getString("String_Error"); 171cdf0e10cSrcweir // Informer.showErrorMessage(message, title); 172cdf0e10cSrcweir } 173cdf0e10cSrcweir 174cdf0e10cSrcweir if ( ! createdDirectory ) { 175cdf0e10cSrcweir String message = ResourceManager.getString("String_ChooseDirectory_No_Success") + ": " + dir; 176cdf0e10cSrcweir String title = ResourceManager.getString("String_Error"); 177cdf0e10cSrcweir Informer.showErrorMessage(message, title); 178cdf0e10cSrcweir } 179cdf0e10cSrcweir 180cdf0e10cSrcweir return createdDirectory; 181cdf0e10cSrcweir } 182cdf0e10cSrcweir reducedRootWritePrivileges()183cdf0e10cSrcweir static public boolean reducedRootWritePrivileges() { 184cdf0e10cSrcweir Vector vec = new Vector(); 185cdf0e10cSrcweir File dir = new File("/usr"); 186cdf0e10cSrcweir vec.add(dir); 187cdf0e10cSrcweir dir = new File("/etc"); 188cdf0e10cSrcweir vec.add(dir); 189cdf0e10cSrcweir 190cdf0e10cSrcweir boolean restrictedWritePrivilges = false; 191cdf0e10cSrcweir 192cdf0e10cSrcweir // Check for zones. If "zonename" is successful and the name is not "global", 193cdf0e10cSrcweir // this is a "sparse zone". 194cdf0e10cSrcweir // Alternative: Simply always check, if root has write access in selected directories. 195cdf0e10cSrcweir 196cdf0e10cSrcweir for (int i = 0; i < vec.size(); i++) { 197cdf0e10cSrcweir File directory = (File)vec.get(i); 198cdf0e10cSrcweir if ( directory.exists() ) { 199cdf0e10cSrcweir // do we have write privileges inside the directory 200cdf0e10cSrcweir String tempDirName = "temptestdir"; 201cdf0e10cSrcweir File tempDir = new File(directory, tempDirName); 202cdf0e10cSrcweir 203cdf0e10cSrcweir if ( SystemManager.createDirectory(tempDir) ) { 204cdf0e10cSrcweir SystemManager.removeDirectory(tempDir); 205cdf0e10cSrcweir } else { 206cdf0e10cSrcweir restrictedWritePrivilges = true; 207cdf0e10cSrcweir System.err.println("Restricted Root privileges. No write access in " + directory.getPath()); 208cdf0e10cSrcweir break; 209cdf0e10cSrcweir } 210cdf0e10cSrcweir } 211cdf0e10cSrcweir } 212cdf0e10cSrcweir 213cdf0e10cSrcweir return restrictedWritePrivilges; 214cdf0e10cSrcweir } 215cdf0e10cSrcweir checkForNewerVersion(InstallData installData)216cdf0e10cSrcweir static public void checkForNewerVersion(InstallData installData) { 217cdf0e10cSrcweir LogManager.setCommandsHeaderLine("Checking change installation"); 218cdf0e10cSrcweir InstallChangeCtrl.checkInstallChange(installData); 219cdf0e10cSrcweir 220cdf0e10cSrcweir if ( installData.newerVersionExists() ) { 221cdf0e10cSrcweir // Inform user about a newer version installed 222cdf0e10cSrcweir SetupDataProvider.setNewMacro("DIR", installData.getInstallDefaultDir()); // important for string replacement 223cdf0e10cSrcweir 224cdf0e10cSrcweir System.err.println("Error: A newer version is already installed in " + installData.getInstallDefaultDir() + " !"); 225cdf0e10cSrcweir String message1 = ResourceManager.getString("String_Newer_Version_Installed_Found") 226cdf0e10cSrcweir + "\n" + installData.getInstallDefaultDir() + "\n"; 227cdf0e10cSrcweir String message2 = ResourceManager.getString("String_Newer_Version_Installed_Remove"); 228cdf0e10cSrcweir String message = message1 + "\n" + message2; 229cdf0e10cSrcweir String title = ResourceManager.getString("String_Error"); 230cdf0e10cSrcweir Informer.showErrorMessage(message, title); 231cdf0e10cSrcweir System.exit(1); 232cdf0e10cSrcweir } 233cdf0e10cSrcweir } 234cdf0e10cSrcweir checkForUidFile(InstallData installData)235cdf0e10cSrcweir static public void checkForUidFile(InstallData installData) { 236cdf0e10cSrcweir // check existence of getuid.so 237cdf0e10cSrcweir File getuidFile = Controller.findUidFile(installData); 238cdf0e10cSrcweir 239cdf0e10cSrcweir if (( getuidFile == null ) || (! getuidFile.exists()) ) { 240cdf0e10cSrcweir // Root privileges required -> abort installation 241cdf0e10cSrcweir System.err.println("Root privileges required for installation!"); 242cdf0e10cSrcweir String message = ResourceManager.getString("String_Root_Privileges_Required_1") + "\n" 243cdf0e10cSrcweir + ResourceManager.getString("String_Root_Privileges_Required_2"); 244cdf0e10cSrcweir String title = ResourceManager.getString("String_Error"); 245cdf0e10cSrcweir Informer.showErrorMessage(message, title); 246cdf0e10cSrcweir System.exit(1); 247cdf0e10cSrcweir } else { 248cdf0e10cSrcweir installData.setGetUidPath(getuidFile.getPath()); 249cdf0e10cSrcweir } 250cdf0e10cSrcweir } 251cdf0e10cSrcweir findUidFile(InstallData data)252cdf0e10cSrcweir static private File findUidFile(InstallData data) { 253cdf0e10cSrcweir 254cdf0e10cSrcweir File getuidFile = null; 255cdf0e10cSrcweir 256cdf0e10cSrcweir if ( data.isInstallationMode()) { 257cdf0e10cSrcweir String getuidpath = System.getProperty("GETUID_PATH"); 258cdf0e10cSrcweir 259cdf0e10cSrcweir if ( getuidpath != null ) { 260cdf0e10cSrcweir getuidFile = new File(getuidpath); 261cdf0e10cSrcweir 262cdf0e10cSrcweir if (( getuidFile.isDirectory() ) && ( ! getuidFile.isFile() )) { 263cdf0e10cSrcweir // Testing, if GETUID_PATH only contains the path, not the filename 264cdf0e10cSrcweir String defaultfilename = "getuid.so"; 265cdf0e10cSrcweir getuidFile = new File(getuidpath, defaultfilename); 266cdf0e10cSrcweir 267cdf0e10cSrcweir if ( ! getuidFile.exists() ) { 268cdf0e10cSrcweir getuidFile = null; 269cdf0e10cSrcweir } 270cdf0e10cSrcweir } 271cdf0e10cSrcweir } 272cdf0e10cSrcweir 273cdf0e10cSrcweir // File resourceRoot = data.getResourceRoot(); 274cdf0e10cSrcweir // String getuidString = "getuid.so"; 275cdf0e10cSrcweir // if ( resourceRoot != null ) { 276cdf0e10cSrcweir // File getuidDir = new File (data.getInfoRoot(), "getuid"); 277cdf0e10cSrcweir // getuidFile = new File(getuidDir, getuidString); 278cdf0e10cSrcweir // } 279cdf0e10cSrcweir 280cdf0e10cSrcweir } else { 281cdf0e10cSrcweir getuidFile = new File(data.getGetUidPath()); 282cdf0e10cSrcweir } 283cdf0e10cSrcweir 284cdf0e10cSrcweir return getuidFile; 285cdf0e10cSrcweir } 286cdf0e10cSrcweir 287cdf0e10cSrcweir } 288