diff options
Diffstat (limited to 'src/cmd_create.c')
| -rw-r--r-- | src/cmd_create.c | 32 |
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; } |
