aboutsummaryrefslogtreecommitdiff
path: root/src/cmd_create.c
diff options
context:
space:
mode:
authorNicholas Rodrigues Lordello <[email protected]>2026-09-06 10:55:07 +0200
committerNicholas Rodrigues Lordello <[email protected]>2026-09-06 10:55:07 +0200
commit5f48411161d243627ff3b521250c74d40d776bc3 (patch)
tree8f1fa43a8c39c2af666668cc8d57b83819345d37 /src/cmd_create.c
parent8165883a153e4bc2d50fa3710e47b76d9f79bb15 (diff)
Implemented Devbox Creation
We are now able to create devboxes :tada:. It supports the post install script, and added support for custom SSH configuration options (through `~/.config/dbx/$NAME.ssh_config` file).
Diffstat (limited to 'src/cmd_create.c')
-rw-r--r--src/cmd_create.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/cmd_create.c b/src/cmd_create.c
index 7b1e185..a68fcb7 100644
--- a/src/cmd_create.c
+++ b/src/cmd_create.c
@@ -1,3 +1,4 @@
+#include <stdio.h>
#include <stdlib.h>
#include <sysexits.h>
#include <unistd.h>
@@ -5,24 +6,39 @@
#include "dbx.h"
int dbx_create(struct dbx_engine *engine, struct dbx_options const *options) {
- if (!dbx_ssh_init(options->name)) {
+ char ssh_pubkey[PATH_MAX];
+ if (!dbx_ssh_init(options->name, ssh_pubkey)) {
dbx_printerr("failed to generate SSH key");
return EX_CANTCREAT;
}
- if (!dbx_engine_create(engine, options->image, options->name,
+ if (!dbx_engine_create(engine, options->image, options->name, ssh_pubkey,
options->ports.host)) {
dbx_printerr("failed to create devbox");
return EX_CANTCREAT;
}
- // TODO: setup and install SSH configuration.
- // TODO: copy over (SCP) and execute post-install script.
-
+ int result = EXIT_SUCCESS;
if (options->post_install != NULL) {
- dbx_printerr("-x SCRIPT not yet supported");
- return EX_USAGE;
+ char hostname[HOSTNAME_MAX];
+ uint16_t sshd_port;
+ if (!dbx_engine_start(engine, options->name, hostname, &sshd_port)) {
+ return EX_CONFIG;
+ }
+
+ char tmp[PATH_MAX];
+ if (dbx_fpath(tmp, "%s:/tmp/post-install", options->name) < 0 ||
+ !dbx_ssh_config(options->name, hostname, sshd_port) ||
+ !dbx_ssh_cp(options->name, options->post_install, tmp) ||
+ !dbx_ssh_sys(options->name,
+ "chmod +x /tmp/post-install && /tmp/post-install")) {
+ result = EX_CONFIG;
+ }
+
+ if (!dbx_engine_stop(engine, options->name)) {
+ result = EX_CONFIG;
+ }
}
- return EXIT_SUCCESS;
+ return result;
}