public static String installPackageOr(Map<?,?> flags, String packageDefaultName, String optionalCommandToRunIfNone) { String ifMissing = (String) flags.get("onlyifmissing"); String zypperInstall = formatIfNotNull("zypper --non-interactive --no-gpg-checks install %s", getFlag(flags, "zypper", packageDefaultName)); String aptInstall = formatIfNotNull("apt-get install -y --allow-unauthenticated %s", getFlag(flags, "apt", packageDefaultName)); String yumInstall = formatIfNotNull("yum -y --nogpgcheck install %s", getFlag(flags, "yum", packageDefaultName)); String brewInstall = formatIfNotNull("brew install %s", getFlag(flags, "brew", packageDefaultName)); String portInstall = formatIfNotNull("port install %s", getFlag(flags, "port", packageDefaultName)); commands.add(format("which %s", ifMissing)); if (zypperInstall != null) commands.add(ifExecutableElse1("zypper", chainGroup( "echo zypper exists, doing refresh", ok(sudo("zypper --non-interactive --no-gpg-checks refresh")), sudo(zypperInstall)))); if (aptInstall != null) commands.add(ifExecutableElse1("apt-get", chainGroup( "echo apt-get exists, doing update", "export DEBIAN_FRONTEND=noninteractive", ok(sudo("apt-get update")), sudo(aptInstall)))); if (yumInstall != null) commands.add(ifExecutableElse1("yum", chainGroup( "echo yum exists, doing update", ok(sudo("yum check-update")), ok(sudo("yum -y install epel-release")), ok(sudo("yum upgrade -y ca-certificates --disablerepo=epel")),
/** * Returns the command that saves iptables rules on file. * * @return Returns the command that saves iptables rules on file. * */ public static String saveIptablesRules() { return alternatives(sudo("service iptables save"), chain(installPackage("iptables-persistent"), sudo("/etc/init.d/iptables-persistent save"))); }
/** * Adds the PPA for OpenJDK for older JDK versions (7 and lower) required by some software (e.g. JBoss) */ public static String addOpenJDKPPK(){ return chainGroup( sudo("sudo add-apt-repository -y ppa:openjdk-r/ppa"), sudo("sudo apt-get update")); }
/** * Returns a string for checking whether the given executable is available, * and installing it if necessary. * <p/> * Uses {@link #installPackage} and accepts the same flags e.g. for apt, yum, rpm. */ public static String installExecutable(Map<?,?> flags, String executable) { return onlyIfExecutableMissing(executable, installPackage(flags, executable)); }
private String getZypperRepository() { return chainGroup( ok(sudo("zypper --non-interactive addrepo http://download.opensuse.org/repositories/devel:/languages:/erlang/SLE_11_SP3 erlang_sles_11")), ok(sudo("zypper --non-interactive addrepo http://download.opensuse.org/repositories/devel:/languages:/erlang/openSUSE_11.4 erlang_suse_11")), ok(sudo("zypper --non-interactive addrepo http://download.opensuse.org/repositories/devel:/languages:/erlang/openSUSE_12.3 erlang_suse_12")), ok(sudo("zypper --non-interactive addrepo http://download.opensuse.org/repositories/devel:/languages:/erlang/openSUSE_13.1 erlang_suse_13"))); } }
/** * Install a particular Java runtime, fails if not possible. * <p> * <em><strong>Note</strong> Java 8 is not yet supported on SUSE</em> * * @return The command to install the given Java runtime. * @see #installJava6OrFail() * @see #installJava7Or6OrFail() * @see #installJavaLatestOrFail() */ public static String installJava(int version) { Preconditions.checkArgument(version == 6 || version == 7 || version == 8, "Supported Java versions are 6, 7, or 8"); List<String> commands = new LinkedList<String>(); commands.add(ok(addOpenJDKPPK())); commands.add(installPackageOr(MutableMap.of("apt", "openjdk-" + version + "-jdk","yum", "java-1." + version + ".0-openjdk-devel"), null, ifExecutableElse1("zypper", chainGroup( ok(sudo("zypper --non-interactive addrepo http://download.opensuse.org/repositories/Java:/openjdk6:/Factory/SLE_11_SP3 java_sles_11")), ok(sudo("zypper --non-interactive addrepo http://download.opensuse.org/repositories/Java:/openjdk6:/Factory/openSUSE_11.4 java_suse_11")), ok(sudo("zypper --non-interactive addrepo http://download.opensuse.org/repositories/Java:/openjdk6:/Factory/openSUSE_12.3 java_suse_12")), ok(sudo("zypper --non-interactive addrepo http://download.opensuse.org/repositories/Java:/openjdk6:/Factory/openSUSE_13.1 java_suse_13")), alternatives(installPackageOrFail(MutableMap.of("zypper", "java-1_" + version + "_0-openjdk-devel"), null), installPackageOrFail(MutableMap.of("zypper", "java-1_" + version + "_0-ibm"), null)))))); commands.add(ok(upgradeNSS())); return chainGroup(commands); }
public String installAmbariRequirements(SshMachineLocation machine) { return BashCommands.chainGroup(BashCommands.INSTALL_CURL, installExecutable("ntp"), BashCommands.alternatives(sudo("service ntpd start"), sudo("service ntp start")), createCommandToAddAmbariToRepositoriesList(machine)); }
/** * Returns the command that adds firewalld direct rule. * * @return Returns the command that adds firewalld direct rule. */ public static String addFirewalldRule(Chain chain, Optional<String> networkInterface, org.apache.brooklyn.util.net.Protocol protocol, int port, Policy policy) { String command = new String("/usr/bin/firewall-cmd"); String commandPermanent = new String("/usr/bin/firewall-cmd --permanent"); String interfaceParameter = String.format("%s", networkInterface.isPresent() ? " -i " + networkInterface.get() : ""); String commandParameters = String.format(" --direct --add-rule ipv4 filter %s 0 %s -p %s --dport %d -j %s", chain, interfaceParameter, protocol, port, policy); return sudo(chain(command + commandParameters, commandPermanent + commandParameters)); } }
@Override public void install() { LOG.info("Installing Node.JS {}", getVersion()); List<String> commands = MutableList.<String>builder() .add(BashCommands.INSTALL_CURL) .add(BashCommands.ifExecutableElse0("apt-get", BashCommands.chain( BashCommands.installPackage("software-properties-common python-software-properties python g++ make"), BashCommands.sudo("add-apt-repository ppa:chris-lea/node.js")))) .add(BashCommands.installPackage(MutableMap.of("yum", "git nodejs npm", "apt", "git-core nodejs npm"), null)) .add("mkdir -p \"$HOME/.npm\"") .add(BashCommands.sudo("npm install -g n")) .add(BashCommands.sudo("n " + getVersion())) .build(); newScript(INSTALLING) .body.append(commands) .execute(); }
.append("which pg_ctl") .appendAll(Iterables.transform(pgctlLocations, StringFunctions.formatter("test -x %s/pg_ctl"))) .append(installPackage(ImmutableMap.of( "yum", "postgresql"+shortVersion+" postgresql"+shortVersion+"-server", "apt", "postgresql-"+majorMinorVersion, .append(warn(format("WARNING: failed to find or install postgresql %s binaries", majorMinorVersion))); .append(ifExecutableElse1("pg_ctl", chainGroup( "PG_EXECUTABLE=`which pg_ctl`", "PG_DIR=`dirname $PG_EXECUTABLE`", "ln -s $PG_DIR bin"))) .appendAll(Iterables.transform(pgctlLocations, givenDirIfFileExistsInItLinkToDir("pg_ctl", "bin"))) .append(fail(format("WARNING: failed to find postgresql %s binaries for pg_ctl, may already have another version installed; aborting", majorMinorVersion), 9)); dontRequireTtyForSudo(), ifExecutableElse0("yum", getYumRepository(version, majorMinorVersion, shortVersion)), ifExecutableElse0("apt-get", getAptRepository()), "rm -f bin", // if left over from previous incomplete/failed install (not sure why that keeps happening!) alternativesGroup(findOrInstall), alternativesGroup(linkFromHere)) .failOnNonZeroResultCode() .queue(); if (DynamicTasks.queue(SshEffectorTasks.ssh(sudoAsUser("postgres", "ls "+getInstallDir())).allowingNonZeroExitCode() .summary("check postgres user can access install dir")).asTask().getUnchecked()!=0) { log.info("Postgres install dir "+getInstallDir()+" for "+getEntity()+" is not accessible to user 'postgres'; " + "using "+altInstallDir+" instead");
/** * Returns the iptables rules. * * @return Returns the command that list all the iptables rules. */ public static String listIptablesRule() { return sudo("/sbin/iptables -L -v -n"); }
@Override public void install() { List<String> urls = resolver.getTargets(); String saveAs = resolver.getFilename(); ImmutableList.Builder<String> commands= ImmutableList.<String> builder(); if (!getLocation().getOsDetails().isMac()) { commands.add(BashCommands.installPackage(ImmutableMap.of( "yum", "libuuid-devel", "apt", "build-essential uuid-dev pkg-config libtool automake"), "libuuid-devel")); commands.add(BashCommands.ifExecutableElse0("yum", BashCommands.sudo("yum -y groupinstall 'Development Tools'"))); } commands.add(BashCommands.installPackage(ImmutableMap.of("yum", "git"), "git")) .add(BashCommands.INSTALL_UNZIP) .addAll(installNativeDependencies()) .addAll(BashCommands.commandsToDownloadUrlsAs(urls, saveAs)) .add("unzip " + saveAs) .add("mkdir -p " + getLocalDir()) .add("chmod 777 " + getLocalDir()); // FIXME newScript(INSTALLING) .body.append(commands.build()) .gatherOutput() .execute(); }
@Beta // implementation not portable across distros public static String iptablesService(String cmd) { return sudo(alternatives( BashCommands.ifExecutableElse1("service", "service iptables " + cmd), "/sbin/service iptables " + cmd)); }
false, null, destName).newTask()); String installCmd = BashCommands.chain( "cd "+privateTmpDirContainingUnpackedCookbook, "COOKBOOK_EXPANDED_DIR=`ls`", BashCommands.requireTest("`ls | wc -w` -eq 1", "The deployed archive "+cookbookArchiveUrl+" must contain exactly one directory"), "mv $COOKBOOK_EXPANDED_DIR '../"+cookbookName+"'", "rm -rf '"+privateTmpDirContainingUnpackedCookbook+"'"); installCmd = force ? BashCommands.alternatives("rm -rf "+cookbookDir, installCmd) : BashCommands.alternatives("ls "+cookbookDir+" > /dev/null 2> /dev/null", installCmd); tb.add(SshEffectorTasks.ssh(installCmd).summary("renaming cookbook dir").requiringExitCodeZero().newTask());
private String useYum(String osVersion, String arch, String epelRelease) { String osMajorVersion = osVersion.substring(0, osVersion.lastIndexOf(".")); return chainGroup( alternatives( sudo("rpm -qa | grep epel-release"), sudo(format("rpm -Uvh http://dl.fedoraproject.org/pub/epel/%s/%s/epel-release-%s.noarch.rpm", osMajorVersion, arch, epelRelease)))); }
.add("export JAVA_HOME=$(/usr/libexec/java_home)") .add("cd " + getInstallDir()) .add(BashCommands.installPackage(ImmutableMap.of("brew", "automake"), "make")) .add(BashCommands.installPackage(ImmutableMap.of("brew", "libtool"), "libtool")) .add(BashCommands.installPackage(ImmutableMap.of("brew", "pkg-config"), "pkg-config")) .add(BashCommands.installPackage(ImmutableMap.of("brew", "zeromq"), "zeromq")) .add("git clone https://github.com/asmaier/jzmq") .add("cd jzmq") .add("./configure") .add("make") .add((BashCommands.sudo("make install"))) .add("cd " + getInstallDir()); } else { commands.add("export JAVA_HOME=$(dirname $(readlink -m `which java`))/../../ || export JAVA_HOME=/usr/lib/jvm/java") .add("cd " + getInstallDir()) .add(BashCommands.commandToDownloadUrlAs(zeromqUrl, targz)) .add("tar xzf " + targz) .add(format("cd zeromq-%s", getZeromqVersion())) .add("./configure") .add("make") .add((BashCommands.sudo("make install"))) .add(BashCommands.ok( "pushd src ; touch classdist_noinst.stamp ; CLASSPATH=.:./.:$CLASSPATH " + "javac -d . org/zeromq/ZMQ.java org/zeromq/App.java org/zeromq/ZMQForwarder.java org/zeromq/EmbeddedLibraryTools.java org/zeromq/ZMQQueue.java org/zeromq/ZMQStreamer.java org/zeromq/ZMQException.java")) .add(BashCommands.ok("popd")) .add((BashCommands.sudo("make install")))
private String setupAptRepo(SshMachineLocation sshMachineLocation) { final String osDetailsVersion = getOsVersion(sshMachineLocation); String repoUrl; if (osDetailsVersion.startsWith("14")) { repoUrl = UBUNTU_14_AMBARI_REPO_LOCATION; } else { repoUrl = UBUNTU_12_AMBARI_REPO_LOCATION; } return ifExecutableElse1("apt-get", chainGroup(sudo(commandToDownloadUrlAs(String.format(repoUrl, repoBaseUrl, getMajorVersion(), version), UBUNTU_REPO_LIST_LOCATION)), sudo("apt-key adv --recv-keys --keyserver keyserver.ubuntu.com B9733A7A07513CAD"), sudo("apt-get update"))); }
@Override public void install() { List<String> commands = Lists.newLinkedList(); commands.addAll(BashCommands.commandsToDownloadUrlsAs(resolver.getTargets(), getCalicoCommand())); commands.add("chmod 755 " + getCalicoCommand()); commands.add(BashCommands.installPackage("ipset")); commands.add(sudo("modprobe ip6_tables")); commands.add(sudo("modprobe xt_set")); newScript(INSTALLING) .body.append(commands) .execute(); }
private String getUnpackCommand(String tmpLocation) { if (tmpLocation.endsWith("tar")) { return sudo(format("tar xvf %s -C %s", tmpLocation, stackResourceLocation())); } else if (tmpLocation.endsWith("tar.gz")) { return sudo(format("tar zxvf %s -C %s", tmpLocation, stackResourceLocation())); } else if (tmpLocation.endsWith("zip")) { return BashCommands.chain( BashCommands.INSTALL_UNZIP, sudo(unzip(tmpLocation, stackResourceLocation()))); } throw new IllegalStateException("Stack locations must be of type tar, tar.gz, zip"); }
return chainGroup( installPackage("apt-transport-https"), "echo 'deb https://apt.dockerproject.org/repo " + dockerRepoName + " main' | " + sudo("tee -a /etc/apt/sources.list.d/docker.list"), sudo("apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D"), installPackage("docker-engine=" + repositoryVersionName));