[izpack-changes] r1847 - izpack-src/branches/3.10/src/lib/com/izforge/izpack/util/os/unix
noreply at berlios.de
noreply at berlios.de
Mon May 28 15:18:43 CEST 2007
Author: eppelman
Date: 2007-05-28 15:18:24 +0200 (Mon, 28 May 2007)
New Revision: 1847
Modified:
izpack-src/branches/3.10/src/lib/com/izforge/izpack/util/os/unix/UnixHelper.java
Log:
Applied the patch: "Fix NPE when ypcat not installed on linux" from Dick Hollenbeck
Also fixed some Javadoc-phrases and the test-main().
Modified: izpack-src/branches/3.10/src/lib/com/izforge/izpack/util/os/unix/UnixHelper.java
===================================================================
--- izpack-src/branches/3.10/src/lib/com/izforge/izpack/util/os/unix/UnixHelper.java 2007-05-28 13:08:54 UTC (rev 1846)
+++ izpack-src/branches/3.10/src/lib/com/izforge/izpack/util/os/unix/UnixHelper.java 2007-05-28 13:18:24 UTC (rev 1847)
@@ -39,7 +39,7 @@
// ~ Static fields/initializers *********************************************************
- /** whichCommand = "/usr/bin/which" or so */
+ /** whichCommand = "/usr/bin/which" or /bin/which */
public static String whichCommand = FileExecutor.getExecOutput(
new String[] { "/usr/bin/env", "which", "which"}, false).trim();
@@ -48,7 +48,7 @@
// ~ Methods ****************************************************************************
/**
- * get the lines from /etc/passwd as Array
+ * Get the lines from /etc/passwd as Array
*
* @return the /etc/passwd as String ArrayList
*/
@@ -72,12 +72,26 @@
{
// ignore - there are maybe no users
}
+ finally
+ {
+ try
+ {
+ if (reader != null) reader.close();
+ }
+ catch (Exception ignore)
+ {
+ // ignore
+ }
+ }
return result;
}
/**
- * get the lines from /etc/passwd as Array
+ * Get the YelloyPages (NIS) Users lines from <code>ypcat passwd</code> as Array. Ypcat
+ * passwd's output has the same format as the the local /etc/passwd. Because there can be
+ * thousands of yp-users and this query is net-based, this is a candidate for a token-based
+ * optimization.
*
* @return the /etc/passwd as String ArrayList
*/
@@ -87,29 +101,44 @@
String line = "";
BufferedReader reader = null;
+ String ypcommand = getYpCatCommand();
- try
+ if (ypcommand != null && ypcommand.length() > 0)
{
- reader = new BufferedReader(new StringReader(FileExecutor.getExecOutput(new String[] {
- getYpCatCommand(), "passwd"})));
- while ((line = reader.readLine()) != null)
+ try
{
- result.add(line);
+ reader = new BufferedReader(new StringReader(FileExecutor
+ .getExecOutput(new String[] { ypcommand, "passwd"})));
+ while ((line = reader.readLine()) != null)
+ {
+ result.add(line);
+ }
}
+ catch (Exception e)
+ {
+ // ignore - there are maybe no users
+ }
+ finally
+ {
+ try
+ {
+ if (reader != null) reader.close();
+
+ }
+ catch (Exception i)
+ {
+ // ignore
+ }
+ }
}
- catch (Exception e)
- {
- // ignore - there are maybe no users
- }
-
return result;
}
/**
- * Test if KDE is installed. This is done by $>/usr/bin/env konqueror --version This assumes
- * that the konqueror as a main-app of kde is already installed. If this returns with 0 konqeror
- * and resp. kde means to be installed,
+ * Test if KDE is installed. This is done by <code> $>/usr/bin/env kwin --version</code> This
+ * assumes that kwin, the window Manager, as part of the kde-base package is already installed.
+ * If this returns with 0 kwin resp. kde means to be installed,
*
* @return true if kde is installed otherwise false.
*/
@@ -119,17 +148,17 @@
String[] execOut = new String[2];
- int execResult = fe.executeCommand(
- new String[] { "/usr/bin/env", "konqueror", "--version"}, execOut);
+ int execResult = fe.executeCommand(new String[] { "/usr/bin/env", "kwin", "--version"},
+ execOut);
return execResult == 0;
}
/**
- * Gets the absolute Pathe to the cp (Copy) Command. This is necessary, because the command is
+ * Gets the absolute path of the which command. This is necessary, because the command is
* located at /bin on linux but in /usr/bin on Sun Solaris.
*
- * @return /bin/cp on linux /usr/bin/cp on solaris
+ * @return /bin/which on linux /usr/bin/which on solaris
*/
public static String getWhichCommand()
{
@@ -137,7 +166,7 @@
}
/**
- * Gets the absolute Pathe to the cp (Copy) Command. This is necessary, because the command is
+ * Gets the absolute path of the cp (Copy) command. This is necessary, because the command is
* located at /bin on linux but in /usr/bin on Sun Solaris.
*
* @return /bin/cp on linux /usr/bin/cp on solaris
@@ -148,7 +177,7 @@
}
/**
- * Gets the absolute Pathe to the su (SuperUser) Command. This is necessary, because the command
+ * Gets the absolute path to the su (SuperUser) command. This is necessary, because the command
* is located at /bin on linux but in /usr/bin on Sun Solaris.
*
* @return /bin/su on linux /usr/bin/su on solaris
@@ -181,12 +210,13 @@
}
/**
- * Gets the absolute Pathe to the ypcat (YellowPage/NIS Cat) Command. This is necessary, because
- * the command is located at /bin on linux but in /usr/bin on Sun Solaris.
+ * Gets the absolute Pathe to the given custom command. This is necessary, because the command
+ * may be located at /bin on linux but in /usr/bin on Sun Solaris. Which can locate it in your
+ * $PATH for you.
*
* @param aCommand a Custom Command
*
- * @return /bin/ypcat on linux /usr/bin/ypcat on solaris
+ * @return /bin/aCommand on linux /usr/bin/aCommand on solaris
*/
public static String getCustomCommand(String aCommand)
{
@@ -194,8 +224,7 @@
}
/**
- * Standalone Test Main Method call with : > java -cp
- * ../bin/panels/UserInputPanel.jar:../_dist/IzPack-install-3.9.0-preview1.jar
+ * Standalone Test Main Method call with : > java -cp ../_build
* com.izforge.izpack.util.os.unix.UnixHelper
*
* @param args commandline args
@@ -207,7 +236,7 @@
// System.out.println( StringTool.stringArrayListToString(UnixUsers.getUsersAsArrayList())
// );
- //System.out.println("Kde is" + (kdeIsInstalled() ? " " : " not ") + "installed");
+ // System.out.println("Kde is" + (kdeIsInstalled() ? " " : " not ") + "installed");
System.out.println("WhichCommand: '" + getWhichCommand() + "'");
System.out.println("SuCommand: " + getSuCommand());
@@ -231,41 +260,65 @@
}
System.out.println("Tempfile: " + tempFile.toString());
+ System.out.println("TempfileName: " + tempFile.getName());
// This does not work :-(
/*
* FileExecutor.getExecOutput(new String[] { getCustomCommand("echo"), "Hallo", ">",
* tempFile.toString()});
*/
+ String username = System.getProperty("user.name");
+ // System.out.println("Your Name: " + username);
// so try:
- try
+ if ("root".equals(username))
{
- BufferedWriter w = new BufferedWriter( new FileWriter(tempFile) );
- w.write("Hallo");
- w.flush();
- w.close();
- if( tempFile.exists() )
- System.out.println("Wrote: " + tempFile + ">>Hallo");
- else
- System.out.println("Could not Wrote: " + tempFile + "Hallo");
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- // tempFile
+ try
+ {
+ BufferedWriter w = new BufferedWriter(new FileWriter(tempFile));
+ w.write("Hallo");
+ w.flush();
+ w.close();
+ if (tempFile.exists())
+ System.out.println("Wrote: " + tempFile + ">>Hallo");
+ else
+ System.out.println("Could not Wrote: " + tempFile + "Hallo");
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
- String destfilename = "/home/marc.eppelmann" + File.separator + "Desktop" ;
+ String destfilename = "/home/marc.eppelmann" + File.separator + "Desktop"
+ + File.separator + tempFile.getName();
- System.out.println("Copy: " + tempFile.toString() + " to " + destfilename);
+ System.out.println("Copy: " + tempFile.toString() + " to " + destfilename);
- String result = FileExecutor.getExecOutput(new String[] { getSuCommand(), "marc.eppelmann", "-c",
- "\"" + getCpCommand() + " " + tempFile.toString() + " " + destfilename + "\""});
-
- System.out.println("Wrote: " + tempFile.toString() + " to " + destfilename + " > " + result);
+ ShellScript s = new ShellScript("bash");
- // getYpPasswdArray();
- // System.out.println("/bin/bash".endsWith("sh"));
+ s.append(getSuCommand() + " " + "marc.eppelmann" + " " + "-c" + " " + "\""
+ + getCpCommand() + " " + tempFile.toString() + " " + destfilename + "\"");
+
+ String shLocation = "/tmp/x.21.21";
+ try
+ {
+ shLocation = File.createTempFile(UnixHelper.class.getName(),
+ Long.toString(System.currentTimeMillis()) + ".sh").toString();
+ }
+ catch (Exception x)
+ {
+ x.printStackTrace();
+ }
+ s.write(shLocation);
+ s.exec();
+
+ // File deleteMe = new File( shLocation ); deleteMe.delete();
+
+ }
+ else
+ {
+ System.out.println("Your name: '" + username
+ + "' is not 'root'. But this is a test for the user root.");
+ }
}
}
More information about the izpack-changes
mailing list