prompt = false;
}
String sshInstallDir = getInstallDir().replace('\\', '/');
SFTPClient sftpClient = sshLauncher.getSFTPClient();
SCPClient scpClient = sshLauncher.getSCPClient();
try {
if (!sftpClient.exists(sshInstallDir)) {
sftpClient.mkdirs(sshInstallDir, 0755);
}
}
catch (IOException ioe) {
logger.info(Strings.get("mkdir.failed", sshInstallDir, host));
throw new IOException(ioe);
}
//delete the sshInstallDir contents if non-empty
try {
//get list of file in DAS sshInstallDir
List<String> files = getListOfInstallFiles(sshInstallDir);
deleteRemoteFiles(sftpClient, files, sshInstallDir, getForce());
}
catch (IOException ex) {
logger.finer("Failed to remove sshInstallDir contents");
throw new IOException(ex);
}
String zip = zipFile.getCanonicalPath();
try {
logger.info("Copying " + zip + " (" + zipFile.length() + " bytes)"
+ " to " + host + ":" + sshInstallDir);
// Looks like we need to quote the paths to scp in case they
// contain spaces.
scpClient.put(zipFile.getAbsolutePath(), FileUtils.quoteString(sshInstallDir));
logger.finer("Copied " + zip + " to " + host + ":" + sshInstallDir);
}
catch (IOException ex) {
logger.info(Strings.get("cannot.copy.zip.file", zip, host));
throw new IOException(ex);
}
try {
logger.info("Installing " + getArchiveName() + " into " + host + ":" + sshInstallDir);
String unzipCommand = "cd '" + sshInstallDir + "'; jar -xvf " + getArchiveName();
int status = sshLauncher.runCommand(unzipCommand, outStream);
if (status != 0) {
logger.info(Strings.get("jar.failed", host, outStream.toString()));
throw new CommandException("Remote command output: " + outStream.toString());
}
logger.finer("Installed " + getArchiveName() + " into " + host + ":" + sshInstallDir);
}
catch (IOException ioe) {
logger.info(Strings.get("jar.failed", host, outStream.toString()));
throw new IOException(ioe);
}
try {
logger.info("Removing " + host + ":" + sshInstallDir + "/" + getArchiveName());
sftpClient.rm(sshInstallDir + "/" + getArchiveName());
logger.finer("Removed " + host + ":" + sshInstallDir + "/" + getArchiveName());
}
catch (IOException ioe) {
logger.info(Strings.get("remove.glassfish.failed", host, sshInstallDir));
throw new IOException(ioe);
}
// unjarring doesn't retain file permissions, hence executables need
// to be fixed with proper permissions
logger.info("Fixing file permissions of all bin files under " + host + ":" + sshInstallDir);
try {
if (binDirFiles.isEmpty()) {
//binDirFiles can be empty if the archive isn't a fresh one
searchAndFixBinDirectoryFiles(sshInstallDir, sftpClient);
}
else {
for (String binDirFile : binDirFiles) {
sftpClient.chmod((sshInstallDir + "/" + binDirFile), 0755);
}
}
logger.finer("Fixed file permissions of all bin files under " + host + ":" + sshInstallDir);
}
catch (IOException ioe) {
logger.info(Strings.get("fix.permissions.failed", host, sshInstallDir));
throw new IOException(ioe);
}
if (Constants.v4) {
logger.info("Fixing file permissions for nadmin file under " + host + ":"
+ sshInstallDir + "/" + SystemPropertyConstants.getComponentName() + "/lib");
try {
sftpClient.chmod((sshInstallDir + "/" + SystemPropertyConstants.getComponentName() + "/lib/nadmin"), 0755);
logger.finer("Fixed file permission for nadmin under " + host + ":" + sshInstallDir + "/" + SystemPropertyConstants.getComponentName() + "/lib/nadmin");
}
catch (IOException ioe) {
logger.info(Strings.get("fix.permissions.failed", host, sshInstallDir));
throw new IOException(ioe);