@Override public String toString() { return asString(); }
static public CaptureOutput captureOutput() { return new CaptureOutput(); }
@Override public String toString() { return asString(); }
static public CaptureOutput captureOutput() { return new CaptureOutput(); }
public String asString() { return asString(StandardCharsets.UTF_8); }
public String asString() { return asString(StandardCharsets.UTF_8); }
static private Map<String,String> which(SshSession ssh, List<String> commands) { // doesn't matter if we find it or not String whichString = sshExec(ssh, "which", commands.toArray()) .pipeOutput(Streamables.captureOutput()) .pipeError(Streamables.nullOutput()) .exitValues(0, 1, 2) .runResult() .map(Actions::toCaptureOutput) .asString(); if (whichString == null) { return Collections.emptyMap(); } Map<String,String> result = new HashMap<>(); String[] lines = whichString.split("\\\n"); for (String line : lines) { Path cmd = Paths.get(line.trim()); result.put(cmd.getFileName().toString(), line.trim()); } return result; }
public Integer getGroupId(String group) { try { String groupId = sshExec(false, false, "id", "-g", group) .pipeOutput(Streamables.captureOutput()) .pipeError(Streamables.nullOutput()) .runResult() .map(Actions::toCaptureOutput) .asString() .trim(); return Integer.valueOf(groupId); } catch (UnexpectedExitValueException e) { return null; } }
public Integer getUserId(String user) { try { String userId = sshExec(false, false, "id", "-u", user) .pipeOutput(Streamables.captureOutput()) .pipeError(Streamables.nullOutput()) .runResult() .map(Actions::toCaptureOutput) .asString() .trim(); return Integer.valueOf(userId); } catch (UnexpectedExitValueException e) { return null; } }
static private String uname(SshSession ssh) { // doesn't matter if we find it or not return sshExec(ssh, "uname", "-srm") .pipeOutput(Streamables.captureOutput()) .pipeError(Streamables.nullOutput()) .exitValues(0) .runResult() .map(Actions::toCaptureOutput) .asString() .trim(); }
static private InitType initType(SshSession ssh) { String initTypeString = sshExec(ssh) .command("sh").args("-c", "if $(/sbin/init --version | egrep -q 'upstart'); then echo upstart; " + "elif $(systemctl | egrep -q '.mount'); then echo systemd; " + "elif [ -f /etc/init.d/cron ] || [ -f /etc/init.d/crond ]; then echo sysv; " + "else echo unknown; fi") .pipeOutput(Streamables.captureOutput()) .pipeError(Streamables.nullOutput()) .runResult() .map(Actions::toCaptureOutput) .asString(); if (initTypeString == null) { return null; } switch (initTypeString.trim()) { case "sysv": return InitType.SYSV; case "systemd": return InitType.SYSTEMD; case "upstart": return InitType.UPSTART; default: return InitType.UNKNOWN; } }
.runResult() .map(Actions::toCaptureOutput) .asString();