Created
February 11, 2011 17:55
-
-
Save stillalex/822747 to your computer and use it in GitHub Desktop.
Short version of classes used in a blog post - full version at https://github.com/alexparvulescu/blog/blob/master/remote-java-install
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class JSCHWrapper { | |
| // just pass private key, user and host | |
| public JSCHWrapper(String identityFile, String user, String host){ /* .. */ } | |
| // executes a command | |
| public String execCommand(String command) throws Exception { /* .. */ } | |
| // disconnects the current ssh session | |
| public void disconnect() { /* .. */ } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class RemoteJavaInstaller { | |
| private String getInstallCommand() { | |
| StringBuilder sb = new StringBuilder(); | |
| sb.append("sudo echo sun-java6-jre shared/accepted-sun-dlj-v1-1 select true | sudo /usr/bin/debconf-set-selections"); | |
| sb.append("; "); | |
| sb.append("sudo add-apt-repository \"deb http://archive.canonical.com/ lucid partner\""); | |
| sb.append("; "); | |
| sb.append("sudo apt-get update"); | |
| sb.append("; "); | |
| sb.append("sudo apt-get install --yes sun-java6-jdk sun-java6-jre"); | |
| sb.append("; "); | |
| sb.append("echo \"JAVA_HOME=/usr/lib/jvm/java-6-sun\" >> .bashrc"); | |
| sb.append("; "); | |
| sb.append("echo \"PATH=\\$PATH:\\$JAVA_HOME/bin\" >> .bashrc"); | |
| sb.append("; "); | |
| sb.append("java -version"); | |
| sb.append("; "); | |
| return sb.toString(); | |
| } | |
| public String install() { | |
| JSCHWrapper j = null; | |
| try { | |
| j = new JSCHWrapper(IDENTITY_FILE, USER, HOST); | |
| return j.execCommand(getInstallCommand()); | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } finally { | |
| if (j != null) { | |
| j.disconnect(); | |
| } | |
| } | |
| return null; | |
| } | |
| public static void main(String[] args) throws Exception { | |
| RemoteJavaInstaller rji = new RemoteJavaInstaller(); | |
| System.out.println(rji.install()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment