Better, Faster, Freer

The LXR Cross Referencer

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Architecture: i386 ]
Version: HEAD ]

001 /*************************************************************************
002  *
003  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004  * 
005  * Copyright 2008 by Sun Microsystems, Inc.
006  *
007  * OpenOffice.org - a multi-platform office productivity suite
008  *
009  * $RCSfile: Controller.java,v $
010  * $Revision: 1.7 $
011  *
012  * This file is part of OpenOffice.org.
013  *
014  * OpenOffice.org is free software: you can redistribute it and/or modify
015  * it under the terms of the GNU Lesser General Public License version 3
016  * only, as published by the Free Software Foundation.
017  *
018  * OpenOffice.org is distributed in the hope that it will be useful,
019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
021  * GNU Lesser General Public License version 3 for more details
022  * (a copy is included in the LICENSE file that accompanied this code).
023  *
024  * You should have received a copy of the GNU Lesser General Public License
025  * version 3 along with OpenOffice.org.  If not, see
026  * <http://www.openoffice.org/license.html>
027  * for a copy of the LGPLv3 License.
028  *
029  ************************************************************************/
030 
031 package org.openoffice.setup.Util;
032 
033 import java.io.File;
034 import java.util.Vector;
035 import org.openoffice.setup.InstallData;
036 import org.openoffice.setup.ResourceManager;
037 import org.openoffice.setup.SetupData.SetupDataProvider;
038 import org.openoffice.setup.Util.LogManager;
039 
040 public class Controller {
041     
042     private Controller() {
043     }
044 
045     static public void checkPackagePathExistence(InstallData installData) {
046         String packagePath = installData.getPackagePath();
047         if (( packagePath == null ) || ( packagePath.equals(""))) {
048             String message = ResourceManager.getString("String_InstallationOngoing_PackagePath_Not_Found");
049             String title = ResourceManager.getString("String_Error");
050             Informer.showErrorMessage(message, title);
051             System.exit(1);
052         }
053     }
054 
055     static public void checkPackageFormat(InstallData installData) {
056         String packageFormat = installData.getPackageFormat();
057         String os = installData.getOSType();
058         
059         boolean notSupportedPackageFormat = true;
060         
061         // Show warnings for currently not supported combinations of OS and package format.
062         // This has to be adapted if further OS or package formats are supported.
063         
064         if (( os.equalsIgnoreCase("SunOS") ) && ( packageFormat.equalsIgnoreCase("pkg") )) {
065             notSupportedPackageFormat = false;
066         }
067 
068         if (( os.equalsIgnoreCase("Linux") ) && ( packageFormat.equalsIgnoreCase("rpm") )) {
069             notSupportedPackageFormat = false;
070         }
071         
072         // Inform user about not supported package format and exit program
073         
074         if ( notSupportedPackageFormat ) {
075             System.err.println("Error: Package format not supported by this OS!");
076             String mainmessage = ResourceManager.getString("String_Packageformat_Not_Supported");
077             String osstring = ResourceManager.getString("String_Operating_System");
078             String formatstring = ResourceManager.getString("String_Packageformat");
079             String message = mainmessage + "\n" + osstring + ": " + os + "\n" + formatstring + ": " + packageFormat;
080             String title = ResourceManager.getString("String_Error");
081             Informer.showErrorMessage(message, title);
082             System.exit(1);
083         }
084     }
085 
086     static public void collectSystemLanguages(InstallData installData) {
087         String pkgCommand = "";
088         String[] pkgCommandArray;
089         String adminFileName = "";
090         String log = "";
091         Vector returnVector = new Vector();
092         Vector returnErrorVector = new Vector();
093         int returnValue;
094 
095         pkgCommand = "locale -a";
096         pkgCommandArray = new String[2];
097         pkgCommandArray[0] = "locale";
098         pkgCommandArray[1] = "-a";
099         returnValue = ExecuteProcess.executeProcessReturnVector(pkgCommandArray, returnVector, returnErrorVector);
100         
101         if ( returnValue == 0 ) {
102             log = pkgCommand + "<br><b>Returns: " + returnValue + " Successful command</b><br>";
103             LogManager.addCommandsLogfileComment(log);                        
104 
105             // System.err.println("Available languages 1: ");
106             // for (int i = 0; i < returnVector.size(); i++) {
107             //     System.err.println(returnVector.get(i));
108             // }
109             
110             // Collecting "en-US" instead of "en-US.UTF8"
111             Vector realVector = new Vector();
112 
113             for (int i = 0; i < returnVector.size(); i++) {
114                 String oneLang = (String)returnVector.get(i);
115                 int position = oneLang.indexOf(".");
116                 if ( position > -1 ) {
117                     oneLang = oneLang.substring(0, position);
118                 }
119                 if ( ! realVector.contains(oneLang)) {
120                     realVector.add(oneLang);
121                 }            
122             }
123 
124             // System.err.println("Available languages 2: ");
125             // for (int i = 0; i < realVector.size(); i++) {
126             //     System.err.println(realVector.get(i));
127             // }
128 
129             installData.setSystemLanguages(realVector);
130         } else {    // an error occured                    
131             log = pkgCommand + "<br><b>Returns: " + returnValue + " An error occured</b><br>";
132             LogManager.addCommandsLogfileComment(log);
133             System.err.println("Error in command: " + pkgCommand);
134             for (int i = 0; i < returnErrorVector.size(); i++) {
135                 LogManager.addCommandsLogfileComment((String)returnErrorVector.get(i));
136                 System.err.println(returnErrorVector.get(i));
137             }
138         }       
139     }
140 
141     static public boolean createdSubDirectory(String dir) {
142         boolean createdDirectory = false;
143         boolean errorShown = false;
144         String subDirName = "testdir";
145         File testDir = new File(dir, subDirName);
146         try {
147             createdDirectory = SystemManager.create_directory(testDir.getPath());
148         }
149         catch (SecurityException ex) {
150             String message = ResourceManager.getString("String_ChooseDirectory_No_Write_Access") + ": " + dir;
151             String title = ResourceManager.getString("String_Error");
152             Informer.showErrorMessage(message, title);
153             errorShown = true;
154         }
155 
156         if (( ! createdDirectory ) && ( ! errorShown )) {
157             String message = ResourceManager.getString("String_ChooseDirectory_No_Write_Access") + ": " + dir;
158             String title = ResourceManager.getString("String_Error");
159             Informer.showErrorMessage(message, title);
160             errorShown = true;
161         }
162                 
163         if ( SystemManager.exists_directory(testDir.getPath()) ) {
164             testDir.delete();
165         }
166         
167         return createdDirectory;
168     }
169 
170     static public boolean createdDirectory(String dir) {
171         boolean createdDirectory = false;
172         try {
173             createdDirectory = SystemManager.create_directory(dir);
174         }
175         catch (SecurityException ex) {
176             // message = ResourceManager.getString("String_ChooseDirectory_Not_Allowed") + ": " + dir;
177             // title = ResourceManager.getString("String_Error");
178             // Informer.showErrorMessage(message, title);
179         }
180         
181         if ( ! createdDirectory ) {
182             String message = ResourceManager.getString("String_ChooseDirectory_No_Success") + ": " + dir;
183             String title = ResourceManager.getString("String_Error");
184             Informer.showErrorMessage(message, title);
185         }
186         
187         return createdDirectory;
188     }
189     
190     static public boolean reducedRootWritePrivileges() {
191         Vector vec = new Vector();
192         File dir = new File("/usr");
193         vec.add(dir);
194         dir = new File("/etc");
195         vec.add(dir);
196 
197         boolean restrictedWritePrivilges = false;
198 
199         // Check for zones. If "zonename" is successful and the name is not "global",
200         // this is a "sparse zone".
201         // Alternative: Simply always check, if root has write access in selected directories.
202         
203         for (int i = 0; i < vec.size(); i++) {
204             File directory = (File)vec.get(i);
205             if ( directory.exists() ) {
206                 // do we have write privileges inside the directory
207                 String tempDirName = "temptestdir";
208                 File tempDir = new File(directory, tempDirName);
209 
210                 if ( SystemManager.createDirectory(tempDir) ) {
211                     SystemManager.removeDirectory(tempDir);
212                 } else {
213                     restrictedWritePrivilges = true;
214                     System.err.println("Restricted Root privileges. No write access in " + directory.getPath());
215                     break;
216                 } 
217             }
218         }
219         
220         return restrictedWritePrivilges;
221     }
222     
223     static public void checkForNewerVersion(InstallData installData) {
224         LogManager.setCommandsHeaderLine("Checking change installation");
225         InstallChangeCtrl.checkInstallChange(installData);
226                 
227         if ( installData.newerVersionExists() ) {
228             // Inform user about a newer version installed
229             SetupDataProvider.setNewMacro("DIR", installData.getInstallDefaultDir()); // important for string replacement
230 
231             System.err.println("Error: A newer version is already installed in " + installData.getInstallDefaultDir() + " !");
232             String message1 = ResourceManager.getString("String_Newer_Version_Installed_Found") 
233                             + "\n" + installData.getInstallDefaultDir() + "\n";
234             String message2 = ResourceManager.getString("String_Newer_Version_Installed_Remove");
235             String message = message1 + "\n" + message2;
236             String title = ResourceManager.getString("String_Error");
237             Informer.showErrorMessage(message, title);
238             System.exit(1);                   
239         }
240     }
241     
242     static public void checkForUidFile(InstallData installData) {
243         // check existence of getuid.so
244         File getuidFile = Controller.findUidFile(installData);
245 
246         if (( getuidFile == null ) || (! getuidFile.exists()) ) {
247             // Root privileges required -> abort installation
248             System.err.println("Root privileges required for installation!");
249             String message = ResourceManager.getString("String_Root_Privileges_Required_1") + "\n"
250                            + ResourceManager.getString("String_Root_Privileges_Required_2");
251             String title = ResourceManager.getString("String_Error");
252             Informer.showErrorMessage(message, title);
253             System.exit(1);
254         } else {
255             installData.setGetUidPath(getuidFile.getPath());
256         }
257     }
258 
259     static private File findUidFile(InstallData data) {
260 
261         File getuidFile = null;
262 
263         if ( data.isInstallationMode()) {
264             String getuidpath = System.getProperty("GETUID_PATH");
265 
266             if ( getuidpath != null ) {
267                 getuidFile = new File(getuidpath);
268                 
269                 if (( getuidFile.isDirectory() ) && ( ! getuidFile.isFile() )) {
270                     // Testing, if GETUID_PATH only contains the path, not the filename
271                     String defaultfilename = "getuid.so";
272                     getuidFile = new File(getuidpath, defaultfilename);
273                     
274                     if ( ! getuidFile.exists() ) {
275                         getuidFile = null;
276                     }
277                 }
278             }
279 
280             // File resourceRoot = data.getResourceRoot();
281             // String getuidString = "getuid.so";
282             // if ( resourceRoot != null ) {
283             //     File getuidDir = new File (data.getInfoRoot(), "getuid");
284             //     getuidFile = new File(getuidDir, getuidString);
285             // }
286 
287         } else {
288             getuidFile = new File(data.getGetUidPath());
289         }
290         
291         return getuidFile;
292     }
293 
294 }

source navigation ] diff markup ] identifier search ] general search ]

This page was automatically generated by the LXR engine.
The LXR team
Valid HTML 4.01!