001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
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
062
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
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
106
107
108
109
110
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
125
126
127
128
129 installData.setSystemLanguages(realVector);
130 } else {
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
177
178
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
200
201
202
203 for (int i = 0; i < vec.size(); i++) {
204 File directory = (File)vec.get(i);
205 if ( directory.exists() ) {
206
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
229 SetupDataProvider.setNewMacro("DIR", installData.getInstallDefaultDir());
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
244 File getuidFile = Controller.findUidFile(installData);
245
246 if (( getuidFile == null ) || (! getuidFile.exists()) ) {
247
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
271 String defaultfilename = "getuid.so";
272 getuidFile = new File(getuidpath, defaultfilename);
273
274 if ( ! getuidFile.exists() ) {
275 getuidFile = null;
276 }
277 }
278 }
279
280
281
282
283
284
285
286
287 } else {
288 getuidFile = new File(data.getGetUidPath());
289 }
290
291 return getuidFile;
292 }
293
294 }