diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/CMakeLists.txt | 1 | ||||
-rw-r--r-- | utils/eurephia_init.c | 47 |
2 files changed, 46 insertions, 2 deletions
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 941d484..df6b2c1 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -40,6 +40,7 @@ IF(EUREPHIADM) ../eurephiadm/get_console_input.c ../eurephiadm/argparser.c ../eurephiadm/client_context.c + ../eurephiadm/client_config.c ) TARGET_LINK_LIBRARIES(eurephia_init dl crypto common ${EXTRA_LIBS}) diff --git a/utils/eurephia_init.c b/utils/eurephia_init.c index 4f3f954..55756d1 100644 --- a/utils/eurephia_init.c +++ b/utils/eurephia_init.c @@ -51,6 +51,7 @@ #define MODULE "eurephia_init" /**< Set the module name to eurephia_init */ #include <client_context.h> +#include <client_config.h> #include <argparser.h> #include <get_console_input.h> @@ -201,6 +202,21 @@ static int config_set(eurephiaCTX *ctx, const char *key, const char *val) { } /** + * Generate a suggestion for a ~/.eurephia/eurephiadm.cfg file + * + * @param fp A file pointer where to write this suggestion + * @param cfg eurephiaVALUES point to the configuration given via the command line. + * + */ +static void write_eurephiadmcfg_file(FILE *fp, eurephiaVALUES *cfg) { + fprintf(fp, "# Database settings\n"); + fprintf(fp, "database_driver = %s\n", eGet_value(cfg, "database_driver")); + fprintf(fp, "database_params = %s\n", eGet_value(cfg, "database_params")); + fprintf(fp, "\n# Disabling logging\n"); + fprintf(fp, "log_level = 0\n"); + fprintf(fp, "log = none:\n"); +} +/** * Guides the user through setting up the first eurephia administrator account. * * @param ctx eurephiaCTX @@ -499,11 +515,13 @@ int setup_attempt_limits(eurephiaCTX *ctx) { * Guides the user through setting up session specific parameters, mainly for the admin utilities * * @param ctx eurephiaCTX + * @param cfg Configuration arguments, given via the command line * * @return Returns 1 on success, otherwise 0. */ -int setup_session_params(eurephiaCTX *ctx) { +int setup_session_params(eurephiaCTX *ctx, eurephiaVALUES *cfg) { char buffer[22], value[22]; + char *fname = get_config_filename(NULL, "eurephiadm.cfg"); memset(&buffer, 0, 22); printf("------------------------------------------------------------------------------\n"); @@ -518,6 +536,31 @@ int setup_session_params(eurephiaCTX *ctx) { fprintf(stderr, "Failed to set configuration settings in database\n"); return 0; } + + if( fname != NULL ) { + printf("\nGenerating %s\n", fname); + printf("---------------------------------------------------------------\n"); + write_eurephiadmcfg_file(stdout, cfg); + printf("---------------------------------------------------------------\n"); + memset(&buffer, 0, 22); + get_console_input(buffer, 8, "Do you want this to be written to disk? [Yes]", 0); + if( (buffer[0] == '\n') || (buffer[0] == 'y') || (buffer[0] == 'Y') ) { + FILE *f; + + if( (f = fopen(fname, "w")) == NULL ) { + fprintf(stderr, "Failed to create %s\n", fname); + return 0; + } + write_eurephiadmcfg_file(f, cfg); + fclose(f); + printf("Wrote %s\n", fname); + } else { + printf("Configuration file was not written to disk\n"); + } + } else { + printf("\n** ERROR ** Could not generate eurephiadm.cfg file due to file system restrictions.\n"); + printf(" Skipping this part.\n"); + } printf("\n==============================================================================\n\n"); return 1; @@ -712,7 +755,7 @@ int main(int argc, char **argv) { goto exit; } - if( !setup_session_params(ctx) ) { + if( !setup_session_params(ctx, cfg) ) { rc = 13; goto exit; } |