public static TaskFactory<?> installCookbook(String chefDirectory, String cookbook, String url, boolean force) { // TODO if it's server, try knife first // TODO support downloads from classpath / local server return SshEffectorTasks.ssh(cdAndRun(chefDirectory, ChefBashCommands.downloadAndExpandCookbook(url, cookbook, force))). summary("install cookbook "+cookbook).requiringExitCodeZero(); }
public static TaskFactory<?> installCookbook(String chefDirectory, String cookbook, String url, boolean force) { // TODO if it's server, try knife first // TODO support downloads from classpath / local server return SshEffectorTasks.ssh(cdAndRun(chefDirectory, ChefBashCommands.downloadAndExpandCookbook(url, cookbook, force))). summary("install cookbook "+cookbook).requiringExitCodeZero(); }
/** this assumes the download is an archive containing a single directory on the root which will be renamed to "cookbookName"; * if that directory already has the correct name cookbookName can be null, * but if e.g. taking from a github tarball it will typically be of the form cookbookName-master/ * hence the renaming */ // TODO support installing from classpath, and using the repository (tie in with those methods) public static final String downloadAndExpandCookbook(String source, @Nullable String cookbookName, boolean force) { String dl = downloadAndExpandCookbook(source); if (cookbookName==null) return dl; String tmpName = "tmp-"+Strings.makeValidFilename(cookbookName)+"-"+Identifiers.makeRandomId(4); String installCmd = BashCommands.chain("mkdir "+tmpName, "cd "+tmpName, dl, BashCommands.requireTest("`ls | wc -w` -eq 1", "The downloaded archive must contain exactly one directory; contained"), "COOKBOOK_EXPANDED_DIR=`ls`", "mv $COOKBOOK_EXPANDED_DIR '../"+cookbookName+"'", "cd ..", "rm -rf "+tmpName); if (!force) return BashCommands.alternatives("ls "+cookbookName, installCmd); else return BashCommands.alternatives("rm -rf "+cookbookName, installCmd); }