/** creates a tag suitable for attaching a snapshot of an environment var map as a "stream" on a task; * mainly for use with STREAM_ENV */ public static WrappedStream tagForEnvStream(String streamEnv, Map<?, ?> env) { StringBuilder sb = new StringBuilder(); for (Map.Entry<?,?> kv: env.entrySet()) { Object val = kv.getValue(); sb.append(kv.getKey()+"=" + (val!=null ? BashStringEscapes.wrapBash(val.toString()) : "") + "\n"); } return BrooklynTaskTags.tagForStream(BrooklynTaskTags.STREAM_ENV, Streams.byteArrayOfString(sb.toString())); }
private String getDumpDatabases(MySqlNode node) { // The config will be inherited from the cluster Collection<String> dumpDbs = node.config().get(MySqlCluster.SLAVE_REPLICATE_DUMP_DB); if (dumpDbs != null && !dumpDbs.isEmpty()) { return " --databases " + Joiner.on(' ').join(Iterables.transform(dumpDbs, BashStringEscapes.wrapBash())); } else { return " --all-databases"; } }
/** wraps plain text in double quotes escaped for use in bash double-quoting */ public static String wrapBash(String value) { StringBuilder out = new StringBuilder(); try { wrapBash(value, out); } catch (IOException e) { //shouldn't happen for string buffer throw Exceptions.propagate(e); } return out.toString(); }
MutableList<Object> c2 = MutableList.of(); for (Object ci: c1) { c2.add(StringEscapes.BashStringEscapes.wrapBash((String)ci));
cmd.add("bash -c "+BashStringEscapes.wrapBash(command));
result.add(wrapBash(hostAndPort.getHostText())); Integer whichPort = knifeWhichPort(hostAndPort); if (whichPort!=null) result.add("-p "+whichPort); result.add("-x "+wrapBash(checkNotNull(machine.getUser(), "user"))); result.add("-r "+wrapBash(runList.apply(entity()))); result.add("-j "+wrapBash(new GsonBuilder().create() .toJson(knifeAttributes)));
result.add(wrapBash(hostAndPort.getHostText())); Integer whichPort = knifeWhichPort(hostAndPort); if (whichPort!=null) result.add("-p "+whichPort); result.add("-x "+wrapBash(checkNotNull(machine.getUser(), "user"))); result.add("-r "+wrapBash(runList.apply(entity()))); result.add("-j "+wrapBash(new GsonBuilder().create() .toJson(knifeAttributes)));
public static String warn(String message) { return "( echo "+BashStringEscapes.wrapBash(message)+" | tee /dev/stderr )"; }
/** fails with nice error if the given file does not exist */ public static String requireExecutable(String command) { return require("which "+BashStringEscapes.wrapBash(command), "The required executable \""+command+"\" does not exist"); }
/** fails with nice error if the given file does not exist */ public static String requireFile(String file) { return requireTest("-f "+BashStringEscapes.wrapBash(file), "The required file \""+file+"\" does not exist"); }
@Override public String apply(String input) { return wrapBash(input); } }
private static String sudoNew(String command) { if (command==null) return null; // on some OS's e.g. Centos 6.5 in SL, sudo -- X tries to run X as a literal argument; // in particular "( echo foo && echo bar )" fails when passed as an argument in that way, // but works if passed to bash -c; // but others e.g. OS X fail if you say sudo -- bash -c "( echo foo )" ... not liking the parentheses // piping to sudo bash seems the most reliable way return "( if test \"$UID\" -eq 0; then ( "+command+" ); else " + "echo " + BashStringEscapes.wrapBash(command) + " | " + "sudo -E -n -S -s -- bash" + " ; fi )"; }
protected String knifeExecutable() { if (knifeExecutable!=null) return knifeExecutable; String knifeExecFromConfig = entityConfig(ChefConfig.KNIFE_EXECUTABLE); if (knifeExecFromConfig!=null) return BashStringEscapes.wrapBash(knifeExecFromConfig); // assume on the path, if executable not set return "knife"; }
@Nullable protected String knifeConfigFileOption() { if (knifeConfigFile!=null) return "-c "+knifeConfigFile; String knifeConfigFileFromConfig = entityConfig(ChefConfig.KNIFE_CONFIG_FILE); if (knifeConfigFileFromConfig!=null) return "-c "+BashStringEscapes.wrapBash(knifeConfigFileFromConfig); // if not supplied will use global config return null; }
protected String knifeExecutable() { if (knifeExecutable!=null) return knifeExecutable; String knifeExecFromConfig = entityConfig(ChefConfig.KNIFE_EXECUTABLE); if (knifeExecFromConfig!=null) return BashStringEscapes.wrapBash(knifeExecFromConfig); // assume on the path, if executable not set return "knife"; }
@Nullable protected String knifeConfigFileOption() { if (knifeConfigFile!=null) return "-c "+knifeConfigFile; String knifeConfigFileFromConfig = entityConfig(ChefConfig.KNIFE_CONFIG_FILE); if (knifeConfigFileFromConfig!=null) return "-c "+BashStringEscapes.wrapBash(knifeConfigFileFromConfig); // if not supplied will use global config return null; }