summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2010-09-06 11:15:29 +0200
committerDavid Sommerseth <dazo@users.sourceforge.net>2010-09-06 11:15:29 +0200
commit3685461592b9adc3f0cc569a391e9e27dd28f21f (patch)
treeb071f593ecb35381ae49eeca639491631b596f7a
parentd20fa4a786eeef6669466b5c9813a373f9359023 (diff)
downloadeurephia-3685461592b9adc3f0cc569a391e9e27dd28f21f.tar.gz
eurephia-3685461592b9adc3f0cc569a391e9e27dd28f21f.tar.xz
eurephia-3685461592b9adc3f0cc569a391e9e27dd28f21f.zip
eurephia_init will now suggest a ~/.eurephia/eurephiadm.cfg file
A suggestion for this file will be generated based on the command line arguments. It will also honour the EUREPHIA_DIR environment variable as well. Signed-off-by: David Sommerseth <dazo@users.sourceforge.net>
-rw-r--r--utils/CMakeLists.txt1
-rw-r--r--utils/eurephia_init.c47
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;
}