}
public void installPackage(PackageDescription packageData) {
// get ProductDescription for logging mechanism
ProductDescription productData = SetupDataProvider.getProductDescription();
InstallData data = InstallData.getInstance();
// String log = "<br><b>Package: " + packageData.getName() + "</b>";
// LogManager.addCommandsLogfileComment(log);
String log = "";
// setting installDir
String installDir = data.getInstallDir();
String packagePath = data.getPackagePath();
if (( packageData.getPkgSubdir() != null ) && ( ! packageData.getPkgSubdir().equals("") )) {
File completePackageFile = new File(packagePath, packageData.getPkgSubdir());
packagePath = completePackageFile.getPath();
}
String packageName = packageData.getPackageName();
if (( packageName.equals("")) || ( packageName == null )) {
log = "<b>No package name specified. Nothing to do</b>";
LogManager.addCommandsLogfileComment(log);
} else {
log = "<b>Package Name: " + packageName + "</b>";
LogManager.addCommandsLogfileComment(log);
File completePackage = new File(packagePath, packageName);
packageName = completePackage.getPath();
if ( completePackage.exists() ) {
String relocations = helper.getRelocationString(packageData, packageName);
if ( relocations != null ) {
// Problem: If Prefix = "/" the packages are not relocatable with RPM version 3.x .
// Therefore Prefix has to be "/opt" in spec file, although packages shall not be
// relocatable (except for installations with root privileges). So /opt has to be
// listed left and right of equal sign: --relocate /opt=<installDir>/opt
// -> /opt has to be added to the installDir
File localInstallDir = new File(installDir, relocations); // "/" -> "/opt"
String localInstallDirString = localInstallDir.getPath();
// Fixing problem with installation directory and RPM version 3.x
String fixedInstallDir = helper.fixInstallationDirectory(localInstallDirString);
relocations = relocations + "=" + fixedInstallDir;
// relocations: "/opt/staroffice8=" + fixedInstallDir;
}
// Some packages have to be installed with parameter "--force", if the link "/usr/bin/soffice"
// already exists. These pacakges return true with methode "useForce()".
boolean useForce = false;
if ( packageData.useForce() ) {
File sofficeLink = new File("/usr/bin/soffice");
if ( sofficeLink.exists() ) { useForce = true; }
}
String rpmCommand = "";
String[] rpmCommandArray;
String databasePath = null;
String databaseString = "";
boolean useLocalDatabase = false;
if ( data.isUserInstallation() ) {
databasePath = data.getDatabasePath();
if ( databasePath == null ) {
databasePath = helper.getLinuxDatabasePath(data);
data.setDatabasePath(databasePath);
}
}
if (( databasePath != null ) && (! databasePath.equalsIgnoreCase("null"))) {
databaseString = "--dbpath";
useLocalDatabase = true;
}
if (useForce) {
if (useLocalDatabase) {
if ( relocations != null ) {
rpmCommand = "rpm --upgrade --ignoresize --force -vh " +
"--relocate " + relocations + " " + databaseString +
" " + databasePath + " " + packageName;
rpmCommandArray = new String[10];
rpmCommandArray[0] = "rpm";
rpmCommandArray[1] = "--upgrade";
rpmCommandArray[2] = "--ignoresize";
rpmCommandArray[3] = "--force";
rpmCommandArray[4] = "-vh";
rpmCommandArray[5] = "--relocate";
rpmCommandArray[6] = relocations;
rpmCommandArray[7] = databaseString;
rpmCommandArray[8] = databasePath;
rpmCommandArray[9] = packageName;
} else {
rpmCommand = "rpm --upgrade --ignoresize --force -vh " +
databaseString + " " + databasePath + " " + packageName;
rpmCommandArray = new String[8];
rpmCommandArray[0] = "rpm";
rpmCommandArray[1] = "--upgrade";
rpmCommandArray[2] = "--ignoresize";
rpmCommandArray[3] = "--force";
rpmCommandArray[4] = "-vh";
rpmCommandArray[5] = databaseString;
rpmCommandArray[6] = databasePath;
rpmCommandArray[7] = packageName;
}
} else {
if ( relocations != null )
{
rpmCommand = "rpm --upgrade --ignoresize --force -vh " +
"--relocate " + relocations + " " + packageName;
rpmCommandArray = new String[8];
rpmCommandArray[0] = "rpm";
rpmCommandArray[1] = "--upgrade";
rpmCommandArray[2] = "--ignoresize";
rpmCommandArray[3] = "--force";
rpmCommandArray[4] = "-vh";
rpmCommandArray[5] = "--relocate";
rpmCommandArray[6] = relocations;
rpmCommandArray[7] = packageName;
} else {
rpmCommand = "rpm --upgrade --ignoresize --force -vh " + packageName;
rpmCommandArray = new String[6];
rpmCommandArray[0] = "rpm";
rpmCommandArray[1] = "--upgrade";
rpmCommandArray[2] = "--ignoresize";
rpmCommandArray[3] = "--force";
rpmCommandArray[4] = "-vh";
rpmCommandArray[5] = packageName;
}
}
} else {
if (useLocalDatabase) {
if ( relocations != null ) {
rpmCommand = "rpm --upgrade --ignoresize -vh " +
"--relocate " + relocations + " " + databaseString +
" " + databasePath + " " + packageName;
rpmCommandArray = new String[9];
rpmCommandArray[0] = "rpm";
rpmCommandArray[1] = "--upgrade";
rpmCommandArray[2] = "--ignoresize";
rpmCommandArray[3] = "-vh";
rpmCommandArray[4] = "--relocate";
rpmCommandArray[5] = relocations;
rpmCommandArray[6] = databaseString;
rpmCommandArray[7] = databasePath;
rpmCommandArray[8] = packageName;
} else {
rpmCommand = "rpm --upgrade --ignoresize -vh " +
databaseString + " " + databasePath + " " + packageName;
rpmCommandArray = new String[7];
rpmCommandArray[0] = "rpm";
rpmCommandArray[1] = "--upgrade";
rpmCommandArray[2] = "--ignoresize";
rpmCommandArray[3] = "-vh";
rpmCommandArray[4] = databaseString;
rpmCommandArray[5] = databasePath;
rpmCommandArray[6] = packageName;
}
} else {
if ( relocations != null )
{
rpmCommand = "rpm --upgrade --ignoresize -vh " +
"--relocate " + relocations + " " + packageName;
rpmCommandArray = new String[7];
rpmCommandArray[0] = "rpm";
rpmCommandArray[1] = "--upgrade";
rpmCommandArray[2] = "--ignoresize";
rpmCommandArray[3] = "-vh";
rpmCommandArray[4] = "--relocate";
rpmCommandArray[5] = relocations;
rpmCommandArray[6] = packageName;
} else {
rpmCommand = "rpm --upgrade --ignoresize -vh " + packageName;
rpmCommandArray = new String[5];
rpmCommandArray[0] = "rpm";
rpmCommandArray[1] = "--upgrade";
rpmCommandArray[2] = "--ignoresize";
rpmCommandArray[3] = "-vh";
rpmCommandArray[4] = packageName;
}
}
}
Vector returnVector = new Vector();
Vector returnErrorVector = new Vector();
// int returnValue = SystemManager.executeProcessReturnVector(rpmCommand, returnVector, returnErrorVector);
int returnValue = ExecuteProcess.executeProcessReturnVector(rpmCommandArray, returnVector, returnErrorVector);
if ( returnValue == 0 ) {
log = rpmCommand + "<br><b>Returns: " + returnValue + " Successful installation</b><br>";
LogManager.addCommandsLogfileComment(log);
} else { // an error occured during installation
if ( packageData.installCanFail() ) {
log = rpmCommand + "<br><b>Returns: " + returnValue + " Problem during installation. Can be ignored.</b><br>";
LogManager.addCommandsLogfileComment(log);
} else {
log = rpmCommand + "<br><b>Returns: " + returnValue + " Error during installation</b><br>";
LogManager.addCommandsLogfileComment(log);
for (int i = 0; i < returnErrorVector.size(); i++) {
LogManager.addCommandsLogfileComment((String)returnErrorVector.get(i));
}
data.setIsErrorInstallation(true);
}
}
// saving installation state at package
packageData.setIsNewInstalled(true);
} else {
log = "<b>Error: Did not find package " + packageName + "</b><br>";
System.err.println(log);
String message = ResourceManager.getString("String_File_Not_Found") + ": " + packageName;
String title = ResourceManager.getString("String_Error");
Informer.showErrorMessage(message, title);
LogManager.addCommandsLogfileComment(log);
data.setIsErrorInstallation(true);
}
}
}