Skip to content

Commit 0f28f1b

Browse files
committed
Wrap GRIP in a shell script when deploying
This lets us save the JVM arguments for when GRIP is running from a robot program. For example, in C++: void RobotInit() override { system("/home/lvuser/grip &"); }
1 parent e36272c commit 0f28f1b

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

ui/src/main/java/edu/wpi/grip/ui/DeployController.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
import javafx.beans.binding.Bindings;
1414
import javafx.beans.property.BooleanProperty;
1515
import javafx.fxml.FXML;
16-
import javafx.scene.control.*;
16+
import javafx.scene.control.Label;
17+
import javafx.scene.control.ProgressIndicator;
18+
import javafx.scene.control.TextArea;
19+
import javafx.scene.control.TextField;
1720
import net.schmizz.sshj.SSHClient;
1821
import net.schmizz.sshj.common.StreamCopier;
1922
import net.schmizz.sshj.connection.channel.direct.Session;
@@ -42,6 +45,7 @@
4245
*/
4346
public class DeployController {
4447
private final static String GRIP_JAR = "grip.jar";
48+
private final static String GRIP_WRAPPER = "grip";
4549
private final static String PROJECT_FILE = "project.grip";
4650
private final static String LOCAL_GRIP_JAR = URLDecoder.decode(
4751
Project.class.getProtectionDomain().getCodeSource().getLocation().getPath());
@@ -152,9 +156,12 @@ public StreamCopier.Listener file(String name, long size) {
152156
StringWriter projectWriter = new StringWriter();
153157
project.save(projectWriter);
154158

155-
// Upload the GRIP core JAR and the serialized project to the robot
156-
scp.upload(new StringInMemoryFile(PROJECT_FILE, projectWriter.toString()), deployDir.getText() + "/");
157-
scp.upload(new FileSystemFile(LOCAL_GRIP_JAR), deployDir.getText() + "/" + GRIP_JAR);
159+
// Upload the GRIP core JAR, a wrapper script to run it, and the serialized project to the robot
160+
final String commandStr = command.getText();
161+
final String pathStr = deployDir.getText() + "/";
162+
scp.upload(new FileSystemFile(LOCAL_GRIP_JAR), pathStr + GRIP_JAR);
163+
scp.upload(new StringInMemoryFile(GRIP_WRAPPER, "echo \"" + commandStr + "\"\n" + commandStr, 0755), pathStr);
164+
scp.upload(new StringInMemoryFile(PROJECT_FILE, projectWriter.toString()), pathStr);
158165

159166
// Stop the pipeline before running it remotely, so the two instances of GRIP don't try to publish to the
160167
// same NetworkTables keys.
@@ -165,8 +172,7 @@ public StreamCopier.Listener file(String name, long size) {
165172
Session session = ssh.startSession();
166173
session.allocateDefaultPTY();
167174

168-
logger.info("Executing " + command.getText());
169-
Session.Command cmd = session.exec(command.getText());
175+
Session.Command cmd = session.exec(String.format("'%s/%s'", pathStr, GRIP_WRAPPER));
170176

171177
LineReader inputReader = new LineReader(new InputStreamReader(cmd.getInputStream()));
172178
while (isNotCanceled()) {

ui/src/main/java/edu/wpi/grip/ui/util/StringInMemoryFile.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212
*/
1313
public class StringInMemoryFile extends InMemorySourceFile {
1414
private final String name, contents;
15+
private final int permissions;
1516

16-
public StringInMemoryFile(String name, String contents) {
17+
public StringInMemoryFile(String name, String contents, int permissions) {
1718
super();
1819
this.name = name;
1920
this.contents = contents;
21+
this.permissions = permissions;
22+
}
23+
24+
public StringInMemoryFile(String name, String contents) {
25+
this(name, contents, 0644);
2026
}
2127

2228
@Override
@@ -29,6 +35,11 @@ public long getLength() {
2935
return contents.getBytes().length;
3036
}
3137

38+
@Override
39+
public int getPermissions() {
40+
return permissions;
41+
}
42+
3243
@Override
3344
public InputStream getInputStream() throws IOException {
3445
return new StringBufferInputStream(contents);

0 commit comments

Comments
 (0)