public static Statement addAuthorizedKeysToRoot(String publicKey) { return newStatementList( appendFile("/root/.ssh/authorized_keys", Splitter.on('\n').split(publicKey)), interpret("chmod 600 /root/.ssh/authorized_keys")); }
@Override public String render(OsFamily family) { checkNotNull(family, "family"); if (family == OsFamily.WINDOWS) throw new UnsupportedOperationException("windows not yet implemented"); Builder<Statement> statements = ImmutableList.builder(); statements.add(exec("mkdir -p " + sshDir)); String authorizedKeys = sshDir + "{fs}authorized_keys"; statements.add(appendFile(authorizedKeys, Splitter.on('\n').split(Joiner.on("\n\n").join(publicKeys)))); statements.add(exec("chmod 600 " + authorizedKeys)); return new StatementList(statements.build()).render(family); } }
@Override public String render(OsFamily family) { checkNotNull(family, "family"); if (family == OsFamily.WINDOWS) throw new UnsupportedOperationException("windows not yet implemented"); Builder<Statement> statements = ImmutableList.builder(); statements.add(exec("mkdir -p " + sshDir)); String authorizedKeys = sshDir + "{fs}authorized_keys"; statements.add(appendFile(authorizedKeys, Splitter.on('\n').split(Joiner.on("\n\n").join(publicKeys)))); statements.add(exec("chmod 600 " + authorizedKeys)); return new StatementList(statements.build()).render(family); } }
private void addUnixRunScriptFooter(String runScript, StringBuilder builder) { builder.append("# add runscript footer\n"); Iterable<String> endScript = Splitter.on(ShellToken.LF.to(OsFamily.UNIX)).split( ShellToken.END_SCRIPT.to(OsFamily.UNIX)); builder.append(appendFile(runScript, endScript, DELIMITER).render(OsFamily.UNIX)); }
@Override public String render(OsFamily family) { checkNotNull(family, "family"); if (family == OsFamily.WINDOWS) throw new UnsupportedOperationException("windows not yet implemented"); Builder<Statement> statements = ImmutableList.builder(); statements.add(exec("mkdir -p " + sshDir)); String authorizedKeys = sshDir + "{fs}authorized_keys"; statements.add(appendFile(authorizedKeys, Splitter.on('\n').split(Joiner.on("\n\n").join(publicKeys)))); statements.add(exec("chmod 600 " + authorizedKeys)); return new StatementList(statements.build()).render(family); } }
private void addUnixRunScriptFooter(String runScript, StringBuilder builder) { builder.append("# add runscript footer\n"); Iterable<String> endScript = Splitter.on(ShellToken.LF.to(OsFamily.UNIX)).split( ShellToken.END_SCRIPT.to(OsFamily.UNIX)); builder.append(appendFile(runScript, endScript, DELIMITER).render(OsFamily.UNIX)); }
private void addUnixRunScriptFooter(String runScript, StringBuilder builder) { builder.append("# add runscript footer\n"); Iterable<String> endScript = Splitter.on(ShellToken.LF.to(OsFamily.UNIX)).split( ShellToken.END_SCRIPT.to(OsFamily.UNIX)); builder.append(appendFile(runScript, endScript, DELIMITER).render(OsFamily.UNIX)); }
private void addUnixRunScriptFooter(String runScript, StringBuilder builder) { builder.append("# add runscript footer\n"); Iterable<String> endScript = Splitter.on(ShellToken.LF.to(OsFamily.UNIX)).split( ShellToken.END_SCRIPT.to(OsFamily.UNIX)); builder.append(appendFile(runScript, endScript, DELIMITER).render(OsFamily.UNIX)); }
private void addUnixRunScriptFooter(String runScript, StringBuilder builder) { builder.append("# add runscript footer\n"); Iterable<String> endScript = Splitter.on(ShellToken.LF.to(OsFamily.UNIX)).split( ShellToken.END_SCRIPT.to(OsFamily.UNIX)); builder.append(appendFile(runScript, endScript, DELIMITER).render(OsFamily.UNIX)); }
private void addUnixRunScriptFooter(String runScript, StringBuilder builder) { builder.append("# add runscript footer\n"); Iterable<String> endScript = Splitter.on(ShellToken.LF.to(OsFamily.UNIX)).split( ShellToken.END_SCRIPT.to(OsFamily.UNIX)); builder.append(appendFile(runScript, endScript, DELIMITER).render(OsFamily.UNIX)); }
private void addUnixRunScript(String runScript, StringBuilder builder) { builder.append("# add desired commands from the user\n"); Builder<String> userCommands = ImmutableList.builder(); userCommands.add("cd " + pwd); for (Statement statement : statements) { if (statement instanceof Call || (statement instanceof StatementList && any(StatementList.class.cast(statement).delegate(), instanceOf(Call.class)))) { statement = new ExitInsteadOfReturn(statement); } userCommands.addAll(Splitter.on('\n').split(statement.render(OsFamily.UNIX))); } builder.append(appendFile(runScript, userCommands.build(), DELIMITER).render(OsFamily.UNIX)); }
private void addUnixRunScript(String runScript, StringBuilder builder) { builder.append("# add desired commands from the user\n"); Builder<String> userCommands = ImmutableList.builder(); userCommands.add("cd " + pwd); for (Statement statement : statements) { if (statement instanceof Call || (statement instanceof StatementList && any(StatementList.class.cast(statement).delegate(), instanceOf(Call.class)))) { statement = new ExitInsteadOfReturn(statement); } userCommands.addAll(Splitter.on('\n').split(statement.render(OsFamily.UNIX))); } builder.append(appendFile(runScript, userCommands.build(), DELIMITER).render(OsFamily.UNIX)); }
@Override public String render(OsFamily family) { checkNotNull(family, "family"); if (family == OsFamily.WINDOWS) throw new UnsupportedOperationException("windows not yet implemented"); Builder<Statement> statements = ImmutableList.builder(); statements.add(exec("{md} " + sshDir)); String idRsa = sshDir + "{fs}id_rsa"; statements.add(exec("{rm} " + idRsa)); statements.add(appendFile(idRsa, Splitter.on('\n').split(privateKey))); statements.add(exec("chmod 600 " + idRsa)); return new StatementList(statements.build()).render(family); } }
@Override public String render(OsFamily family) { checkNotNull(family, "family"); if (family == OsFamily.WINDOWS) throw new UnsupportedOperationException("windows not yet implemented"); Builder<Statement> statements = ImmutableList.builder(); statements.add(exec("{md} " + sshDir)); String idRsa = sshDir + "{fs}id_rsa"; statements.add(exec("{rm} " + idRsa)); statements.add(appendFile(idRsa, Splitter.on('\n').split(privateKey))); statements.add(exec("chmod 600 " + idRsa)); return new StatementList(statements.build()).render(family); } }
private void addUnixRunScript(String runScript, StringBuilder builder) { builder.append("# add desired commands from the user\n"); Builder<String> userCommands = ImmutableList.builder(); userCommands.add("cd " + pwd); for (Statement statement : statements) { if (statement instanceof Call || (statement instanceof StatementList && any(StatementList.class.cast(statement).delegate(), instanceOf(Call.class)))) { statement = new ExitInsteadOfReturn(statement); } userCommands.addAll(Splitter.on('\n').split(statement.render(OsFamily.UNIX))); } builder.append(appendFile(runScript, userCommands.build(), DELIMITER).render(OsFamily.UNIX)); }
@Override public String render(OsFamily family) { checkNotNull(family, "family"); if (family == OsFamily.WINDOWS) throw new UnsupportedOperationException("windows not yet implemented"); Builder<Statement> statements = ImmutableList.builder(); statements.add(exec("{md} " + sshDir)); String idRsa = sshDir + "{fs}id_rsa"; statements.add(exec("{rm} " + idRsa)); statements.add(appendFile(idRsa, Splitter.on('\n').split(privateKey))); statements.add(exec("chmod 600 " + idRsa)); return new StatementList(statements.build()).render(family); } }
private void addUnixRunScript(String runScript, StringBuilder builder) { builder.append("# add desired commands from the user\n"); Builder<String> userCommands = ImmutableList.builder(); userCommands.add("cd " + pwd); for (Statement statement : statements) { if (statement instanceof Call || (statement instanceof StatementList && any(StatementList.class.cast(statement).delegate(), instanceOf(Call.class)))) { statement = new ExitInsteadOfReturn(statement); } userCommands.addAll(Splitter.on('\n').split(statement.render(OsFamily.UNIX))); } builder.append(appendFile(runScript, userCommands.build(), DELIMITER).render(OsFamily.UNIX)); }
@Override public String render(OsFamily family) { checkNotNull(family, "family"); if (family == OsFamily.WINDOWS) throw new UnsupportedOperationException("windows not yet implemented"); Builder<Statement> statements = ImmutableList.builder(); statements.add(exec("{md} " + sshDir)); String idRsa = sshDir + "{fs}id_rsa"; statements.add(exec("{rm} " + idRsa)); statements.add(appendFile(idRsa, Splitter.on('\n').split(privateKey))); statements.add(exec("chmod 600 " + idRsa)); return new StatementList(statements.build()).render(family); } }
private void addUnixRunScript(String runScript, StringBuilder builder) { builder.append("# add desired commands from the user\n"); Builder<String> userCommands = ImmutableList.builder(); userCommands.add("cd " + pwd); for (Statement statement : statements) { if (statement instanceof Call || (statement instanceof StatementList && any(StatementList.class.cast(statement).delegate(), instanceOf(Call.class)))) { statement = new ExitInsteadOfReturn(statement); } userCommands.addAll(Splitter.on('\n').split(statement.render(OsFamily.UNIX))); } builder.append(appendFile(runScript, userCommands.build(), DELIMITER).render(OsFamily.UNIX)); }
public void testSwitchArgUNIX() { assertEquals(new SwitchArg(1, ImmutableMap.of("0", newStatementList(appendFile( "{tmp}{fs}{uid}{fs}scripttest{fs}temp.txt", ImmutableList.of("hello world")), interpret("echo hello zero{lf}")), "1", interpret("echo hello one{lf}"))).render(OsFamily.UNIX), "case $1 in\n"+ "0)\n"+ " cat >> /tmp/$USER/scripttest/temp.txt <<-'END_OF_JCLOUDS_FILE'\n"+ "\thello world\n"+ "END_OF_JCLOUDS_FILE\n"+ " echo hello zero\n"+ " ;;\n"+ "1)\n"+ " echo hello one\n"+ " ;;\n"+ "esac\n"); }