reused common logic in guest addition install

This commit is contained in:
Adrian Cole 2012-01-30 02:41:16 +08:00
parent ef97bef786
commit 4e69321e2e
2 changed files with 11 additions and 6 deletions

View File

@ -23,12 +23,16 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.scriptbuilder.domain.Statements.call;
import static org.jclouds.scriptbuilder.domain.Statements.exec;
import java.net.URI;
import java.util.Collections;
import org.jclouds.scriptbuilder.ScriptBuilder;
import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.scriptbuilder.domain.SaveHttpResponseTo;
import org.jclouds.scriptbuilder.domain.Statement;
import com.google.common.collect.ImmutableMultimap;
public class InstallGuestAdditions implements Statement {
private final String vboxVersion;
@ -56,9 +60,11 @@ public class InstallGuestAdditions implements Statement {
String vboxGuestAdditionsIso = "VBoxGuestAdditions_" + vboxVersion + ".iso";
ScriptBuilder scriptBuilder = new ScriptBuilder()
.addStatement(exec("{cd} {fs}tmp"))
.addStatement(exec("wget http://download.virtualbox.org/virtualbox/" + vboxVersion + "/" + vboxGuestAdditionsIso))
.addStatement(exec(String.format("mount -o loop %s %s", vboxGuestAdditionsIso, mountPoint)))
.addStatement(
new SaveHttpResponseTo("{tmp}", vboxGuestAdditionsIso, "GET", URI
.create("http://download.virtualbox.org/virtualbox/" + vboxVersion + "/"
+ vboxGuestAdditionsIso), ImmutableMultimap.<String, String> of()))
.addStatement(exec(String.format("mount -o loop {tmp}{fs}%s %s", vboxGuestAdditionsIso, mountPoint)))
.addStatement(call("installGuestAdditions"))
.addStatement(exec(String.format("sh %s%s", mountPoint, "/VBoxLinuxAdditions.run")))
.addStatement(exec(String.format("umount %s", mountPoint)));

View File

@ -22,9 +22,8 @@ function installGuestAdditions {
return 0
}
export PATH=/usr/ucb/bin:/bin:/sbin:/usr/bin:/usr/sbin
cd /tmp
wget http://download.virtualbox.org/virtualbox/4.1.6/VBoxGuestAdditions_4.1.6.iso
mount -o loop VBoxGuestAdditions_4.1.6.iso /mnt
(mkdir -p /tmp && cd /tmp && [ ! -f VBoxGuestAdditions_4.1.6.iso ] && curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -C - -X GET http://download.virtualbox.org/virtualbox/4.1.6/VBoxGuestAdditions_4.1.6.iso >VBoxGuestAdditions_4.1.6.iso)
mount -o loop /tmp/VBoxGuestAdditions_4.1.6.iso /mnt
installGuestAdditions || exit 1
sh /mnt/VBoxLinuxAdditions.run
umount /mnt