| 1 |
package gnu.io.installer.macosx; |
| 2 |
|
| 3 |
import java.net.*; |
| 4 |
import java.io.*; |
| 5 |
import java.util.*; |
| 6 |
|
| 7 |
import glguerin.authkit.*; |
| 8 |
import gnu.io.installer.*; |
| 9 |
import gnu.io.installer.util.*; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
public class MACOSXRXTXInstaller extends gnu.io.installer.RXTXInstaller{ |
| 16 |
private static final String JavaExtensions = "Java/Extensions"; |
| 17 |
|
| 18 |
public MACOSXRXTXInstaller(){ |
| 19 |
createJarFolder(); |
| 20 |
createLibFolder(); |
| 21 |
installAuthKit(); |
| 22 |
addJarResource("RXTXcomm.jar","/gnu/io/installer/resources/macosx/jar/RXTXcomm.dat"); |
| 23 |
addLibResource("librxtxSerial.jnilib","/gnu/io/installer/resources/macosx/lib/librxtxSerial.jnilib"); |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
public void runPreProcess() { |
| 28 |
|
| 29 |
Authorization auth = new glguerin.authkit.imp.macosx.MacOSXAuthorization(); |
| 30 |
Privilege priv = new Privilege("system.privilege.admin"); |
| 31 |
|
| 32 |
int count = 0; |
| 33 |
boolean succeed = false; |
| 34 |
do { |
| 35 |
try{ |
| 36 |
auth.authorize( priv, true ); |
| 37 |
succeed = true; |
| 38 |
break; |
| 39 |
} catch (Throwable t) { |
| 40 |
System.out.println("Throwable "+t); |
| 41 |
} |
| 42 |
count++; |
| 43 |
} while (count <= 3); |
| 44 |
|
| 45 |
if(succeed){ |
| 46 |
String preinstallPath = createTemporaryPreinstallFile(); |
| 47 |
if(preinstallPath == null) return; |
| 48 |
String [] progArray = {preinstallPath,System.getProperty("user.name")}; |
| 49 |
try { |
| 50 |
Process p = auth.execPrivileged( progArray ); |
| 51 |
Thread.sleep( 1000L ); |
| 52 |
} catch (Throwable t) { |
| 53 |
System.out.println("Throwable "+t); |
| 54 |
t.printStackTrace(); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
} |
| 59 |
|
| 60 |
public void runPostProcess() {} |
| 61 |
|
| 62 |
|
| 63 |
protected void createJarFolder(){ |
| 64 |
File libFile = new File(InstallUtil.getFolderPath(InstallUtil.kLocalDomain,InstallUtil.kDomainLibraryFolder)); |
| 65 |
jarFolder = new File(libFile,JavaExtensions); |
| 66 |
if(!jarFolder.canWrite()){ |
| 67 |
libFile = new File(InstallUtil.getFolderPath(InstallUtil.kUserDomain,InstallUtil.kDomainLibraryFolder)); |
| 68 |
jarFolder = new File(libFile,JavaExtensions); |
| 69 |
if(!jarFolder.exists()){ |
| 70 |
jarFolder.mkdirs(); |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
protected void createLibFolder(){ |
| 76 |
File libFile = new File(InstallUtil.getFolderPath(InstallUtil.kLocalDomain,InstallUtil.kDomainLibraryFolder)); |
| 77 |
libFolder = new File(libFile,JavaExtensions); |
| 78 |
if(!libFolder.canWrite()){ |
| 79 |
libFile = new File(InstallUtil.getFolderPath(InstallUtil.kUserDomain,InstallUtil.kDomainLibraryFolder)); |
| 80 |
libFolder = new File(libFile,JavaExtensions); |
| 81 |
if(!libFolder.exists()){ |
| 82 |
libFolder.mkdirs(); |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
private String createTemporaryPreinstallFile() { |
| 88 |
try { |
| 89 |
File tempFile = File.createTempFile("preinstall",null); |
| 90 |
tempFile.deleteOnExit(); |
| 91 |
InstallUtil.copyResourceToFile("/gnu/io/installer/resources/macosx/preinstall",tempFile); |
| 92 |
String absPath = tempFile.getAbsolutePath(); |
| 93 |
Process p = Runtime.getRuntime().exec(new String[]{"chmod","a+x",absPath}); |
| 94 |
p.waitFor(); |
| 95 |
return absPath; |
| 96 |
} catch (Throwable t) {} |
| 97 |
return null; |
| 98 |
} |
| 99 |
|
| 100 |
private void installAuthKit() { |
| 101 |
boolean usingJWS = false; |
| 102 |
final ClassLoader originalClassLoader=Thread.currentThread().getContextClassLoader(); |
| 103 |
if(originalClassLoader.toString().toLowerCase().indexOf("jnlp")!=-1) usingJWS=true; |
| 104 |
if(usingJWS) return; |
| 105 |
try { |
| 106 |
File tempFile = new File(jarFolder,"libAuthKit.jnilib"); |
| 107 |
tempFile.deleteOnExit(); |
| 108 |
InstallUtil.copyResourceToFile("/gnu/io/installer/resources/macosx/lib/libAuthKit.jnilib",tempFile); |
| 109 |
} catch (Throwable t) { |
| 110 |
System.out.println("installAuthKit Throwable "+t); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
} |
| 115 |
|