mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-06-22 22:40:01 -04:00
Fix incus/lxd launches for busybox [stage]
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
package io.xpipe.ext.system.incus;
|
||||
|
||||
import io.xpipe.app.ext.ContainerStoreState;
|
||||
import io.xpipe.app.ext.ShellStore;
|
||||
import io.xpipe.app.issue.ErrorEvent;
|
||||
import io.xpipe.app.storage.DataStoreEntry;
|
||||
import io.xpipe.app.storage.DataStoreEntryRef;
|
||||
import io.xpipe.app.util.CommandViewBase;
|
||||
import io.xpipe.core.process.*;
|
||||
|
||||
import io.xpipe.core.store.StatefulDataStore;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class IncusCommandView extends CommandViewBase {
|
||||
@@ -138,16 +141,16 @@ public class IncusCommandView extends CommandViewBase {
|
||||
}
|
||||
}
|
||||
|
||||
public ShellControl exec(String container, String user) {
|
||||
public ShellControl exec(String container, String user, Supplier<Boolean> busybox) {
|
||||
var sub = shellControl.subShell();
|
||||
sub.setDumbOpen(createOpenFunction(container, user, false));
|
||||
sub.setTerminalOpen(createOpenFunction(container, user, true));
|
||||
sub.setDumbOpen(createOpenFunction(container, user, false, busybox));
|
||||
sub.setTerminalOpen(createOpenFunction(container, user, true, busybox));
|
||||
return sub.withErrorFormatter(IncusCommandView::formatErrorMessage)
|
||||
.withExceptionConverter(IncusCommandView::convertException)
|
||||
.elevated(requiresElevation());
|
||||
}
|
||||
|
||||
private ShellOpenFunction createOpenFunction(String containerName, String user, boolean terminal) {
|
||||
private ShellOpenFunction createOpenFunction(String containerName, String user, boolean terminal, Supplier<Boolean> busybox) {
|
||||
return new ShellOpenFunction() {
|
||||
@Override
|
||||
public CommandBuilder prepareWithoutInitCommand() {
|
||||
@@ -164,7 +167,14 @@ public class IncusCommandView extends CommandViewBase {
|
||||
if (user != null) {
|
||||
b.addQuoted(user);
|
||||
}
|
||||
return b.add("--session-command").addLiteral(command);
|
||||
return b.add(sc -> {
|
||||
var suType = busybox.get();
|
||||
if (suType) {
|
||||
return "-c";
|
||||
} else {
|
||||
return "--session-command";
|
||||
}
|
||||
}).addLiteral(command);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import io.xpipe.app.ext.ShellStore;
|
||||
import io.xpipe.app.storage.DataStoreEntryRef;
|
||||
import io.xpipe.app.util.*;
|
||||
import io.xpipe.core.process.ShellControl;
|
||||
import io.xpipe.core.process.ShellStoreState;
|
||||
import io.xpipe.core.store.FixedChildStore;
|
||||
import io.xpipe.core.store.StatefulDataStore;
|
||||
import io.xpipe.ext.base.identity.IdentityValue;
|
||||
@@ -75,7 +76,11 @@ public class IncusContainerStore
|
||||
@Override
|
||||
public ShellControl control(ShellControl parent) {
|
||||
var user = identity != null ? identity.unwrap().getUsername() : null;
|
||||
var sc = new IncusCommandView(parent).exec(containerName, user);
|
||||
var sc = new IncusCommandView(parent).exec(containerName, user, () -> {
|
||||
var state = getState();
|
||||
var alpine = state.getOsName() != null && state.getOsName().toLowerCase().contains("alpine");
|
||||
return alpine;
|
||||
});
|
||||
sc.withSourceStore(IncusContainerStore.this);
|
||||
if (identity != null && identity.unwrap().getPassword() != null) {
|
||||
sc.setElevationHandler(new BaseElevationHandler(
|
||||
|
||||
@@ -11,6 +11,7 @@ import lombok.NonNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class LxdCommandView extends CommandViewBase {
|
||||
@@ -150,16 +151,16 @@ public class LxdCommandView extends CommandViewBase {
|
||||
}
|
||||
}
|
||||
|
||||
public ShellControl exec(String container, String user) {
|
||||
public ShellControl exec(String container, String user, Supplier<Boolean> busybox) {
|
||||
var sub = shellControl.subShell();
|
||||
sub.setDumbOpen(createOpenFunction(container, user, false));
|
||||
sub.setTerminalOpen(createOpenFunction(container, user, true));
|
||||
sub.setDumbOpen(createOpenFunction(container, user, false, busybox));
|
||||
sub.setTerminalOpen(createOpenFunction(container, user, true, busybox));
|
||||
return sub.withErrorFormatter(LxdCommandView::formatErrorMessage)
|
||||
.withExceptionConverter(LxdCommandView::convertException)
|
||||
.elevated(requiresElevation());
|
||||
}
|
||||
|
||||
private ShellOpenFunction createOpenFunction(String containerName, String user, boolean terminal) {
|
||||
private ShellOpenFunction createOpenFunction(String containerName, String user, boolean terminal, Supplier<Boolean> busybox) {
|
||||
return new ShellOpenFunction() {
|
||||
@Override
|
||||
public CommandBuilder prepareWithoutInitCommand() {
|
||||
@@ -176,7 +177,14 @@ public class LxdCommandView extends CommandViewBase {
|
||||
if (user != null) {
|
||||
b.addQuoted(user);
|
||||
}
|
||||
return b.add("--session-command").addLiteral(command);
|
||||
return b.add(sc -> {
|
||||
var suType = busybox.get();
|
||||
if (suType) {
|
||||
return "-c";
|
||||
} else {
|
||||
return "--session-command";
|
||||
}
|
||||
}).addLiteral(command);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -73,7 +73,11 @@ public class LxdContainerStore
|
||||
@Override
|
||||
public ShellControl control(ShellControl parent) {
|
||||
var user = identity != null ? identity.unwrap().getUsername() : null;
|
||||
var base = new LxdCommandView(parent).exec(containerName, user);
|
||||
var base = new LxdCommandView(parent).exec(containerName, user, () -> {
|
||||
var state = getState();
|
||||
var alpine = state.getOsName() != null && state.getOsName().toLowerCase().contains("alpine");
|
||||
return alpine;
|
||||
});
|
||||
if (identity != null && identity.unwrap().getPassword() != null) {
|
||||
base.setElevationHandler(new BaseElevationHandler(
|
||||
LxdContainerStore.this, identity.unwrap().getPassword())
|
||||
|
||||
Reference in New Issue
Block a user