static public Pipeline pipeline() { return new Pipeline(Contexts.currentContext()); }
@Override public boolean promptYesNo(String prompt) { // fix prompt for host key if (prompt.contains("authenticity of host") && prompt.endsWith("connecting?")) { prompt = prompt.substring(0, prompt.length() - 1); prompt += " (yes/no)?"; } String answer = Contexts.prompt(prompt + " "); return answer.equalsIgnoreCase("yes"); }
@Override public void unpack(String path, String targetDir) { if (path.endsWith(".tar.gz")) { sshExec(false, false, "tar", "xzf", path, "-C", targetDir).run(); } else if (path.endsWith(".zip")) { sshExec(false, false, "unzip", "-q", "-d", targetDir, path).run(); } else { fail("Unable to support file extension for '" + path + "'"); } log.info("Unpacked {}", path); }
@Override public String getPassphrase() { String prompt = String.format("identity passphrase: "); char[] password = Contexts.passwordPrompt(prompt); // THIS IS UNFORTUNATE SINCE THIS STRING IS INTERNED... return new String(password); }
@Override public String getPassword() { // pass along password if provided (but only one time!) if (JschConnect.this.uri.getPassword() != null) { if (this.returnedPassword) { // prevent possible infinite loop! throw new IllegalStateException("Password prompted too many times"); } this.returnedPassword = true; return JschConnect.this.uri.getPassword(); } // joelauer@hosts's password: String prompt = String.format("%1s@%2s's password: ", jschSession.getUserName(), jschSession.getHost()); char[] password = Contexts.passwordPrompt(prompt); // THIS IS UNFORTUNATE SINCE THIS STRING IS INTERNED... return new String(password); }
static public SshSftp sshSftp(SshSession session) { return new JschSftp(Contexts.currentContext(), session); }
log.warn("Its possible you need to edit your conf files before it can start"); while (!options.safeUnattended()) { String answer = Contexts.prompt("Do you want to try and start your daemons now [yes/no]? "); if (answer.equalsIgnoreCase("yes")) { break;
static public SshSession sshConnect(String uri) throws IOException { MutableUri u = MutableUri.of(uri); if (u.getScheme() == null) { throw new IOException("uri missing scheme (not in format such as ssh://host)"); } switch (u.getScheme()) { case "ssh": return SecureShells.sshConnect(uri).run(); case "vagrant+ssh": { String host = u.getHost(); log.info("Querying vagrant ssh-config for {}", host); return SecureShells.sshConnect("ssh://" + host) .configFile(VAGRANT_CLIENT.sshConfig(host)) .run(); } default: fail("Unsupported target uri. Support for either ssh://host or vagrant+ssh://host"); return null; } }
static public SshExec sshExec(SshSession session) { return new JschExec(Contexts.currentContext(), session); }
static public Pipeline pipeline() { return new Pipeline(Contexts.currentContext()); }
static public Tail tail(int count) { return new Tail(Contexts.currentContext()) .count(count); }
static public Head head(int count) { return new Head(Contexts.currentContext()) .count(count); }
static public Head head(int count) { return new Head(Contexts.currentContext()) .count(count); }
static public Tail tail(int count) { return new Tail(Contexts.currentContext()) .count(count); }
/** * Prepares an action to require an executable to be present or an exception will be thrown and * the script will stop executing. Will use which() under-the-hood. * * <pre> * import static com.fizzed.blaze.Systems.requireExec; * * // ... * * requireExec("javac").run(); * </pre> * * @param command The command to require for such as "javac" or "ls" * @return A new RequireExec action bound to current context */ static public RequireExec requireExec(Path command) { return new RequireExec(Contexts.currentContext()) .command(command); }
/** * Prepares an action to require an executable to be present or an exception will be thrown and * the script will stop executing. Will use which() under-the-hood. * * <pre> * import static com.fizzed.blaze.Systems.requireExec; * * // ... * * requireExec("javac").run(); * </pre> * * @param command The command to require for such as "javac" or "ls" * @return A new RequireExec action bound to current context */ static public RequireExec requireExec(File command) { return new RequireExec(Contexts.currentContext()) .command(command); }
/** * Prepares an action to require an executable to be present or an exception will be thrown and * the script will stop executing. Will use which() under-the-hood. * * <pre> * import static com.fizzed.blaze.Systems.requireExec; * * // ... * * requireExec("javac").run(); * </pre> * * @param command The command to require for such as "javac" or "ls" * @return A new RequireExec action bound to current context */ static public RequireExec requireExec(String command) { return new RequireExec(Contexts.currentContext()) .command(command); }
/** * Prepares an action to require an executable to be present or an exception will be thrown and * the script will stop executing. Will use which() under-the-hood. * * <pre> * import static com.fizzed.blaze.Systems.requireExec; * * // ... * * requireExec("javac").run(); * </pre> * * @param command The command to require for such as "javac" or "ls" * @return A new RequireExec action bound to current context */ static public RequireExec requireExec(Path command) { return new RequireExec(Contexts.currentContext()) .command(command); }
/** * Prepares an action to require an executable to be present or an exception will be thrown and * the script will stop executing. Will use which() under-the-hood. * * <pre> * import static com.fizzed.blaze.Systems.requireExec; * * // ... * * requireExec("javac").run(); * </pre> * * @param command The command to require for such as "javac" or "ls" * @return A new RequireExec action bound to current context */ static public RequireExec requireExec(File command) { return new RequireExec(Contexts.currentContext()) .command(command); }
/** * Prepares an action to find `which` executable to use for a command. Similar to a Unix `which` * command. Platform-specific executable extensions do not need to included * (e.g. `.bat` on windows). Will search for an executable base do on * the environment PATH variable as well as any user-defined paths. * * <pre> * import static com.fizzed.blaze.Systems.which; * * // ... * * Path p = which("javac").run(); * </pre> * * @param command The command to search for such as "javac" or "ls" * @return A new Which action bound to current context */ static public Which which(File command) { return new Which(Contexts.currentContext()) .command(command); }